Skip to content

Commit

Permalink
Merge branch 'v0.11.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
GardenHamster committed May 8, 2024
2 parents 27216e9 + 87f550e commit 8d23626
Show file tree
Hide file tree
Showing 17 changed files with 197 additions and 31 deletions.
4 changes: 2 additions & 2 deletions Theresa3rd-Bot/TheresaBot.GoCqHttp/TheresaBot.GoCqHttp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<RootNamespace>TheresaBot.GoCqHttp</RootNamespace>
<StartupObject></StartupObject>
<BaseOutputPath></BaseOutputPath>
<Version>0.11.3</Version>
<Version>0.11.4</Version>
<Nullable>disable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<WarningLevel>3</WarningLevel>
Expand All @@ -18,7 +18,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EleCho.GoCqHttpSdk" Version="1.2.4" />
<PackageReference Include="EleCho.GoCqHttpSdk" Version="1.2.5" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Theresa3rd-Bot/TheresaBot.Main/Common/BotConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace TheresaBot.Main.Common
{
public static class BotConfig
{
public const string BotVersion = "0.11.3";
public const string BotVersion = "0.11.4";
public const string BotHomepage = "https://www.theresa3rd.cn";
public static BotInfos BotInfos = new BotInfos(0, "Bot");
public static List<long> AcceptGroups = new();
Expand Down
65 changes: 65 additions & 0 deletions Theresa3rd-Bot/TheresaBot.Main/Controller/DictionaryController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using TheresaBot.Main.Datas;
using TheresaBot.Main.Helper;
using TheresaBot.Main.Model.DTO;
using TheresaBot.Main.Model.Result;
using TheresaBot.Main.Model.VO;
using TheresaBot.Main.Services;
using TheresaBot.Main.Type;

namespace TheresaBot.Main.Controller
{
[ApiController]
[Route("api/[controller]")]
public class DictionaryController : BaseController
{
private DictionaryService dictionaryService;

public DictionaryController()
{
dictionaryService = new DictionaryService();
}

[HttpGet]
[Authorize]
[Route("list")]
public ApiResult GetDictionary()
{
var datas = dictionaryService.GetDictionary();
var dataInfos = datas.Select(o => new DictionaryVo
{
Id = o.Id,
Words = o.Words,
WordType = o.WordType,
SubType = o.SubType,
CreateAt = o.CreateDate.ToTimeStamp()
}).ToList();
return ApiResult.Success(dataInfos);
}

[HttpPost]
[Authorize]
[Route("add")]
public ApiResult AddDictionary([FromBody] AddDictionaryDto datas)
{
var words = datas.Words ?? new();
if (words.Count == 0) return ApiResult.ParamError;
dictionaryService.InsertDictionary(datas.WordType, words, datas.SubType);
return ApiResult.Success();
}

[HttpPost]
[Authorize]
[Route("del")]
public ApiResult DelDictionary(int[] ids)
{
dictionaryService.DelByIds(ids);
return ApiResult.Success();
}




}
}
20 changes: 20 additions & 0 deletions Theresa3rd-Bot/TheresaBot.Main/Controller/OptionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Mvc;
using TheresaBot.Main.Helper;
using TheresaBot.Main.Model.Result;
using TheresaBot.Main.Type;

namespace TheresaBot.Main.Controller
{
Expand Down Expand Up @@ -128,5 +129,24 @@ public ApiResult ListPixivRankingSort()
}
}

[HttpGet]
[Authorize]
[Route("list/dictionary/type")]
public ApiResult ListDictionaryType()
{
try
{
var optionList = EnumHelper.DictionaryTypeOptions.ToOptionList();
optionList.AddSubOptions((int)DictionaryType.WordCloud, EnumHelper.WordcloudTypeOptions);
return ApiResult.Success(optionList);
}
catch (Exception ex)
{
LogHelper.Error(ex);
throw;
}
}


}
}
13 changes: 9 additions & 4 deletions Theresa3rd-Bot/TheresaBot.Main/Dao/DictionaryDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,27 @@ namespace TheresaBot.Main.Dao
{
public class DictionaryDao : DbContext<DictionaryPO>
{
public List<DictionaryPO> GetDictionary(WordType wordType)
public List<DictionaryPO> GetDictionary()
{
return Db.Queryable<DictionaryPO>().ToList();
}

public List<DictionaryPO> GetDictionary(DictionaryType wordType)
{
return Db.Queryable<DictionaryPO>().Where(o => o.WordType == wordType).ToList();
}

public List<DictionaryPO> GetDictionary(WordType wordType, int subType)
public List<DictionaryPO> GetDictionary(DictionaryType wordType, int subType)
{
return Db.Queryable<DictionaryPO>().Where(o => o.WordType == wordType && o.SubType == subType).ToList();
}

public List<DictionaryPO> GetDictionary(WordType wordType, string word)
public List<DictionaryPO> GetDictionary(DictionaryType wordType, string word)
{
return Db.Queryable<DictionaryPO>().Where(o => o.WordType == wordType && o.Words == word).ToList();
}

public List<DictionaryPO> GetDictionary(WordType wordType, int subType, string word)
public List<DictionaryPO> GetDictionary(DictionaryType wordType, int subType, string word)
{
return Db.Queryable<DictionaryPO>().Where(o => o.WordType == wordType && o.SubType == subType && o.Words == word).ToList();
}
Expand Down
8 changes: 4 additions & 4 deletions Theresa3rd-Bot/TheresaBot.Main/Handler/DictionaryHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ public async Task AddCloudWordAsync(GroupCommand command)
List<DictionaryPO> existsList = new List<DictionaryPO>();
foreach (string word in wordArr)
{
var dictionary = dictionaryService.GetDictionary(WordType.WordCloud, (int)WordCloudSubType.NewWord, word.Trim());
var dictionary = dictionaryService.GetDictionary(DictionaryType.WordCloud, (int)WordCloudType.NewWord, word.Trim());
if (dictionary is not null && dictionary.Count > 0)
{
existsList.AddRange(dictionary);
continue;
}
dictionaryService.InsertDictionary(WordType.WordCloud, word, (int)WordCloudSubType.NewWord);
dictionaryService.InsertDictionary(DictionaryType.WordCloud, word, (int)WordCloudType.NewWord);
}

if (existsList.Count > 0)
Expand Down Expand Up @@ -73,13 +73,13 @@ public async Task HideCloudWordAsync(GroupCommand command)
List<DictionaryPO> existsList = new List<DictionaryPO>();
foreach (string word in wordArr)
{
var dictionary = dictionaryService.GetDictionary(WordType.WordCloud, (int)WordCloudSubType.HiddenWord, word.Trim());
var dictionary = dictionaryService.GetDictionary(DictionaryType.WordCloud, (int)WordCloudType.HiddenWord, word.Trim());
if (dictionary is not null && dictionary.Count > 0)
{
existsList.AddRange(dictionary);
continue;
}
dictionaryService.InsertDictionary(WordType.WordCloud, word, (int)WordCloudSubType.HiddenWord);
dictionaryService.InsertDictionary(DictionaryType.WordCloud, word, (int)WordCloudType.HiddenWord);
}

if (existsList.Count > 0)
Expand Down
18 changes: 18 additions & 0 deletions Theresa3rd-Bot/TheresaBot.Main/Helper/EnumHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ public static class EnumHelper
{(int)PixivRankingSortType.RankingRate, "点赞率倒序排序"},
};

public static Dictionary<int, string> DictionaryTypeOptions => new()
{
{(int)DictionaryType.WordCloud, "词云"}
};

public static Dictionary<int, string> WordcloudTypeOptions => new()
{
{(int)WordCloudType.NewWord, "新词"},
{(int)WordCloudType.HiddenWord, "隐藏词"}
};

public static Dictionary<int, string> UCGameModes => new()
{
{(int)UCGameMode.Standard, "默认(3平1卧)"},
Expand All @@ -75,6 +86,13 @@ public static List<OptionVo> ToOptionList(this Dictionary<int, string> options)
return options.Select(o => new OptionVo(o.Key, o.Value)).ToList();
}

public static List<OptionVo> AddSubOptions(this List<OptionVo> optionList, int optionValue, Dictionary<int, string> subOptions)
{
var parentOptions = optionList.FirstOrDefault(o => o.Value == optionValue);
if (parentOptions is not null) parentOptions.AddSubOptions(subOptions);
return optionList;
}

public static string GetOptionName(this Dictionary<int, string> options, Enum value)
{
int intValue = Convert.ToInt32(value);
Expand Down
14 changes: 14 additions & 0 deletions Theresa3rd-Bot/TheresaBot.Main/Model/DTO/AddDictionaryDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using TheresaBot.Main.Type;

namespace TheresaBot.Main.Model.DTO
{
public record AddDictionaryDto
{
public List<string> Words { get; set; }

public DictionaryType WordType { get; set; }

public int SubType { get; set; }

}
}
2 changes: 1 addition & 1 deletion Theresa3rd-Bot/TheresaBot.Main/Model/PO/DictionaryPO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public record DictionaryPO : BasePO
public string Words { get; set; }

[SugarColumn(IsNullable = false, ColumnDescription = "词类型")]
public WordType WordType { get; set; }
public DictionaryType WordType { get; set; }

[SugarColumn(IsNullable = false, ColumnDescription = "子类型")]
public int SubType { get; set; }
Expand Down
19 changes: 19 additions & 0 deletions Theresa3rd-Bot/TheresaBot.Main/Model/VO/DictionaryVo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using TheresaBot.Main.Type;

namespace TheresaBot.Main.Model.VO
{
public record DictionaryVo
{
public int Id { get; set; }

public string Words { get; set; }

public long CreateAt { get; set; }

public DictionaryType WordType { get; set; }

public int SubType { get; set; }


}
}
14 changes: 13 additions & 1 deletion Theresa3rd-Bot/TheresaBot.Main/Model/VO/OptionVo.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
namespace TheresaBot.Main.Model.VO
using TheresaBot.Main.Helper;

namespace TheresaBot.Main.Model.VO
{
public record OptionVo
{
public int Value { get; set; }

public string Label { get; set; }

public List<OptionVo> SubOptions { get; set; } = new();

public OptionVo(int value, string label)
{
Value = value;
Label = label;
}

public void AddSubOptions(Dictionary<int, string> options)
{
SubOptions.AddRange(options.ToOptionList());
}




}
}
27 changes: 22 additions & 5 deletions Theresa3rd-Bot/TheresaBot.Main/Services/DictionaryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,40 @@ public DictionaryService()
dictionaryDao = new DictionaryDao();
}

public List<DictionaryPO> GetDictionary(WordType wordType)
public List<DictionaryPO> GetDictionary()
{
return dictionaryDao.GetDictionary();
}

public List<DictionaryPO> GetDictionary(DictionaryType wordType)
{
return dictionaryDao.GetDictionary(wordType);
}

public List<DictionaryPO> GetDictionary(WordType wordType, int subType)
public List<DictionaryPO> GetDictionary(DictionaryType wordType, int subType)
{
return dictionaryDao.GetDictionary(wordType, subType);
}

public List<DictionaryPO> GetDictionary(WordType wordType, string word)
public List<DictionaryPO> GetDictionary(DictionaryType wordType, string word)
{
return dictionaryDao.GetDictionary(wordType, word);
}

public List<DictionaryPO> GetDictionary(WordType wordType, int subType, string word)
public List<DictionaryPO> GetDictionary(DictionaryType wordType, int subType, string word)
{
return dictionaryDao.GetDictionary(wordType, subType, word);
}

public void InsertDictionary(WordType wordType, string word, int subType = 0, string translate = "")
public void InsertDictionary(DictionaryType wordType, List<string> words, int subType = 0)
{
foreach (string word in words)
{
InsertDictionary(wordType, word, subType);
}
}

public void InsertDictionary(DictionaryType wordType, string word, int subType = 0)
{
DictionaryPO dictionary = new DictionaryPO();
dictionary.Words = word;
Expand All @@ -43,6 +56,10 @@ public void InsertDictionary(WordType wordType, string word, int subType = 0, st
dictionaryDao.Insert(dictionary);
}

public int DelByIds(int[] ids)
{
return dictionaryDao.DeleteByIds(ids);
}

}
}
11 changes: 4 additions & 7 deletions Theresa3rd-Bot/TheresaBot.Main/Services/WordCloudService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,16 @@ public List<string> GetWords(long groupId, DateTime startTime, DateTime endTime)

