Skip to content

Commit

Permalink
Merge branch 'v0.8.3-dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
GardenHamster committed Mar 24, 2023
2 parents a2bb563 + 29f9882 commit fac97d6
Show file tree
Hide file tree
Showing 32 changed files with 306 additions and 163 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 25 additions & 7 deletions Theresa3rd-Bot/TheresaBot.Main/Business/PixivBusiness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ public async Task<PixivWorkInfo> getRandomWorkInSubscribeAsync(long groupId, boo
for (int j = 0; j < loopWorkTimes; j++)
{
PixivUserWorkInfo pixivUserWorkInfo = workList[new Random().Next(0, workList.Count)];
if (pixivUserWorkInfo.IsImproper()) continue;
if (pixivUserWorkInfo.IsImproper) continue;
if (pixivUserWorkInfo.hasBanTag() != null) continue;
if (pixivUserWorkInfo.isR18() && includeR18 == false) continue;
if (pixivUserWorkInfo.isAI() && includeAI == false) continue;
if (pixivUserWorkInfo.IsR18 && includeR18 == false) continue;
if (pixivUserWorkInfo.IsAI && includeAI == false) continue;
PixivWorkInfo pixivWorkInfo = await PixivHelper.GetPixivWorkInfoAsync(pixivUserWorkInfo.id);
if (pixivWorkInfo is null) continue;
if (pixivWorkInfo.bookmarkCount < 100) continue;
Expand Down Expand Up @@ -135,10 +135,10 @@ public async Task<PixivWorkInfo> getRandomWorkInFollowAsync(bool includeR18, boo
for (int i = 0; i < loopWorkTimes; i++)
{
PixivUserWorkInfo pixivUserWorkInfo = workList[new Random().Next(0, workList.Count)];
if (pixivUserWorkInfo.IsImproper()) continue;
if (pixivUserWorkInfo.IsImproper) continue;
if (pixivUserWorkInfo.hasBanTag() != null) continue;
if (pixivUserWorkInfo.isR18() && includeR18 == false) continue;
if (pixivUserWorkInfo.isAI() && includeAI == false) continue;
if (pixivUserWorkInfo.IsR18 && includeR18 == false) continue;
if (pixivUserWorkInfo.IsAI && includeAI == false) continue;
PixivWorkInfo pixivWorkInfo = await PixivHelper.GetPixivWorkInfoAsync(pixivUserWorkInfo.id);
if (pixivWorkInfo is null) continue;
if (pixivWorkInfo.bookmarkCount < 100) continue;
Expand Down Expand Up @@ -409,6 +409,9 @@ public async Task scanAndPushUserAsync(SubscribeTask subscribeTask, PixivUserSca
int getCount = 5;
string userId = subscribeTask.SubscribeCode;
int subscribeId = subscribeTask.SubscribeId;
List<long> groupIds = subscribeTask.GroupIdList;
bool isShowAIs = groupIds.IsShowAISetu();
bool isShowR18s = groupIds.IsShowR18Setu();
PixivUserInfo pixivUserInfo = await PixivHelper.GetPixivUserInfoAsync(userId);
if (pixivUserInfo is null) return;
Dictionary<string, PixivUserWorkInfo> illusts = pixivUserInfo?.illusts;
Expand All @@ -421,6 +424,9 @@ public async Task scanAndPushUserAsync(SubscribeTask subscribeTask, PixivUserSca
{
if (++index > getCount) break;
if (workInfo is null || string.IsNullOrWhiteSpace(workInfo.id)) continue;
if (workInfo.IsImproper) continue;
if (isShowAIs == false && workInfo.IsAI) continue;
if (isShowR18s == false && workInfo.IsR18) continue;
if (shelfLife > 0 && workInfo.createDate < DateTime.Now.AddSeconds(-1 * shelfLife)) break;
if (subscribeRecordDao.checkExists(subscribeTask.SubscribeType, workInfo.id)) continue;
scanReport.ScanWork++;
Expand Down Expand Up @@ -453,6 +459,9 @@ public async Task scanAndPushTagAsync(SubscribeTask subscribeTask, PixivTagScanR
{
string tagNames = subscribeTask.SubscribeCode;
int subscribeId = subscribeTask.SubscribeId;
List<long> groupIds = subscribeTask.GroupIdList;
bool isShowAIs = groupIds.IsShowAISetu();
bool isShowR18s = groupIds.IsShowR18Setu();
string searchWord = toPixivSearchWord(tagNames);
int maxScan = BotConfig.SubscribeConfig.PixivTag.MaxScan;
int shelfLife = BotConfig.SubscribeConfig.PixivTag.ShelfLife;
Expand All @@ -462,6 +471,9 @@ public async Task scanAndPushTagAsync(SubscribeTask subscribeTask, PixivTagScanR
try
{
if (item is null || string.IsNullOrWhiteSpace(item.id)) continue;
if (item.IsImproper) continue;
if (isShowAIs == false && item.IsAI) continue;
if (isShowR18s == false && item.IsR18) continue;
if (shelfLife > 0 && item.createDate < DateTime.Now.AddSeconds(-1 * shelfLife)) break;
if (subscribeRecordDao.checkExists(subscribeTask.SubscribeType, item.id)) continue;
scanReport.ScanWork++;
Expand Down Expand Up @@ -495,6 +507,9 @@ public async Task scanAndPushTagAsync(SubscribeTask subscribeTask, PixivTagScanR
public async Task scanAndPushFollowAsync(PixivUserScanReport scanReport, Func<PixivSubscribe, List<long>, Task> pushAsync)
{
int pageIndex = 1;
List<long> groupIds = BotConfig.PermissionsConfig.SubscribeGroups;
bool isShowAIs = groupIds.IsShowAISetu();
bool isShowR18s = groupIds.IsShowR18Setu();
PixivFollowLatest pageOne = await PixivHelper.GetPixivFollowLatestAsync(pageIndex);
if (pageOne?.page?.ids is null) return;
int shelfLife = BotConfig.SubscribeConfig.PixivTag.ShelfLife;
Expand All @@ -508,12 +523,15 @@ public async Task scanAndPushFollowAsync(PixivUserScanReport scanReport, Func<Pi
scanReport.ScanWork++;
PixivWorkInfo pixivWorkInfo = await PixivHelper.GetPixivWorkInfoAsync(workId.ToString(), 0);
if (pixivWorkInfo is null) continue;
if (pixivWorkInfo.IsImproper) continue;
if (isShowAIs == false && pixivWorkInfo.IsAI) continue;
if (isShowR18s == false && pixivWorkInfo.IsR18) continue;
if (shelfLife > 0 && pixivWorkInfo.createDate < DateTime.Now.AddSeconds(-1 * shelfLife)) break;
SubscribePO dbSubscribe = getOrInsertUserSubscribe(pixivWorkInfo);
SubscribeRecordPO subscribeRecord = toSubscribeRecord(pixivWorkInfo, dbSubscribe.Id);
subscribeRecord = subscribeRecordDao.Insert(subscribeRecord);
PixivSubscribe pixivSubscribe = new PixivSubscribe(subscribeRecord, pixivWorkInfo);
await pushAsync(pixivSubscribe, BotConfig.PermissionsConfig.SubscribeGroups);
await pushAsync(pixivSubscribe, groupIds);
}
catch (Exception ex)
{
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 @@ -7,7 +7,7 @@ namespace TheresaBot.Main.Common
{
public static class BotConfig
{
public const string BotVersion = "v0.8.2";
public const string BotVersion = "v0.8.3";
public const string BotHomepage = "https://www.theresa3rd.cn";
public static GeneralConfig GeneralConfig = new GeneralConfig();
public static PixivConfig PixivConfig = new PixivConfig();
Expand Down
Binary file added Theresa3rd-Bot/TheresaBot.Main/Font/simsun.ttc
Binary file not shown.
12 changes: 5 additions & 7 deletions Theresa3rd-Bot/TheresaBot.Main/Handler/LolisukiHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public async Task lolisukiSearchAsync(GroupCommand command)
List<LolisukiData> dataList;
int r18Mode = isShowR18 ? 2 : 0;
int aiMode = isShowAI ? 2 : 0;
string levelStr = getLevelStr(isShowR18);
string levelStr = getLevelStr(isShowR18, BotConfig.SetuConfig?.Lolisuki?.Level);

if (string.IsNullOrEmpty(tagStr))
{
Expand Down Expand Up @@ -101,7 +101,7 @@ public async Task sendTimingSetuAsync(TimingSetuTimer timingSetuTimer, long grou
int margeEachPage = 5;
bool isShowAI = groupId.IsShowAISetu();
bool isShowR18 = groupId.IsShowR18Setu();
string levelStr = getLevelStr(isShowR18);
string levelStr = getLevelStr(isShowR18, BotConfig.TimingSetuConfig?.LolisukiLevel);
bool sendMerge = timingSetuTimer.SendMerge;
int aiMode = isShowAI ? 2 : 0;
int r18Mode = isShowR18 ? 2 : 0;
Expand Down Expand Up @@ -135,14 +135,12 @@ private async Task<SetuContent> getSetuContent(LolisukiData data, long groupId)
return new SetuContent(setuInfo, setuFiles);
}

private string getLevelStr(bool isShowR18)
private string getLevelStr(bool isShowR18, string settingLevel)
{
try
{
string levelStr = BotConfig.SetuConfig.Lolisuki.Level;
if (string.IsNullOrWhiteSpace(levelStr)) return $"{(int)LolisukiLevel.Level0}-{(int)LolisukiLevel.Level3}";

string[] levelArr = levelStr.Split('-', StringSplitOptions.RemoveEmptyEntries);
if (string.IsNullOrWhiteSpace(settingLevel)) return $"{(int)LolisukiLevel.Level0}-{(int)LolisukiLevel.Level2}";
string[] levelArr = settingLevel.Split('-', StringSplitOptions.RemoveEmptyEntries);
string minLevelStr = levelArr[0].Trim();
string maxLevelStr = levelArr.Length > 1 ? levelArr[1].Trim() : levelArr[0].Trim();
int minLevel = int.Parse(minLevelStr);
Expand Down
19 changes: 12 additions & 7 deletions Theresa3rd-Bot/TheresaBot.Main/Handler/PixivRankingHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,25 @@ private async Task sendPreviewFileAsync(PixivRankingTimer rankingTimer, PixivRan
List<string> PreviewFilePaths = pixivRankingInfo.PreviewFilePaths;
if (PreviewFilePaths is null || PreviewFilePaths.IsFilesExists() == false)
{
PreviewFilePaths = createPreviewImg(pixivRankingInfo);
PreviewFilePaths = await createPreviewImgAsync(pixivRankingInfo);
pixivRankingInfo.PreviewFilePaths = PreviewFilePaths;
}

List<SetuContent> setuContents = new List<SetuContent>();
setuContents.Add(new SetuContent(templateMsg));
setuContents.AddRange(PreviewFilePaths.Select(o => new SetuContent(new FileInfo(o))));
setuContents.AddRange(rankingBusiness.getRankAndPids(pixivRankingInfo, 10));

foreach (var groupId in rankingTimer.Groups)
{
if (rankingMode.IsR18 && groupId.IsShowR18SetuImg() == false) continue;
await Session.SendGroupMessageAsync(groupId, templateMsg);
await Task.Delay(1000);
}

foreach (var groupId in rankingTimer.Groups)
{
if (rankingMode.IsR18 && groupId.IsShowR18SetuImg() == false) continue;
await SendGroupSetuAsync(setuContents, groupId, true);
await Task.Delay(1000);
}
Expand Down Expand Up @@ -211,7 +217,7 @@ private async Task replyRankingInfo(GroupCommand command, PixivRankingMode ranki
List<string> PreviewFilePaths = pixivRankingInfo.PreviewFilePaths;
if (PreviewFilePaths is null || PreviewFilePaths.IsFilesExists() == false)
{
PreviewFilePaths = createPreviewImg(pixivRankingInfo);
PreviewFilePaths = await createPreviewImgAsync(pixivRankingInfo);
pixivRankingInfo.PreviewFilePaths = PreviewFilePaths;
}

Expand Down Expand Up @@ -246,7 +252,7 @@ private async Task replyRankingInfo(GroupCommand command, PixivRankingMode ranki
}
}

private List<string> createPreviewImg(PixivRankingInfo rankingInfo)
private async Task<List<string>> createPreviewImgAsync(PixivRankingInfo rankingInfo)
{
int startIndex = 0;
int previewInPage = BotConfig.PixivRankingConfig.PreviewInPage;
Expand All @@ -260,18 +266,18 @@ private List<string> createPreviewImg(PixivRankingInfo rankingInfo)
string fileName = $"{rankingMode.Code}_preview_{rankingInfo.RankingDate}_{startIndex}_{startIndex + previewInPage}.jpg";
string fullSavePath = Path.Combine(FilePath.GetPixivPreviewSavePath(), fileName);
var partList = details.Skip(startIndex).Take(previewInPage).ToList();
var previewFile = createPreviewImg(rankingInfo, partList, fullSavePath);
var previewFile = await createPreviewImgAsync(rankingInfo, partList, fullSavePath);
if (previewFile is not null) fileInfos.Add(previewFile.FullName);
startIndex += previewInPage;
}
return fileInfos;
}

private FileInfo createPreviewImg(PixivRankingInfo rankingInfo, List<PixivRankingDetail> datas, string savePath)
private async Task<FileInfo> createPreviewImgAsync(PixivRankingInfo rankingInfo, List<PixivRankingDetail> datas, string fullSavePath)
{
try
{
return PixivRankingDrawHelper.DrawPreview(rankingInfo, datas, savePath);
return await PixivRankingDrawHelper.DrawPreview(rankingInfo, datas, fullSavePath);
}
catch (Exception ex)
{
Expand All @@ -281,6 +287,5 @@ private FileInfo createPreviewImg(PixivRankingInfo rankingInfo, List<PixivRankin
}
}


}
}
5 changes: 2 additions & 3 deletions Theresa3rd-Bot/TheresaBot.Main/Handler/SetuHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,7 @@ protected async Task<FileInfo> downAndComposeGifAsync(BaseWorkInfo workInfo)
PixivUgoiraMeta pixivUgoiraMetaDto = await PixivHelper.GetPixivUgoiraMetaAsync(pixivIdStr);
string zipHttpUrl = pixivUgoiraMetaDto.src;

string fullZipSavePath = Path.Combine(FilePath.GetTempSavePath(), $"{pixivId}.zip");
FileInfo zipFile = await PixivHelper.DownPixivFileAsync(pixivIdStr, zipHttpUrl, fullZipSavePath);
FileInfo zipFile = await PixivHelper.DownPixivFileAsync(pixivIdStr, zipHttpUrl);
if (zipFile == null) return null;

string unZipDirPath = Path.Combine(FilePath.GetTempSavePath(), pixivIdStr);
Expand All @@ -350,7 +349,7 @@ protected async Task<FileInfo> downAndComposeGifAsync(BaseWorkInfo workInfo)
}
gif.SaveAsGif(fullGifSavePath);

FileHelper.DeleteFile(fullZipSavePath);
FileHelper.DeleteFile(zipFile);
FileHelper.DeleteDirectory(unZipDirPath);
return new FileInfo(fullGifSavePath);
}
Expand Down
4 changes: 1 addition & 3 deletions Theresa3rd-Bot/TheresaBot.Main/Helper/BusinessHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,7 @@ public static List<BaseContent> GetErrorContents(this Exception ex, SendTarget s
string template = BotConfig.GeneralConfig.ErrorMsg;
if (string.IsNullOrWhiteSpace(template)) template = "出了点小问题,再试一次吧~";
if (template.StartsWith(" ") == false) template = " " + template;
List<BaseContent> contents = new();
if (string.IsNullOrEmpty(message) == false) contents.Add(new PlainContent(message));
if (string.IsNullOrEmpty(ex.Message) == false) contents.Add(new PlainContent(ex.Message.cutString(200)));
List<BaseContent> contents = new List<BaseContent>();
contents.AddRange(template.SplitToChainAsync(sendTarget));
return contents;
}
Expand Down
3 changes: 2 additions & 1 deletion Theresa3rd-Bot/TheresaBot.Main/Helper/CommandHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using TheresaBot.Main.Common;
using TheresaBot.Main.Invoker;
using TheresaBot.Main.Model.Content;
using TheresaBot.Main.Type;

namespace TheresaBot.Main.Helper
{
Expand All @@ -11,7 +12,7 @@ public static class CommandHelper
public static async Task ReplyGroupSetuAndRevokeAsync(this GroupCommand command, SetuContent setuContent, int revokeInterval, bool sendImgBehind, bool isAt = false)
{
int[] msgIdArr = await command.ReplyGroupMessageAndRevokeAsync(setuContent, revokeInterval, sendImgBehind, isAt);
if (msgIdArr.Where(o => o < 0).Any())
if (msgIdArr.Where(o => o < 0).Any() && BotConfig.PixivConfig.ImgResend != ResendType.None)
{
await Task.Delay(1000);
SetuContent resendContent = setuContent.ToResendContent(BotConfig.PixivConfig.ImgResend);
Expand Down
2 changes: 1 addition & 1 deletion Theresa3rd-Bot/TheresaBot.Main/Helper/ContentHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public static class ContentHelper
{
public static SetuContent ToResendContent(this SetuContent setuContents, ResendType resendType)
{
if (resendType == ResendType.WithoutImg)
if (resendType == ResendType.None)
{
return null;
}
Expand Down
3 changes: 3 additions & 0 deletions Theresa3rd-Bot/TheresaBot.Main/Helper/FileHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static void DeleteFile(string fullFilePath)
{
try
{
if (!File.Exists(fullFilePath)) return;
File.Delete(fullFilePath);
}
catch (Exception ex)
Expand All @@ -37,6 +38,7 @@ public static void DeleteFile(FileInfo fileInfo)
{
try
{
if (fileInfo is null) return;
fileInfo.Delete();
}
catch (Exception ex)
Expand All @@ -49,6 +51,7 @@ public static void DeleteDirectory(string directoryPath)
{
try
{
if (!Directory.Exists(directoryPath)) return;
Directory.Delete(directoryPath, true);
}
catch (Exception ex)
Expand Down
2 changes: 1 addition & 1 deletion Theresa3rd-Bot/TheresaBot.Main/Helper/MathHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static int getMaxPage(int total, int eachPage)
/// <returns></returns>
public static string toPercent(this double number)
{
return (number * 100).ToString("0.000") + "%";
return (number * 100).ToString("0.00") + "%";
}

}
Expand Down
10 changes: 10 additions & 0 deletions Theresa3rd-Bot/TheresaBot.Main/Helper/PermissionsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ public static bool IsShowR18SetuImg(this long groupId)
return true;
}

/// <summary>
/// 判断是否存在其中一个群可以显示R18内容
/// </summary>
/// <param name="groupIds"></param>
/// <returns></returns>
public static bool IsShowR18Setu(this List<long> groupIds)
{
return groupIds.Where(o => o.IsShowR18Setu()).Any();
}

/// <summary>
/// 判断某一个群是否可以显示R18内容
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions Theresa3rd-Bot/TheresaBot.Main/Helper/PixivHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ private static async Task<FileInfo> DownPixivFileAsync(string url, Dictionary<st
try
{
if (string.IsNullOrWhiteSpace(fullFileName)) fullFileName = new HttpFileInfo(url).FullFileName;
string fullImgSavePath = Path.Combine(FilePath.GetTempSavePath(), fullFileName);
return await DownPixivFileAsync(url, fullImgSavePath, headerDic, timeout);
string fullFileSavePath = Path.Combine(FilePath.GetTempSavePath(), fullFileName);
return await DownPixivFileAsync(url, fullFileSavePath, headerDic, timeout);
}
catch (Exception ex)
{
Expand Down
Loading

0 comments on commit fac97d6

Please sign in to comment.