Skip to content

Commit

Permalink
Saucenao搜图优化
Browse files Browse the repository at this point in the history
  • Loading branch information
GardenHamster committed Jan 9, 2024
1 parent 6538264 commit 345e7c6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
12 changes: 10 additions & 2 deletions Theresa3rd-Bot/TheresaBot.Main/Handler/SaucenaoHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,18 @@ private async Task<bool> SearchWithSaucenao(GroupCommand command, string imgUrl)
if (filterList.Count == 0) return false;

var sortList = saucenaoService.SortItems(filterList);
var sendList = new List<SaucenaoItem>();
var maxSimilarity = sortList.Max(o => o.Similarity);
var singlePriority = BotConfig.SaucenaoConfig.SinglePriority;
var showCount = maxSimilarity >= singlePriority ? 1 : readCount;
var sendList = sortList.Take(showCount).ToList();

if (maxSimilarity >= singlePriority)
{
sendList = sortList.Where(o => o.SourceType == SetuSourceType.Pixiv).Take(1).ToList();
}
if (sendList.Count == 0)
{
sendList = sortList.Take(readCount).ToList();
}

if (BotConfig.SaucenaoConfig.PullOrigin == false)
{
Expand Down
2 changes: 1 addition & 1 deletion Theresa3rd-Bot/TheresaBot.Main/Services/SaucenaoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public List<SaucenaoItem> SortItems(List<SaucenaoItem> itemList)
List<SaucenaoItem> sortList = new List<SaucenaoItem>();
List<SaucenaoItem> selectList = itemList.OrderByDescending(o => o.Similarity).Take(20).ToList();
sortList.AddRange(selectList.Where(o => o.SourceType == SetuSourceType.Pixiv && o.Similarity >= BotConfig.SaucenaoConfig.PixivPriority).ToList());
sortList.AddRange(selectList.Where(o => o.Similarity >= 80).OrderByDescending(o => o.SourceType));
sortList.AddRange(selectList.Where(o => o.Similarity >= 80).OrderBy(o => o.SourceType));
sortList.AddRange(selectList.OrderByDescending(o => o.Similarity).ThenBy(o => o.SourceType));
return sortList.Distinct().ToList();
}
Expand Down
16 changes: 8 additions & 8 deletions Theresa3rd-Bot/TheresaBot.Main/Type/SetuSourceType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
{
public enum SetuSourceType
{
Pixiv,
FanBox,
Twitter,
Konachan,
Yande,
Danbooru,
Gelbooru,
AnimePictures
Pixiv = 1,
FanBox = 2,
Twitter = 3,
Konachan = 4,
Yande = 5,
Danbooru = 6,
Gelbooru = 7,
AnimePictures = 8
}


Expand Down

0 comments on commit 345e7c6

Please sign in to comment.