public List<string> LoadNewWords()
{
var dicList = dictionaryDao.GetDictionary(WordType.WordCloud, (int)WordCloudSubType.NewWord);
return dicList.Select(o => o.Words).ToList();
var newWords = dictionaryDao.GetDictionary(DictionaryType.WordCloud, (int)WordCloudType.NewWord);
var hiddenWords = dictionaryDao.GetDictionary(DictionaryType.WordCloud, (int)WordCloudType.HiddenWord);
return newWords.Concat(hiddenWords).Select(o => o.Words).Distinct().ToList();
}

public List<string> LoadHiddenWords()
{
var dicList = dictionaryDao.GetDictionary(WordType.WordCloud, (int)WordCloudSubType.HiddenWord);
var dicList = dictionaryDao.GetDictionary(DictionaryType.WordCloud, (int)WordCloudType.HiddenWord);
return dicList.Select(o => o.Words).ToList();
}





}
}
2 changes: 1 addition & 1 deletion Theresa3rd-Bot/TheresaBot.Main/TheresaBot.Main.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Quartz" Version="3.8.0" />
<PackageReference Include="SharpZipLib" Version="1.4.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.3" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.4" />
<PackageReference Include="SkiaSharp" Version="2.88.6" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.6" />
<PackageReference Include="SqlSugar.IOC" Version="2.0.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
namespace TheresaBot.Main.Type
{
public enum WordType
public enum DictionaryType
{
Other = 0,
WordCloud = 1,
PixivTag = 2
WordCloud = 1
}
}
Loading

0 comments on commit 8d23626

Please sign in to comment.