diff --git a/Document.md b/Document.md deleted file mode 100644 index d380298b..00000000 --- a/Document.md +++ /dev/null @@ -1,190 +0,0 @@ -# 部署文档 - -## 安装数据库 -- 数据库为mysql,需要自行安装([小白教程](https://github.com/GardenHamster/Theresa3rd-Bot/blob/main/MysqlInstall.md)),或者可以购买云数据库 - -## 安装mirai-console-loader -- 参照 [mirai-console-loader](https://github.com/iTXTech/mirai-console-loader) 文档安装mcl,并为mcl安装并配置 [mirai-api-http](https://github.com/project-mirai/mirai-api-http) 插件,([小白教程](https://github.com/GardenHamster/Theresa3rd-Bot/blob/main/MiraiInstall.md)) -- 最后在config/Console/AutoLogin.yml中配置bot账号密码并启动mcl,正常启动结果如下 -```bash -2022-02-13 18:09:37 I/main: Auto-login 123456789 -2022-02-13 18:09:38 I/Bot.123456789: Loaded account secrets from local cache. -2022-02-13 18:09:38 I/Bot.123456789: Saved account secrets to local cache for fast login. -2022-02-13 18:09:38 I/Bot.123456789: Login successful. -2022-02-13 18:09:39 V/Bot.123456789: Event: BotOnlineEvent(bot=Bot(123456789)) -2022-02-13 18:09:39 I/Bot.123456789: Bot login successful. -2022-02-13 18:09:39 I/main: mirai-console started successfully. -``` - -## 下载并修改配置文件 -- [点击这里下载最新版本](https://github.com/GardenHamster/Theresa3rd-Bot/releases),注:各版本之间的`botsettings.yml`可能会有较大差异,升级版本后请注意对比并修改该文件 -- 根据自己的需要修改根目录下的配置文件`botsettings.yml`,修改完成后需要重新启动,**注:参数值为空时需要用一对单引号代替,不能直接删掉什么也不加,不然会报错** -- [botsetting.yml的一些补充说明](https://github.com/GardenHamster/Theresa3rd-Bot/blob/main/botsetting.md),实在没接触过yml语法的小白可以看一下[这里](https://github.com/GardenHamster/Theresa3rd-Bot/blob/main/ymlconfig.md) -- 修改根目录下的配置文件appsettings.Production.json,使项目可以连接上mcl -```json5 -{ - "Mirai": { //mirai-api-http配置在mcl目录config/net.mamoe.mirai-api-http/setting.yml里面 - "host": "127.0.0.1", //mcl主机ip - "port": "8100", //mirai-api-http配置的port - "authKey": "theresa3rd", //mirai-api-http中配置的verifyKey - "botQQ": "123456789" //mcl中登录的QQ号 - }, - "Database": { - "ConnectionString": "Data Source=127.0.0.1;port=3306;Initial Catalog=theresa_bot;uid=root;pwd=123456;CharSet=utf8mb4;SslMode=None;" //mysql数据库链接,确保能连上数据库以后,然后改成自己的 - } -} - -``` - -## Linux下部署 -1、签名密钥并添加 Microsoft 包存储库 -```bash -sudo rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm -``` -2、安装ASP.NET Core 6.0 运行时 -```bash -sudo yum install aspnetcore-runtime-6.0 -``` -3、安装libgdiplus -```bash -yum install epel-release -``` -```bash -sudo yum install libgdiplus -``` -```bash -sudo ln -s /usr/lib/libgdiplus.so /usr/lib/gdiplus.dll -sudo ln -s /usr/lib64/libgdiplus.so /usr/lib64/gdiplus.dll -``` -4、切换到Theresa3rd-Bot.dll所在目录下,运行Theresa3rd-Bot.dll,这里的端口可以随意 -```bash -nohup dotnet Theresa3rd-Bot.dll --launch-profile Production --urls http://0.0.0.0:8088 -``` -5、如果使用#瑟图命令时报错:The remote certificate is invalid because of errors in the certificate chain: NotTimeValid,需要升级一下ca证书 -```bash -yum update ca-certificates -y -``` - -## Windows下部署 -- 下载并安装 [ASP.NET Core Runtime 6.0](https://dotnet.microsoft.com/en-us/download/dotnet/6.0),推荐下载页面中的 [Hosting Bundle](https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-aspnetcore-6.0.8-windows-hosting-bundle-installer) -- 启动powershell并将路径切换到Theresa3rd-Bot.dll所在目录下,~~或者在目标文件夹中,按住Shift然后右键,在此处打开Powershell窗口~~ - -- 运行Theresa3rd-Bot.dll,这里的端口可以随意 -```bash -dotnet Theresa3rd-Bot.dll --launch-profile Production --urls http://0.0.0.0:8088 -``` - -- 可以在桌面创建一个powershell.ps1脚本方便一键启动 -```bash -$host.ui.RawUI.WindowTitle="Theresa3rd-Bot" -cd C:\Theresa3rd-Bot -dotnet Theresa3rd-Bot.dll --launch-profile Production --urls http://0.0.0.0:8088 -``` - -## 正常运行结果如下 -```bash -2022-08-28 03:43:52,310 [1] INFO ConsoleLog - 日志配置完毕... -2022-08-28 03:43:52,441 [1] INFO ConsoleLog - 配置文件读取完毕... -2022-08-28 03:43:52,442 [1] INFO ConsoleLog - 开始初始化数据库... -2022-08-28 03:43:53,347 [1] INFO ConsoleLog - 数据库初始化完毕... -2022-08-28 03:43:53,393 [1] INFO ConsoleLog - 网站cookie加载完成... -2022-08-28 03:43:53,411 [1] INFO ConsoleLog - 订阅任务加载完成... -2022-08-28 03:43:53,418 [1] INFO ConsoleLog - 加载禁止标签完毕 -2022-08-28 03:43:53,420 [1] INFO ConsoleLog - 加载黑名单完毕 -2022-08-28 03:43:53,720 [1] INFO ConsoleLog - 定时器[深渊结算提醒]启动完毕... -2022-08-28 03:43:53,721 [1] INFO ConsoleLog - pixiv用户订阅任务启动完毕... -2022-08-28 03:43:53,722 [1] INFO ConsoleLog - pixiv标签订阅任务启动完毕... -2022-08-28 03:43:53,722 [1] INFO ConsoleLog - 米游社订阅任务启动完毕... -2022-08-28 03:43:53,725 [1] INFO ConsoleLog - 清理定时器启动完毕... -2022-08-28 03:43:53,727 [1] INFO ConsoleLog - Cookie检查定时器启动完毕... -2022-08-28 03:43:53,728 [1] INFO ConsoleLog - Theresa3rd-Bot启动完毕,版本:v0.7.1 -info: Microsoft.Hosting.Lifetime[14] - Now listening on: https://localhost:5001 -info: Microsoft.Hosting.Lifetime[14] - Now listening on: http://localhost:5000 -info: Microsoft.Hosting.Lifetime[0] - Application started. Press Ctrl+C to shut down. -info: Microsoft.Hosting.Lifetime[0] - Hosting environment: Development -info: Microsoft.Hosting.Lifetime[0] - Content root path: D:\Theresa3rd-Bot -2022-08-28 03:43:53,882 [8] INFO ConsoleLog - 已成功连接到mirai-console... -``` - -## 更新版本的步骤 -- 关掉正在运行的powershell脚本 -- 替换掉除了以下几个以外的文件 -```bash -botsettings.yml -appsettings.json -appsettings.Development.json -appsettings.Production.json -``` -- 检查一下botsettings.yml是否有更新,有则对比修改该文件,如果遇到修改比较多的情况可以对照旧文件重新修改一次 -- 重新启动脚本 - -## pixiv图片反向代理 -- 如果在qq中打开原图连接时出现感叹号,或者打不开原图链接时,[可以参考这里配置一个自己的反向代理域名](https://github.com/GardenHamster/Theresa3rd-Bot/blob/main/pixivproxy.md),然后修改相关配置 - -## 一些已知的错误 -### 数据库自动建表失败 -```bash -SqlSugar.SqlSugarException: 中文提示 : 连接数据库过程中发生错误,检查服务器是否正常连接字符串是否正确,实在找不到原因请先Google错误信息:The given key '0' was not present in the dictionary.. -English Message : Connection open error . The given key '0' was not present in the dictionary. - at SqlSugar.AdoProvider.GetDataReader(String sql, SugarParameter[] parameters) - at SqlSugar.AdoProvider.SqlQuery[T,T2,T3,T4,T5,T6,T7](String sql, Object parameters) - at SqlSugar.AdoProvider.SqlQuery[T](String sql, SugarParameter[] parameters) - at SqlSugar.AdoProvider.SqlQuery[T](String sql, Object parameters) - at SqlSugar.DbMaintenanceProvider.GetDataBaseList(SqlSugarClient db) - at SqlSugar.MySqlDbMaintenance.CreateDatabase(String databaseName, String databaseDirectory) - at SqlSugar.DbMaintenanceProvider.CreateDatabase(String databaseDirectory) - at Theresa3rd_Bot.Dao.DBClient.CreateDB() in D:\project\Theresa3rd-Bot\Theresa3rd-Bot\Dao\DBClient.cs:line 17 -``` -```bash -System.Collections.Generic.KeyNotFoundException: The given key '25185' was not present in the dictionary. - at SqlSugar.AdoProvider.GetDataReader(String sql, SugarParameter[] parameters) - at SqlSugar.AdoProvider.SqlQuery[T,T2,T3,T4,T5,T6,T7](String sql, Object parameters) - at SqlSugar.AdoProvider.SqlQuery[T](String sql, SugarParameter[] parameters) - at SqlSugar.AdoProvider.SqlQuery[T](String sql, Object parameters) - at SqlSugar.DbMaintenanceProvider.GetDataBaseList(SqlSugarClient db) - at SqlSugar.MySqlDbMaintenance.CreateDatabase(String databaseName, String databaseDirectory) - at SqlSugar.DbMaintenanceProvider.CreateDatabase(String databaseDirectory) - at Theresa3rd_Bot.Dao.DBClient.CreateDB() in D:\project\Theresa3rd-Bot\Theresa3rd-Bot\Dao\DBClient.cs:line 17 -``` -- 检查appsettings.Production.json中数据库链接字符串完整,完整的链接字符串如下 -```bash -Data Source=127.0.0.1;port=3306;Initial Catalog=theresa_bot;uid=root;pwd=123456;CharSet=utf8mb4;SslMode=None; -``` - -### yml语法错误 -- 遇到类似 `YamlDotNet.Core.YamlException` 情况需要重新检查 `botsetting.yml` 文件 -```bash -Unhandled exception. YamlDotNet.Core.YamlException: (Line: 18, Col: 30, Idx: 1361) - (Line: 18, Col: 49, Idx: 1380): Exception during deserialization - ---> System.FormatException: Input string was not in a correct format. - at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type) - at YamlDotNet.Serialization.NodeDeserializers.ScalarNodeDeserializer.DeserializeIntegerHelper(TypeCode typeCode, String value) - at YamlDotNet.Serialization.NodeDeserializers.ScalarNodeDeserializer.YamlDotNet.Serialization.INodeDeserializer.Deserialize(IParser parser, Type expectedType, Func`3 nestedObjectDeserializer, Object& value) - at YamlDotNet.Serialization.ValueDeserializers.NodeValueDeserializer.DeserializeValue(IParser parser, Type expectedType, SerializerState state, IValueDeserializer nestedObjectDeserializer) - --- End of inner exception stack trace --- - at YamlDotNet.Serialization.ValueDeserializers.NodeValueDeserializer.DeserializeValue(IParser parser, Type expectedType, SerializerState state, IValueDeserializer nestedObjectDeserializer) - at YamlDotNet.Serialization.ValueDeserializers.AliasValueDeserializer.DeserializeValue(IParser parser, Type expectedType, SerializerState state, IValueDeserializer nestedObjectDeserializer) - at YamlDotNet.Serialization.ValueDeserializers.NodeValueDeserializer.<>c__DisplayClass3_0.b__0(IParser r, Type t) -``` - -### linux下报错The remote certificate is invalid because of errors in the certificate chain: NotTimeValid -- 更新一下ca证书 -```bash -yum update ca-certificates -y -``` - -### bot没有回复或者只回复表情 -**只有#pixivcookie等更新cookie的指令需要私发给机器人以外,其他指令都要发送到群里面** - -**有可能是你发送的不是一个指令,或者这个指令不存在,或者发送的指令前缀不一致,或者你修改了配置文件以后没有重启** - -私聊bot但是只会回复表情的情况: -- 需要加bot为好友 - -群聊bot但是没有回应的情况 -- 配置文件中AcceptGroups没有配置群号,或者群号填写错误 -- mcl中机器人有回应但是群里没有消息出来,那可能是你的bot账号是刚注册没多久的,或者内容太色了mht不让你发 diff --git a/MysqlInstall.md b/MysqlInstall.md deleted file mode 100644 index f4eba4e7..00000000 --- a/MysqlInstall.md +++ /dev/null @@ -1,53 +0,0 @@ -# Mysql安装 - -## 下载 -- 从 [mysql官网](https://dev.mysql.com/downloads/installer) 中下载最新版本,或者点击直接下载 [MySQL Installer 8.0.31](https://dev.mysql.com/get/Downloads/MySQLInstaller/mysql-installer-community-8.0.31.0.msi) -## 安装 - -### 打开刚下载的安装包 -![image](https://user-images.githubusercontent.com/89188316/161034492-b420439a-f5fb-4bfd-bc3a-d43e63ac9bb5.png) - -### 选择Full(完全安装),然后一直Next -![image](https://user-images.githubusercontent.com/89188316/161034853-96cc6e51-3a71-4621-8b22-1e066ba3b4c1.png) - -### 选择Yes -![image](https://user-images.githubusercontent.com/89188316/161035483-5c07bc2a-2b0c-4839-97a0-77872064cb50.png) - -### 接着Execute等待执行完毕,然后保持默认一直Next -![image](https://user-images.githubusercontent.com/89188316/161036291-05d4f84d-7d61-470c-b12d-be219bd8e85c.png) - -### 这里选择第二项 -![image](https://user-images.githubusercontent.com/89188316/161036600-0c7eb97c-5c65-4c9f-880f-09f8a8283869.png) - -### 这里设置一下数据库密码 -![image](https://user-images.githubusercontent.com/89188316/161037041-b2891423-b1ec-4705-9deb-c94785645760.png) - -### 接着一路Next、Execute、Finish -![image](https://user-images.githubusercontent.com/89188316/161037448-f0ff8f57-68a0-4a56-9d40-aef87be72f02.png) - -### 将刚才设置的数据库密码填入Password中,然后点check,显示Connection successded后点一路Next、Execute、Finish -![image](https://user-images.githubusercontent.com/89188316/161037965-01a850d5-cc5f-484f-b60f-f8e4cb07a7ed.png) - -### 完成后会打开一个Mysql Workbench,点一下下面这个连接 -![image](https://user-images.githubusercontent.com/89188316/161039046-bbf3b5de-0d7a-44df-a178-8a4ac53396e7.png) - -### 输入数据库密码 -![image](https://user-images.githubusercontent.com/89188316/161039376-873eac51-2a37-45a2-ad68-91418f1914b2.png) - -### 能进来表示安装成功了 -![image](https://user-images.githubusercontent.com/89188316/161039540-72f1b007-4266-40e8-8ab0-8e0df30ef04f.png) - -### 如果打开失败,检查一下mysql服务有没有打开 -- 搜索 服务 或者 services.msc -![image](https://user-images.githubusercontent.com/89188316/161040329-7fde87a3-4268-47dd-92e4-88059add0170.png) - -- 找到Mysql,如果没有正在运行的话,点击右键启动 -![image](https://user-images.githubusercontent.com/89188316/161040800-bc413e1d-02e2-4b69-9e78-b823d349b75e.png) - -## 将数据库密码写入到bot配置文件中 -### 推荐安装一个NodePad++编辑器 -### 用NodePad++打开appsettings.Production.json -### 将配置文件中pwd的值(这里是123456),改为刚才设置的数据库密码,然后保存 -![image](https://user-images.githubusercontent.com/89188316/161043245-510c6c00-a2f1-4ed1-864c-f420c4795635.png) - - diff --git a/Theresa3rd-Bot/TheresaBot.Main/Business/LocalSetuBusiness.cs b/Theresa3rd-Bot/TheresaBot.Main/Business/LocalSetuBusiness.cs index bcbbc654..662a0ee9 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Business/LocalSetuBusiness.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Business/LocalSetuBusiness.cs @@ -6,16 +6,17 @@ namespace TheresaBot.Main.Business { public class LocalSetuBusiness : SetuBusiness { - public List loadRandom(string localPath, int count, bool fromOneDir = false) + public List loadRandomDir(string localPath, int count, bool fromOneDir = false) { List setuList = new List(); DirectoryInfo localDir = new DirectoryInfo(localPath); DirectoryInfo[] directoryInfos = localDir.GetDirectories(); - int randomDirIndex = new Random().Next(0, directoryInfos.Length); + if (directoryInfos.Length == 0) throw new Exception($"localPath路径下不存在子文件夹,请在子文件夹下存放图片"); + int singleDirIndex = new Random().Next(0, directoryInfos.Length); for (int i = 0; i < count; i++) { - randomDirIndex = fromOneDir ? randomDirIndex : new Random().Next(0, directoryInfos.Length); - DirectoryInfo randomDir = directoryInfos[randomDirIndex]; + int dirIndex = fromOneDir ? singleDirIndex : new Random().Next(0, directoryInfos.Length); + DirectoryInfo randomDir = directoryInfos[dirIndex]; FileInfo[] fileInfos = randomDir.GetFiles(); if (fileInfos.Length == 0) continue; int randomFileIndex = new Random().Next(0, fileInfos.Length); @@ -25,11 +26,12 @@ public List loadRandom(string localPath, int count, bool fromOneD return setuList; } - public List loadInDir(string localPath, string dirName, int count) + public List loadTargetDir(string localPath, string dirName, int count) { List setuList = new List(); DirectoryInfo localDir = new DirectoryInfo(localPath); DirectoryInfo[] directoryInfos = localDir.GetDirectories(); + if (directoryInfos is null || directoryInfos.Length == 0) return setuList; DirectoryInfo directoryInfo = directoryInfos.Where(o => o.Name.ToLower() == dirName.ToLower()).FirstOrDefault(); if (directoryInfo is null) return setuList; FileInfo[] fileInfos = directoryInfo.GetFiles(); diff --git a/Theresa3rd-Bot/TheresaBot.Main/Business/PixivRankingBusiness.cs b/Theresa3rd-Bot/TheresaBot.Main/Business/PixivRankingBusiness.cs index a7c97b67..d459aca4 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Business/PixivRankingBusiness.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Business/PixivRankingBusiness.cs @@ -72,7 +72,8 @@ public async Task> filterContents(PixivRankingItem rank await Task.Delay(500); if (pixivWorkInfo is null) continue; if (checkWorkIsOk(rankingItem, pixivWorkInfo) == false) continue; - FileInfo previewFile = await PixivHelper.DownPixivImgAsync(rankingContent.illust_id.ToString(), rankingContent.url); + string fullFileName = rankingContent.url.GetPreviewImgSaveName(pixivWorkInfo.illustId); + FileInfo previewFile = await PixivHelper.DownPixivImgAsync(rankingContent.illust_id.ToString(), rankingContent.url, fullFileName); PixivRankingDetail rankingDetail = new PixivRankingDetail(rankingContent, pixivWorkInfo, previewFile?.FullName); rankingDetails.Add(rankingDetail); } diff --git a/Theresa3rd-Bot/TheresaBot.Main/Common/BotConfig.cs b/Theresa3rd-Bot/TheresaBot.Main/Common/BotConfig.cs index 7f0e4005..f1462e72 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Common/BotConfig.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Common/BotConfig.cs @@ -7,10 +7,8 @@ namespace TheresaBot.Main.Common { public static class BotConfig { - public const string BotVersion = "v0.8.0"; + public const string BotVersion = "v0.8.1"; public const string BotHomepage = "https://www.theresa3rd.cn"; - public static DBConfig DBConfig = new DBConfig(); - public static MiraiConfig MiraiConfig = new MiraiConfig(); public static GeneralConfig GeneralConfig = new GeneralConfig(); public static PixivConfig PixivConfig = new PixivConfig(); public static PermissionsConfig PermissionsConfig = new PermissionsConfig(); @@ -29,5 +27,7 @@ public static class BotConfig public static List BanSetuTagList = new List(); public static List BanMemberList = new List(); + + } } diff --git a/Theresa3rd-Bot/TheresaBot.Main/Common/FilePath.cs b/Theresa3rd-Bot/TheresaBot.Main/Common/FilePath.cs index e9920bd0..c0402111 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Common/FilePath.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Common/FilePath.cs @@ -1,33 +1,108 @@ -namespace TheresaBot.Main.Common +using TheresaBot.Main.Helper; + +namespace TheresaBot.Main.Common { public static class FilePath { private const string DownDir = "BotDownload"; + private const string TempDir = "Temp"; + private const string MiyousheDir = "Miyoushe"; + private const string PixivWorkDir = "PixivWork"; + private const string PixivPreviewDir = "PixivPreview"; + + /// + /// 获取图片下载错误后的替代图片 + /// + /// + public static FileInfo GetDownErrorImg() + { + string fullImgPath = BotConfig.GeneralConfig.DownErrorImgPath; + if (File.Exists(fullImgPath) == false) return null; + return new FileInfo(fullImgPath); + } /// - /// 获取下载图的保存的绝对路径 + /// 获取下载图片的保存路径 /// - /// /// public static string GetDownFileSavePath() { string configPath = BotConfig.GeneralConfig.DownloadPath; if (string.IsNullOrWhiteSpace(configPath)) configPath = AppContext.BaseDirectory; string savePath = Path.Combine(configPath, DownDir); - if (Directory.Exists(savePath) == false) Directory.CreateDirectory(savePath); + if (!Directory.Exists(savePath)) Directory.CreateDirectory(savePath); return savePath; } /// - /// 获取图片下载错误后的替代图片 + /// 获取米游社图片存放路径 /// /// - public static FileInfo GetDownErrorImg() + public static string GetFullMysImgSavePath(string imgUrl) { - string fullImgPath = BotConfig.GeneralConfig.DownErrorImgPath; - if (File.Exists(fullImgPath) == false) return null; - return new FileInfo(fullImgPath); + string suffix = StringHelper.getSuffixByUrl(imgUrl); + if (string.IsNullOrEmpty(suffix)) suffix = "jpg"; + string fullFileName = StringHelper.get16UUID() + "." + suffix; + string downFilePath = GetDownFileSavePath(); + string savePath = Path.Combine(downFilePath, MiyousheDir); + if (!Directory.Exists(savePath)) Directory.CreateDirectory(savePath); + return Path.Combine(savePath, fullFileName); } + /// + /// 获取pixiv图片存放路径 + /// + /// + /// + public static string GetPixivImgSavePath(int pixivId) + { + string downFilePath = GetDownFileSavePath(); + string pixivImgDir = GetPixivImgDir(pixivId); + string savePath = Path.Combine(downFilePath, PixivWorkDir, pixivImgDir); + if (!Directory.Exists(savePath)) Directory.CreateDirectory(savePath); + return savePath; + } + + /// + /// 获取pixiv日榜大图存放路径 + /// + /// + /// + public static string GetPixivPreviewSavePath() + { + string downFilePath = GetDownFileSavePath(); + string savePath = Path.Combine(downFilePath, PixivPreviewDir); + if (!Directory.Exists(savePath)) Directory.CreateDirectory(savePath); + return savePath; + } + + /// + /// 获取临时文件存放路径 + /// + /// + /// + public static string GetTempSavePath() + { + string downFilePath = GetDownFileSavePath(); + string savePath = Path.Combine(downFilePath, TempDir); + if (!Directory.Exists(savePath)) Directory.CreateDirectory(savePath); + return savePath; + } + + /// + /// 获取pixiv图片存放文件夹名称 + /// + /// + /// + private static string GetPixivImgDir(int pixivId) + { + //105866144 + if (pixivId > 100000000) return $"{(pixivId / 100000) * 100000}"; + if (pixivId > 80000000) return $"{(pixivId / 5000000) * 5000000}"; + if (pixivId > 50000000) return $"{(pixivId / 10000000) * 10000000}"; + return "50000000"; + } + + } } diff --git a/Theresa3rd-Bot/TheresaBot.Main/Common/HttpUrl.cs b/Theresa3rd-Bot/TheresaBot.Main/Common/HttpUrl.cs index fcca1180..1567d709 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Common/HttpUrl.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Common/HttpUrl.cs @@ -1,6 +1,4 @@ -using Microsoft.AspNetCore.Mvc.RazorPages; - -namespace TheresaBot.Main.Common +namespace TheresaBot.Main.Common { public static class HttpUrl { @@ -211,7 +209,7 @@ public static string getLoliconApiV2Url() /// public static string getLolisukiApiUrl() { - return "https://lolisuki.cc/api/setu/v1"; + return "https://lolisuki.cn/api/setu/v1"; } /*---------------------------------------------------------------米游社-----------------------------------------------------------------------*/ diff --git a/Theresa3rd-Bot/TheresaBot.Main/Handler/LocalSetuHandler.cs b/Theresa3rd-Bot/TheresaBot.Main/Handler/LocalSetuHandler.cs index d8215a3c..e37ae1a1 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Handler/LocalSetuHandler.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Handler/LocalSetuHandler.cs @@ -29,7 +29,7 @@ public async Task localSearchAsync(GroupCommand command) CoolingCache.SetHanding(command.GroupId, command.MemberId);//请求处理中 - string localPath = BotConfig.TimingSetuConfig.LocalPath; + string localPath = BotConfig.SetuConfig.Local.LocalPath; if (string.IsNullOrWhiteSpace(localPath)) throw new Exception($"未配置LocalPath"); if (Directory.Exists(localPath) == false) throw new Exception($"本地涩图路径:{localPath}不存在"); @@ -37,12 +37,12 @@ public async Task localSearchAsync(GroupCommand command) if (string.IsNullOrEmpty(tagName)) { - dataList = localSetuBusiness.loadRandom(localPath, 1, true); + dataList = localSetuBusiness.loadRandomDir(localPath, 1, true); } else { if (await CheckSetuCustomEnableAsync(command) == false) return; - dataList = localSetuBusiness.loadInDir(localPath, tagName, 1); + dataList = localSetuBusiness.loadTargetDir(localPath, tagName, 1); } if (dataList.Count == 0) @@ -83,18 +83,19 @@ public async Task localSearchAsync(GroupCommand command) public async Task sendTimingSetuAsync(TimingSetuTimer timingSetuTimer, long groupId) { + int margeEachPage = 5; bool sendMerge = timingSetuTimer.SendMerge; bool fromOneDir = BotConfig.TimingSetuConfig.FromOneDir; string localPath = BotConfig.TimingSetuConfig.LocalPath; if (string.IsNullOrWhiteSpace(localPath)) throw new Exception($"未配置LocalPath"); if (Directory.Exists(localPath) == false) throw new Exception($"本地涩图路径:{localPath}不存在"); - List dataList = localSetuBusiness.loadRandom(localPath, timingSetuTimer.Quantity, fromOneDir); + List dataList = localSetuBusiness.loadRandomDir(localPath, timingSetuTimer.Quantity, fromOneDir); if (dataList is null || dataList.Count == 0) throw new Exception("未能在LocalPath中读取任何涩图"); string tags = fromOneDir ? dataList[0].DirInfo.Name : ""; List setuContents = getSetuContent(dataList); await sendTimingSetuMessageAsync(timingSetuTimer, tags, groupId); await Task.Delay(2000); - await Session.SendGroupSetuAsync(setuContents, groupId, sendMerge); + await Session.SendGroupSetuAsync(setuContents, groupId, sendMerge, margeEachPage); } private List getSetuContent(List datas) diff --git a/Theresa3rd-Bot/TheresaBot.Main/Handler/LoliconHandler.cs b/Theresa3rd-Bot/TheresaBot.Main/Handler/LoliconHandler.cs index 91e52c8d..2b5439ba 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Handler/LoliconHandler.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Handler/LoliconHandler.cs @@ -95,6 +95,7 @@ public async Task sendTimingSetuAsync(TimingSetuTimer timingSetuTimer, long grou { try { + int margeEachPage = 5; bool sendMerge = timingSetuTimer.SendMerge; int r18Mode = groupId.IsShowR18Setu() ? 2 : 0; bool excludeAI = groupId.IsShowAISetu() == false; @@ -105,7 +106,7 @@ public async Task sendTimingSetuAsync(TimingSetuTimer timingSetuTimer, long grou List setuContents = await getSetuContent(dataList, groupId); await sendTimingSetuMessageAsync(timingSetuTimer, tagStr, groupId); await Task.Delay(2000); - await Session.SendGroupSetuAsync(setuContents, groupId, sendMerge); + await Session.SendGroupSetuAsync(setuContents, groupId, sendMerge, margeEachPage); } catch (Exception ex) { diff --git a/Theresa3rd-Bot/TheresaBot.Main/Handler/LolisukiHandler.cs b/Theresa3rd-Bot/TheresaBot.Main/Handler/LolisukiHandler.cs index d926f378..44b6ffcd 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Handler/LolisukiHandler.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Handler/LolisukiHandler.cs @@ -99,6 +99,7 @@ public async Task sendTimingSetuAsync(TimingSetuTimer timingSetuTimer, long grou { try { + int margeEachPage = 5; bool isShowAI = groupId.IsShowAISetu(); bool isShowR18 = groupId.IsShowR18Setu(); string levelStr = getLevelStr(isShowR18); @@ -112,7 +113,7 @@ public async Task sendTimingSetuAsync(TimingSetuTimer timingSetuTimer, long grou List setuContents = await getSetuContent(dataList, groupId); await sendTimingSetuMessageAsync(timingSetuTimer, tagStr, groupId); await Task.Delay(2000); - await Session.SendGroupSetuAsync(setuContents, groupId, sendMerge); + await Session.SendGroupSetuAsync(setuContents, groupId, sendMerge, margeEachPage); } catch (Exception ex) { diff --git a/Theresa3rd-Bot/TheresaBot.Main/Handler/MYSHandler.cs b/Theresa3rd-Bot/TheresaBot.Main/Handler/MYSHandler.cs index 5dbe666c..ae894855 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Handler/MYSHandler.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Handler/MYSHandler.cs @@ -85,8 +85,15 @@ public async Task subscribeMYSUserAsync(GroupCommand command) chailList.Add(new PlainContent($"目标群:{Enum.GetName(typeof(SubscribeGroupType), groupType)}\r\n")); chailList.Add(new PlainContent($"uid:{dbSubscribe.SubscribeCode}\r\n")); chailList.Add(new PlainContent($"签名:{dbSubscribe.SubscribeDescription}\r\n")); - FileInfo fileInfo = string.IsNullOrEmpty(userInfoDto.data.user_info.avatar_url) ? null : await HttpHelper.DownImgAsync(userInfoDto.data.user_info.avatar_url); - if (fileInfo != null) chailList.Add(new LocalImageContent(SendTarget.Group, fileInfo)); + + string avatar_url = userInfoDto.data.user_info.avatar_url; + if (string.IsNullOrWhiteSpace(avatar_url) == false) + { + string fullImgSavePath = FilePath.GetFullMysImgSavePath(avatar_url); + FileInfo fileInfo = await HttpHelper.DownImgAsync(avatar_url, fullImgSavePath); + if (fileInfo != null) chailList.Add(new LocalImageContent(SendTarget.Group, fileInfo)); + } + await command.ReplyGroupMessageWithAtAsync(chailList); ConfigHelper.LoadSubscribeTask(); } @@ -181,20 +188,17 @@ private async Task sendGroupSubscribeAsync(SubscribeTask subscribeTask, List msgList = new List(); msgList.Add(new PlainContent(mysBusiness.getPostInfoAsync(mysSubscribe, BotConfig.SubscribeConfig.Miyoushe.Template))); - if (string.IsNullOrEmpty(coverUrl) == false) - { - fileInfo = await HttpHelper.DownImgAsync(mysSubscribe.SubscribeRecord.CoverUrl); - } - if (fileInfo != null) + if (string.IsNullOrWhiteSpace(coverUrl) == false) { - msgList.Add(new LocalImageContent(SendTarget.Group, fileInfo)); + string fullImgSavePath = FilePath.GetFullMysImgSavePath(coverUrl); + FileInfo fileInfo = await HttpHelper.DownImgAsync(coverUrl, fullImgSavePath); + if (fileInfo != null) msgList.Add(new LocalImageContent(SendTarget.Group, fileInfo)); } foreach (long groupId in subscribeTask.GroupIdList) diff --git a/Theresa3rd-Bot/TheresaBot.Main/Handler/PixivRankingHandler.cs b/Theresa3rd-Bot/TheresaBot.Main/Handler/PixivRankingHandler.cs index a600f6d8..5f56a64a 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Handler/PixivRankingHandler.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Handler/PixivRankingHandler.cs @@ -229,9 +229,9 @@ private List createPreviewImg(PixivRankingInfo rankingInfo) while (startIndex < details.Count) { string fileName = $"{rankingMode.Code}_preview_{rankingInfo.RankingDate}_{startIndex}_{startIndex + previewInPage}.jpg"; - string savePath = Path.Combine(FilePath.GetDownFileSavePath(), fileName); + string fullSavePath = Path.Combine(FilePath.GetPixivPreviewSavePath(), fileName); var partList = details.Skip(startIndex).Take(previewInPage).ToList(); - var previewFile = createPreviewImg(rankingInfo, partList, savePath); + var previewFile = createPreviewImg(rankingInfo, partList, fullSavePath); if (previewFile is not null) fileInfos.Add(previewFile.FullName); startIndex += previewInPage; } diff --git a/Theresa3rd-Bot/TheresaBot.Main/Handler/SaucenaoHandler.cs b/Theresa3rd-Bot/TheresaBot.Main/Handler/SaucenaoHandler.cs index 1675ce07..112a5e81 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Handler/SaucenaoHandler.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Handler/SaucenaoHandler.cs @@ -78,7 +78,7 @@ public async Task searchResult(GroupCommand command) if (BotConfig.SaucenaoConfig.RevokeSearched) { await Task.Delay(1000); - await command.RevokeGroupMessageAsync(revokeMsgId, command.MsgId); + await command.RevokeGroupMessageAsync(revokeMsgId, command.GroupId); } if (notFoundList.Count > 0 && await CheckContinueAscii2d(command, notFoundList)) diff --git a/Theresa3rd-Bot/TheresaBot.Main/Handler/SetuHandler.cs b/Theresa3rd-Bot/TheresaBot.Main/Handler/SetuHandler.cs index 5f9671be..7d281aa8 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Handler/SetuHandler.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Handler/SetuHandler.cs @@ -207,21 +207,22 @@ public async Task> downPixivImgsAsync(BaseWorkInfo pixivWorkInfo) /// /// /// - protected async Task downAndComposeGifAsync(string pixivId) + protected async Task downAndComposeGifAsync(string pixivIdStr) { try { - string fullGifSavePath = Path.Combine(FilePath.GetDownFileSavePath(), $"{pixivId}.gif"); + int pixivId = Convert.ToInt32(pixivIdStr); + string fullGifSavePath = Path.Combine(FilePath.GetPixivImgSavePath(pixivId), $"{pixivId}.gif"); if (File.Exists(fullGifSavePath)) return new FileInfo(fullGifSavePath); - PixivUgoiraMeta pixivUgoiraMetaDto = await PixivHelper.GetPixivUgoiraMetaAsync(pixivId); + PixivUgoiraMeta pixivUgoiraMetaDto = await PixivHelper.GetPixivUgoiraMetaAsync(pixivIdStr); string zipHttpUrl = pixivUgoiraMetaDto.src; - string fullZipSavePath = Path.Combine(FilePath.GetDownFileSavePath(), $"{pixivId}.zip"); - FileInfo zipFile = await PixivHelper.DownPixivFileAsync(pixivId, zipHttpUrl, fullZipSavePath); + string fullZipSavePath = Path.Combine(FilePath.GetTempSavePath(), $"{pixivId}.zip"); + FileInfo zipFile = await PixivHelper.DownPixivFileAsync(pixivIdStr, zipHttpUrl, fullZipSavePath); if (zipFile == null) return null; - string unZipDirPath = Path.Combine(FilePath.GetDownFileSavePath(), pixivId); + string unZipDirPath = Path.Combine(FilePath.GetTempSavePath(), pixivIdStr); ZipHelper.ZipToFile(zipFile.FullName, unZipDirPath); DirectoryInfo directoryInfo = new DirectoryInfo(unZipDirPath); diff --git a/Theresa3rd-Bot/TheresaBot.Main/Helper/BusinessHelper.cs b/Theresa3rd-Bot/TheresaBot.Main/Helper/BusinessHelper.cs index 076b5e21..58cb3c54 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Helper/BusinessHelper.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Helper/BusinessHelper.cs @@ -187,9 +187,10 @@ public static List GetErrorContents(this Exception ex, SendTarget s string template = BotConfig.GeneralConfig.ErrorMsg; if (string.IsNullOrWhiteSpace(template)) template = "出了点小问题,再试一次吧~"; if (template.StartsWith(" ") == false) template = " " + template; - List contents = template.SplitToChainAsync(sendTarget); + List 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))); + contents.AddRange(template.SplitToChainAsync(sendTarget)); return contents; } diff --git a/Theresa3rd-Bot/TheresaBot.Main/Helper/ConfigHelper.cs b/Theresa3rd-Bot/TheresaBot.Main/Helper/ConfigHelper.cs index b391aee7..4072155a 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Helper/ConfigHelper.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Helper/ConfigHelper.cs @@ -1,5 +1,4 @@ -using Microsoft.Extensions.Configuration; -using System.Text; +using System.Text; using TheresaBot.Main.Business; using TheresaBot.Main.Common; using TheresaBot.Main.Model.Config; @@ -11,25 +10,6 @@ namespace TheresaBot.Main.Helper { public class ConfigHelper { - private static IConfiguration Configuration; - - public static void setConfiguration(IConfiguration configuration) - { - Configuration = configuration; - } - - /// - /// 加载MiraiHttpApi配置 - /// - public static void LoadMiraiConfig() - { - BotConfig.DBConfig.ConnectionString = Configuration["Database:ConnectionString"]; - BotConfig.MiraiConfig.Host = Configuration["Mirai:host"]; - BotConfig.MiraiConfig.Port = Convert.ToInt32(Configuration["Mirai:port"]); - BotConfig.MiraiConfig.AuthKey = Configuration["Mirai:authKey"]; - BotConfig.MiraiConfig.BotQQ = Convert.ToInt64(Configuration["Mirai:botQQ"]); - } - /// /// 加载botsetting.yml配置 /// @@ -42,7 +22,7 @@ public static void LoadBotConfig() Deserializer deserializer = new Deserializer(); BotConfigDto botConfig = deserializer.Deserialize(reader); BotConfig.GeneralConfig = botConfig.General; - BotConfig.PixivConfig = botConfig.Pixiv; + BotConfig.PixivConfig = botConfig.Pixiv.FormatConfig(); BotConfig.PermissionsConfig = botConfig.Permissions; BotConfig.ManageConfig = botConfig.Manage; BotConfig.MenuConfig = botConfig.Menu; diff --git a/Theresa3rd-Bot/TheresaBot.Main/Helper/FileHelper.cs b/Theresa3rd-Bot/TheresaBot.Main/Helper/FileHelper.cs index 7929a56f..9ac1be53 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Helper/FileHelper.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Helper/FileHelper.cs @@ -4,11 +4,6 @@ namespace TheresaBot.Main.Helper { public static class FileHelper { - public static void clearHistoryImg() - { - clearDownloadImg(); - } - public static bool IsFilesExists(this List fullFilePaths) { if (fullFilePaths is null || fullFilePaths.Count == 0) return false; @@ -19,21 +14,6 @@ public static bool IsFilesExists(this List fullFilePaths) return true; } - public static void clearDownloadImg() - { - try - { - string path = FilePath.GetDownFileSavePath(); - DirectoryInfo directoryInfo = new DirectoryInfo(path); - FileInfo[] fileInfoArr = directoryInfo.GetFiles(); - foreach (FileInfo fileInfo in fileInfoArr) deleteFile(fileInfo); - } - catch (Exception ex) - { - LogHelper.Error(ex); - } - } - public static void deleteFile(string fullFilePath) { try diff --git a/Theresa3rd-Bot/TheresaBot.Main/Helper/HttpHelper.cs b/Theresa3rd-Bot/TheresaBot.Main/Helper/HttpHelper.cs index 394d2979..55e64aff 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Helper/HttpHelper.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Helper/HttpHelper.cs @@ -51,7 +51,7 @@ static HttpHelper() /// public static async Task GetAsync(string url, Dictionary headerDic = null, int timeout = 60000) { - HttpClient client = DefaultHttpClientFactory.CreateClient(); + using HttpClient client = DefaultHttpClientFactory.CreateClient(); client.BaseAddress = new Uri(url); client.addHeaders(headerDic); client.DefaultRequestHeaders.Add("User-Agent", GetRandomUserAgent()); @@ -70,7 +70,7 @@ public static async Task GetAsync(string url, Dictionary /// public static async Task GetWithProxyAsync(string url, Dictionary headerDic = null, int timeout = 60000) { - HttpClient client = ProxyHttpClientFactory.CreateClient("ProxyClient"); + using HttpClient client = ProxyHttpClientFactory.CreateClient("ProxyClient"); client.BaseAddress = new Uri(url); client.addHeaders(headerDic); client.DefaultRequestHeaders.Add("User-Agent", GetRandomUserAgent()); @@ -92,7 +92,7 @@ public static async Task PostJsonAsync(string url, string postJsonStr, D { HttpContent content = new StringContent(postJsonStr); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); - HttpClient client = DefaultHttpClientFactory.CreateClient(); + using HttpClient client = DefaultHttpClientFactory.CreateClient(); client.addHeaders(headerDic); client.DefaultRequestHeaders.Add("User-Agent", GetRandomUserAgent()); client.Timeout = TimeSpan.FromMilliseconds(timeout); @@ -111,7 +111,7 @@ public static async Task PostJsonAsync(string url, string postJsonStr, D /// public static async Task PostFormForHtml(string url, Dictionary paramDic, Dictionary headerDic = null, int timeout = 60000) { - HttpClient client = DefaultHttpClientFactory.CreateClient(); + using HttpClient client = DefaultHttpClientFactory.CreateClient(); client.addHeaders(headerDic); client.DefaultRequestHeaders.Add("User-Agent", GetRandomUserAgent()); client.Timeout = TimeSpan.FromMilliseconds(timeout); @@ -128,7 +128,7 @@ public static async Task PostFormForHtml(string url, Dictio public static async Task PostImageAsync(string postUrl, FileInfo imageFile, Dictionary headerDic = null, int timeout = 60000) { using FileStream fs = new FileStream(imageFile.FullName, FileMode.Open, FileAccess.Read); - HttpClient client = DefaultHttpClientFactory.CreateClient(); + using HttpClient client = DefaultHttpClientFactory.CreateClient(); client.addHeaders(headerDic); client.Timeout = TimeSpan.FromMilliseconds(timeout); client.DefaultRequestHeaders.Add("User-Agent", GetRandomUserAgent()); @@ -150,7 +150,7 @@ public static async Task PostImageAsync(string postUrl, FileInfo imageFi /// public static async Task GetHtmlAsync(string httpUrl, Dictionary headerDic = null, int timeout = 60000) { - HttpClient client = DefaultHttpClientFactory.CreateClient(); + using HttpClient client = DefaultHttpClientFactory.CreateClient(); client.addHeaders(headerDic); client.Timeout = TimeSpan.FromMilliseconds(timeout); client.DefaultRequestHeaders.Add("User-Agent", GetRandomUserAgent()); @@ -162,12 +162,8 @@ public static async Task GetHtmlAsync(string httpUrl, Dictionary /// /// - public static async Task DownImgAsync(string imgUrl, Dictionary headerDic = null, int timeout = 120000) + public static async Task DownImgAsync(string imgUrl, string fullImageSavePath, Dictionary headerDic = null, int timeout = 120000) { - string suffix = StringHelper.getSuffixByUrl(imgUrl); - if (string.IsNullOrEmpty(suffix)) suffix = "jpg"; - string fullFileName = StringHelper.get16UUID() + "." + suffix; - string fullImageSavePath = Path.Combine(FilePath.GetDownFileSavePath(), fullFileName); return await HttpHelper.DownFileAsync(imgUrl, fullImageSavePath, headerDic, timeout); } @@ -181,7 +177,7 @@ public static async Task DownImgAsync(string imgUrl, Dictionary DownFileAsync(string imgUrl, string fullImageSavePath, Dictionary headerDic = null, int timeout = 120000) { if (File.Exists(fullImageSavePath)) return new FileInfo(fullImageSavePath); - HttpClient client = DefaultHttpClientFactory.CreateClient(); + using HttpClient client = DefaultHttpClientFactory.CreateClient(); client.addHeaders(headerDic); client.Timeout = TimeSpan.FromMilliseconds(timeout); client.DefaultRequestHeaders.Add("User-Agent", GetRandomUserAgent()); @@ -203,7 +199,7 @@ public static async Task DownFileAsync(string imgUrl, string fullImage public static async Task DownFileWithProxyAsync(string imgUrl, string fullImageSavePath, Dictionary headerDic = null, int timeout = 120000) { if (File.Exists(fullImageSavePath)) return new FileInfo(fullImageSavePath); - HttpClient client = ProxyHttpClientFactory.CreateClient("ProxyClient"); + using HttpClient client = ProxyHttpClientFactory.CreateClient("ProxyClient"); client.addHeaders(headerDic); client.Timeout = TimeSpan.FromMilliseconds(timeout); client.DefaultRequestHeaders.Add("User-Agent", GetRandomUserAgent()); diff --git a/Theresa3rd-Bot/TheresaBot.Main/Helper/ImageHelper.cs b/Theresa3rd-Bot/TheresaBot.Main/Helper/ImageHelper.cs index 0a8ec61f..e8cc38ab 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Helper/ImageHelper.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Helper/ImageHelper.cs @@ -1,14 +1,7 @@ -using System.Drawing; -using System.Drawing.Drawing2D; -using System.Drawing.Imaging; - -namespace TheresaBot.Main.Helper +namespace TheresaBot.Main.Helper { public static class ImageHelper { - - - } } diff --git a/Theresa3rd-Bot/TheresaBot.Main/Helper/PixivHelper.cs b/Theresa3rd-Bot/TheresaBot.Main/Helper/PixivHelper.cs index 8d320510..1bf7cc9c 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Helper/PixivHelper.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Helper/PixivHelper.cs @@ -6,6 +6,7 @@ using System.Net.Sockets; using TheresaBot.Main.Common; using TheresaBot.Main.Exceptions; +using TheresaBot.Main.Model.File; using TheresaBot.Main.Model.Pixiv; using TheresaBot.Main.Model.PixivRanking; @@ -117,19 +118,22 @@ public static async Task GetPixivRankingData(string mode, int return await GetPixivRankingAsync(postUrl, operation, headerDic, BotConfig.PixivConfig.ErrRetryTimes); } - public static async Task DownPixivImgAsync(string pixivId, string downloadUrl, string fullFileName = null) + public static async Task DownPixivImgAsync(string pixivIdStr, string downloadUrl, string fullFileName = null) { - string referer = HttpUrl.getPixivArtworksReferer(pixivId); + int pixivId = Convert.ToInt32(pixivIdStr); + string referer = HttpUrl.getPixivArtworksReferer(pixivIdStr); Dictionary headerDic = GetPixivHeader(referer); - return await DownPixivImgAsync(downloadUrl, headerDic, fullFileName, BotConfig.PixivConfig.ImgRetryTimes); + return await DownPixivImgAsync(downloadUrl, pixivId, headerDic, fullFileName, BotConfig.PixivConfig.ImgRetryTimes); } - public static async Task DownPixivImgBySizeAsync(string pixivId, string originUrl, string fullFileName = null) + public static async Task DownPixivImgBySizeAsync(string pixivIdStr, string originUrl) { + int pixivId = Convert.ToInt32(pixivIdStr); string downloadUrl = GetImgUrlBySize(originUrl); - string referer = HttpUrl.getPixivArtworksReferer(pixivId); + string fullFileName = GetImgNameBySize(originUrl); + string referer = HttpUrl.getPixivArtworksReferer(pixivIdStr); Dictionary headerDic = GetPixivHeader(referer); - return await DownPixivImgAsync(downloadUrl, headerDic, fullFileName, BotConfig.PixivConfig.ImgRetryTimes); + return await DownPixivImgAsync(downloadUrl, pixivId, headerDic, fullFileName, BotConfig.PixivConfig.ImgRetryTimes); } public static async Task DownPixivFileAsync(string pixivId, string downloadUrl, string fullFileName = null) @@ -223,7 +227,7 @@ private static async Task GetPixivJsonAsync(string url, Dictionary DownPixivImgAsync(string url, Dictionary headerDic = null, string fullFileName = null, int retryTimes = 0, int timeout = 60000) + private static async Task DownPixivImgAsync(string url, int pixivId, Dictionary headerDic = null, string fullFileName = null, int retryTimes = 0, int timeout = 60000) { if (retryTimes < 0) retryTimes = 0; while (retryTimes >= 0) @@ -231,7 +235,7 @@ private static async Task DownPixivImgAsync(string url, Dictionary DownPixivFileAsync(string url, Dictionary DownPixivFileAsync(string url, string fullIm { if (BotConfig.PixivConfig.FreeProxy) { - return await HttpHelper.DownFileAsync(url.ToProxyUrl(), fullImgSavePath); + return await HttpHelper.DownFileAsync(url.ToProxyUrl(), fullImgSavePath); } else if (string.IsNullOrWhiteSpace(BotConfig.PixivConfig.ImgProxy) == false) { @@ -311,11 +315,6 @@ private static async Task DownPixivFileAsync(string url, string fullIm } } - - - - - private static Dictionary GetPixivHeader(string referer) { Dictionary headerDic = new Dictionary(); @@ -337,7 +336,7 @@ private static Dictionary GetPixivHeader(string referer) /// private static async Task GetAsync(string url, Dictionary headerDic = null, int timeout = 60000) { - HttpClient client = GetHttpClient(); + using HttpClient client = GetHttpClient(); client.BaseAddress = new Uri(url); client.addHeaders(headerDic); client.DefaultRequestHeaders.Add("User-Agent", HttpHelper.GetRandomUserAgent()); @@ -355,10 +354,7 @@ private static async Task GetAsync(string url, Dictionary + /// 获取保存预览图的文件名 + /// + /// + /// + /// + public static string GetPreviewImgSaveName(this string downUrl, string pixivId) + { + HttpFileInfo httpFileInfo = new HttpFileInfo(downUrl); + return $"{pixivId}_p0_preview.{httpFileInfo.FileExtension}"; + } + /// /// 根据配置文件设置的图片大小获取图片下载地址 /// @@ -465,6 +473,22 @@ private static string GetImgUrlBySize(string originalUrl) return originalUrl.ToThumbUrl(); } + /// + /// 根据配置文件设置的图片大小获取图片下载地址 + /// + /// + private static string GetImgNameBySize(string originalUrl) + { + string imgSize = BotConfig.PixivConfig.ImgSize?.ToLower(); + HttpFileInfo httpFileInfo = new HttpFileInfo(originalUrl); + if (imgSize == "original") return httpFileInfo.FullFileName; + if (imgSize == "regular") return $"{httpFileInfo.FileName}_regular.{httpFileInfo.FileExtension}"; + if (imgSize == "small") return $"{httpFileInfo.FileName}_small.{httpFileInfo.FileExtension}"; + if (imgSize == "thumb") return $"{httpFileInfo.FileName}_thumb.{httpFileInfo.FileExtension}"; + return $"{httpFileInfo.FileName}_thumb.{httpFileInfo.FileExtension}"; + } + + /// /// 拆解originalUrl,返回host和文件目录等信息 /// diff --git a/Theresa3rd-Bot/TheresaBot.Main/Helper/PixivRankingDrawHelper.cs b/Theresa3rd-Bot/TheresaBot.Main/Helper/PixivRankingDrawHelper.cs index 4e3c2b27..e1e9d351 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Helper/PixivRankingDrawHelper.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Helper/PixivRankingDrawHelper.cs @@ -1,6 +1,7 @@ using SkiaSharp; using TheresaBot.Main.Common; using TheresaBot.Main.Model.Cache; +using TheresaBot.Main.Model.Pixiv; using TheresaBot.Main.Model.PixivRanking; namespace TheresaBot.Main.Helper @@ -172,7 +173,8 @@ private static async Task GetDrawImg(PixivRankingDetail detail) { string imgSavePath = detail.ImageSavePath; if (File.Exists(imgSavePath)) return new FileInfo(imgSavePath); - return await PixivHelper.DownPixivImgAsync(detail.WorkInfo.PixivId, detail.RankingContent.url, imgSavePath); + string fullFileName = detail.RankingContent.url.GetPreviewImgSaveName(detail.WorkInfo.illustId); + return await PixivHelper.DownPixivImgAsync(detail.WorkInfo.PixivId, detail.RankingContent.url, fullFileName); } catch (Exception ex) { diff --git a/Theresa3rd-Bot/TheresaBot.Main/Helper/StringHelper.cs b/Theresa3rd-Bot/TheresaBot.Main/Helper/StringHelper.cs index 1f4ed054..aee35ec7 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Helper/StringHelper.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Helper/StringHelper.cs @@ -135,6 +135,36 @@ public static string[] splitHttpUrl(this string value) return urlStr.Split('/', StringSplitOptions.RemoveEmptyEntries); } + /// + /// 格式化url + /// + /// + /// + public static string formatHttpUrl(this string httpUrl, bool defaultHttps = true) + { + if (string.IsNullOrWhiteSpace(httpUrl)) return string.Empty; + httpUrl = httpUrl.Trim(); + string lowerUrl = httpUrl.ToLower(); + if (lowerUrl.StartsWith("//")) + { + string header = defaultHttps ? "https:" : "http:"; + httpUrl = header + httpUrl; + lowerUrl = header + lowerUrl; + } + else if (!lowerUrl.StartsWith("http")) + { + string header = defaultHttps ? "https://" : "http://"; + httpUrl = header + httpUrl; + lowerUrl = header + lowerUrl; + } + while (lowerUrl.EndsWith("/")) + { + httpUrl = httpUrl.Substring(0, httpUrl.Length - 1); + lowerUrl = lowerUrl.Substring(0, lowerUrl.Length - 1); + } + return httpUrl; + } + /// /// 从一个http url中提取文件名 /// @@ -171,52 +201,6 @@ public static string joinCookie(this Dictionary cookieDic) return cookieBuilder.ToString(); } - - public static string isContainsWord(this string str, List containWords) - { - foreach (string word in containWords) - { - if (str.Contains(word)) return word; - } - return null; - } - - public static string isContainsWord(this string str, string[] containWords) - { - foreach (string word in containWords) - { - if (str.Contains(word)) return word; - } - return null; - } - - public static string[] isContainsWord(this string str, string[][] containWords) - { - foreach (string[] words in containWords) - { - foreach (string word in words) - { - if (str.Contains(word)) return words; - } - } - return null; - } - - public static string removePunctuation(this string str) - { - string[] punctuation = new string[] { " ", ":", ":", "·", ",", ".", "•", ",", "。", "(", ")", "(", ")", "-", "—", "☆", "Δ" }; - foreach (string item in punctuation) str = str.Replace(item, ""); - return str; - } - - public static string getHttpUrlWithoutParam(this string url) - { - if (string.IsNullOrEmpty(url)) return url; - int questionMarkIndex = url.IndexOf("?"); - if (questionMarkIndex < 0) return url; - return url.Substring(0, questionMarkIndex); - } - public static string getSuffixByUrl(this string url) { int lastPointIndex = url.LastIndexOf("."); diff --git a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/BasePluginConfig.cs b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/BasePluginConfig.cs index 8e887448..4513cbb9 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/BasePluginConfig.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/BasePluginConfig.cs @@ -2,6 +2,6 @@ { public class BasePluginConfig { - public bool Enable { get; set; } + public bool Enable { get; protected set; } } } diff --git a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/BaseSubscribeConfig.cs b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/BaseSubscribeConfig.cs index 3cd4ab1e..71ccd31e 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/BaseSubscribeConfig.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/BaseSubscribeConfig.cs @@ -2,12 +2,12 @@ { public class BaseSubscribeConfig : BasePluginConfig { - public List AddCommands { get; set; } + public List AddCommands { get; protected set; } - public List RmCommands { get; set; } + public List RmCommands { get; protected set; } - public string Template { get; set; } + public string Template { get; protected set; } - public int ScanInterval { get; set; } + public int ScanInterval { get; protected set; } } } diff --git a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/BotConfigDto.cs b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/BotConfigDto.cs index 4460d87c..5277c068 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/BotConfigDto.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/BotConfigDto.cs @@ -1,20 +1,22 @@ -namespace TheresaBot.Main.Model.Config +using TheresaBot.Main.Helper; + +namespace TheresaBot.Main.Model.Config { public class BotConfigDto { - public GeneralConfig General { get; set; } - public PixivConfig Pixiv { get; set; } - public PermissionsConfig Permissions { get; set; } - public ManageConfig Manage { get; set; } - public MenuConfig Menu { get; set; } - public RepeaterConfig Repeater { get; set; } - public WelcomeConfig Welcome { get; set; } - public ReminderConfig Reminder { get; set; } - public SetuConfig Setu { get; set; } - public SaucenaoConfig Saucenao { get; set; } - public SubscribeConfig Subscribe { get; set; } - public TimingSetuConfig TimingSetu { get; set; } - public PixivRankingConfig PixivRanking { get; set; } + public GeneralConfig General { get; private set; } + public PixivConfig Pixiv { get; private set; } + public PermissionsConfig Permissions { get; private set; } + public ManageConfig Manage { get; private set; } + public MenuConfig Menu { get; private set; } + public RepeaterConfig Repeater { get; private set; } + public WelcomeConfig Welcome { get; private set; } + public ReminderConfig Reminder { get; private set; } + public SetuConfig Setu { get; private set; } + public SaucenaoConfig Saucenao { get; private set; } + public SubscribeConfig Subscribe { get; private set; } + public TimingSetuConfig TimingSetu { get; private set; } + public PixivRankingConfig PixivRanking { get; private set; } } } diff --git a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/DBConfig.cs b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/DBConfig.cs deleted file mode 100644 index 98aa977a..00000000 --- a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/DBConfig.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace TheresaBot.Main.Model.Config -{ - public class DBConfig - { - public string ConnectionString { get; set; } - } -} diff --git a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/GeneralConfig.cs b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/GeneralConfig.cs index 1a2127d7..f55631ef 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/GeneralConfig.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/GeneralConfig.cs @@ -2,24 +2,26 @@ { public class GeneralConfig { - public string Prefix { get; set; } + public string Prefix { get; private set; } - public string DownloadPath { get; set; } + public string DownloadPath { get; private set; } - public List ErrorGroups { get; set; } + public List ErrorGroups { get; private set; } - public string ErrorMsg { get; set; } + public string ErrorMsg { get; private set; } - public string DownErrorImgPath { get; set; } + public string DownPathCleanCron { get; set; } - public string DisableMsg { get; set; } + public string DownErrorImgPath { get; private set; } - public string NoPermissionsMsg { get; set; } + public string DisableMsg { get; private set; } - public string ManagersRequiredMsg { get; set; } + public string NoPermissionsMsg { get; private set; } - public string SetuCustomDisableMsg { get; set; } + public string ManagersRequiredMsg { get; private set; } - public bool SendRelevantCommands { get; set; } + public string SetuCustomDisableMsg { get; private set; } + + public bool SendRelevantCommands { get; private set; } } } diff --git a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/LocalSetuConfig.cs b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/LocalSetuConfig.cs index 03de815e..72d14bd0 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/LocalSetuConfig.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/LocalSetuConfig.cs @@ -2,11 +2,11 @@ { public class LocalSetuConfig : BasePluginConfig { - public List Commands { get; set; } + public List Commands { get; private set; } - public string LocalPath { get; set; } + public string LocalPath { get; private set; } - public string Template { get; set; } + public string Template { get; private set; } } } diff --git a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/LoliconConfig.cs b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/LoliconConfig.cs index 50954dcb..8ef183f0 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/LoliconConfig.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/LoliconConfig.cs @@ -2,9 +2,9 @@ { public class LoliconConfig : BasePluginConfig { - public List Commands { get; set; } + public List Commands { get; private set; } - public string Template { get; set; } + public string Template { get; private set; } } } diff --git a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/LolisukiConfig.cs b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/LolisukiConfig.cs index 45bf7368..5dbc87f2 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/LolisukiConfig.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/LolisukiConfig.cs @@ -2,11 +2,11 @@ { public class LolisukiConfig : BasePluginConfig { - public List Commands { get; set; } + public List Commands { get; private set; } - public string Level { get; set; } + public string Level { get; private set; } - public string Template { get; set; } + public string Template { get; private set; } } } diff --git a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/ManageConfig.cs b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/ManageConfig.cs index 07cc4f8f..bbcb12fa 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/ManageConfig.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/ManageConfig.cs @@ -2,17 +2,17 @@ { public class ManageConfig { - public List PixivCookieCommands { get; set; } + public List PixivCookieCommands { get; private set; } - public List SaucenaoCookieCommands { get; set; } + public List SaucenaoCookieCommands { get; private set; } - public List DisableTagCommands { get; set; } + public List DisableTagCommands { get; private set; } - public List EnableTagCommands { get; set; } + public List EnableTagCommands { get; private set; } - public List DisableMemberCommands { get; set; } + public List DisableMemberCommands { get; private set; } - public List EnableMemberCommands { get; set; } + public List EnableMemberCommands { get; private set; } } } diff --git a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/MenuConfig.cs b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/MenuConfig.cs index 20705be1..760e3ede 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/MenuConfig.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/MenuConfig.cs @@ -2,9 +2,9 @@ { public class MenuConfig : BasePluginConfig { - public List Commands { get; set; } + public List Commands { get; private set; } - public string Template { get; set; } + public string Template { get; private set; } } } diff --git a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/MiraiConfig.cs b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/MiraiConfig.cs deleted file mode 100644 index a78b06ec..00000000 --- a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/MiraiConfig.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace TheresaBot.Main.Model.Config -{ - public class MiraiConfig - { - public string Host { get; set; } - - public int Port { get; set; } - - public string AuthKey { get; set; } - - public long BotQQ { get; set; } - } -} diff --git a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/MysUserSubscribeConfig.cs b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/MysUserSubscribeConfig.cs index 3f058a86..b115148d 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/MysUserSubscribeConfig.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/MysUserSubscribeConfig.cs @@ -2,7 +2,7 @@ { public class MysUserSubscribeConfig : BaseSubscribeConfig { - public int ShelfLife { get; set; } + public int ShelfLife { get; private set; } public MysUserSubscribeConfig() { diff --git a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/PermissionsConfig.cs b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/PermissionsConfig.cs index 9382285f..93772194 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/PermissionsConfig.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/PermissionsConfig.cs @@ -2,33 +2,33 @@ { public class PermissionsConfig { - public List AcceptGroups { get; set; } + public List AcceptGroups { get; private set; } - public List SuperManagers { get; set; } + public List SuperManagers { get; private set; } - public List LimitlessMembers { get; set; } + public List LimitlessMembers { get; private set; } - public List SetuGroups { get; set; } + public List SetuGroups { get; private set; } - public List SetuShowImgGroups { get; set; } + public List SetuShowImgGroups { get; private set; } - public List SetuShowAIGroups { get; set; } + public List SetuShowAIGroups { get; private set; } - public List SetuShowR18Groups { get; set; } + public List SetuShowR18Groups { get; private set; } - public List SetuCustomGroups { get; set; } + public List SetuCustomGroups { get; private set; } - public List SetuNoneCDGroups { get; set; } + public List SetuNoneCDGroups { get; private set; } - public List SetuLimitlessGroups { get; set; } + public List SetuLimitlessGroups { get; private set; } - public List SaucenaoGroups { get; set; } + public List SaucenaoGroups { get; private set; } - public List SaucenaoR18Groups { get; set; } + public List SaucenaoR18Groups { get; private set; } - public List SubscribeGroups { get; set; } + public List SubscribeGroups { get; private set; } - public List PixivRankingGroups { get; set; } + public List PixivRankingGroups { get; private set; } } } diff --git a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/PixivConfig.cs b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/PixivConfig.cs index 5f603d0d..9858c40c 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/PixivConfig.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/PixivConfig.cs @@ -1,26 +1,37 @@ -namespace TheresaBot.Main.Model.Config +using TheresaBot.Main.Helper; + +namespace TheresaBot.Main.Model.Config { public class PixivConfig { - public bool FreeProxy { get; set; } - public string HttpProxy { get; set; } - public string ImgProxy { get; set; } - public int ImgShowMaximum { get; set; } - public int TagShowMaximum { get; set; } - public int UrlShowMaximum { get; set; } - public string ImgSize { get; set; } - public string OriginUrlProxy { get; set; } - public bool SendImgBehind { get; set; } - public int ImgRetryTimes { get; set; } - public int ErrRetryTimes { get; set; } - public int CookieExpire { get; set; } - public string CookieExpireMsg { get; set; } - public string Template { get; set; } + public bool FreeProxy { get; private set; } + public string HttpProxy { get; private set; } + public string ImgProxy { get; private set; } + public int ImgShowMaximum { get; private set; } + public int TagShowMaximum { get; private set; } + public int UrlShowMaximum { get; private set; } + public string ImgSize { get; private set; } + public string OriginUrlProxy { get; private set; } + public bool SendImgBehind { get; private set; } + public int ImgRetryTimes { get; private set; } + public int ErrRetryTimes { get; private set; } + public int CookieExpire { get; private set; } + public string CookieExpireMsg { get; private set; } + public string Template { get; private set; } public PixivConfig() { this.ImgShowMaximum = 1; this.TagShowMaximum = 3; this.UrlShowMaximum = 3; } + + public PixivConfig FormatConfig() + { + this.ImgProxy = StringHelper.formatHttpUrl(ImgProxy); + this.HttpProxy = StringHelper.formatHttpUrl(HttpProxy, false); + this.OriginUrlProxy = StringHelper.formatHttpUrl(OriginUrlProxy); + return this; + } + } } diff --git a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/PixivRankingConfig.cs b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/PixivRankingConfig.cs index 1588dca5..63e45faf 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/PixivRankingConfig.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/PixivRankingConfig.cs @@ -4,40 +4,40 @@ namespace TheresaBot.Main.Model.Config { public class PixivRankingConfig : BasePluginConfig { - public string ProcessingMsg { get; set; } - public string Template { get; set; } - public int MaxScan { get; set; } - public int PreviewInPage { get; set; } - public PixivRankingSortType SortType { get; set; } - public int GroupCD { get; set; } - public int CacheSeconds { get; set; } - public int SendDetail { get; set; } - public PixivRankingItem Daily { get; set; } - public PixivRankingItem DailyAI { get; set; } - public PixivRankingItem Male { get; set; } - public PixivRankingItem Weekly { get; set; } - public PixivRankingItem Monthly { get; set; } - public List Subscribes { get; set; } + public string ProcessingMsg { get; private set; } + public string Template { get; private set; } + public int MaxScan { get; private set; } + public int PreviewInPage { get; private set; } + public PixivRankingSortType SortType { get; private set; } + public int GroupCD { get; private set; } + public int CacheSeconds { get; private set; } + public int SendDetail { get; private set; } + public PixivRankingItem Daily { get; private set; } + public PixivRankingItem DailyAI { get; private set; } + public PixivRankingItem Male { get; private set; } + public PixivRankingItem Weekly { get; private set; } + public PixivRankingItem Monthly { get; private set; } + public List Subscribes { get; private set; } } public class PixivRankingItem { - public bool Enable { get; set; } - public List Commands { get; set; } - public int MinRatingCount { get; set; } - public double MinRatingRate { get; set; } - public int MinBookCount { get; set; } - public double MinBookRate { get; set; } + public bool Enable { get; private set; } + public List Commands { get; private set; } + public int MinRatingCount { get; private set; } + public double MinRatingRate { get; private set; } + public int MinBookCount { get; private set; } + public double MinBookRate { get; private set; } } public class PixivRankingTimer { - public bool Enable { get; set; } - public string Name { get; set; } - public List Groups { get; set; } - public List Contents { get; set; } - public string Cron { get; set; } - public int SendDetail { get; set; } + public bool Enable { get; private set; } + public string Name { get; private set; } + public List Groups { get; private set; } + public List Contents { get; private set; } + public string Cron { get; private set; } + public int SendDetail { get; private set; } } } diff --git a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/PixivTagSubscribeConfig.cs b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/PixivTagSubscribeConfig.cs index b3bc648e..f0d1010f 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/PixivTagSubscribeConfig.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/PixivTagSubscribeConfig.cs @@ -2,13 +2,13 @@ { public class PixivTagSubscribeConfig : BaseSubscribeConfig { - public int ShelfLife { get; set; } + public int ShelfLife { get; private set; } - public int MinBookmark { get; set; } + public int MinBookmark { get; private set; } - public int MinBookPerHour { get; set; } + public int MinBookPerHour { get; private set; } - public int MaxScan { get; set; } + public int MaxScan { get; private set; } public PixivTagSubscribeConfig() { diff --git a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/PixivUserSubscribeConfig.cs b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/PixivUserSubscribeConfig.cs index 6c2b9329..08181cbc 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/PixivUserSubscribeConfig.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/PixivUserSubscribeConfig.cs @@ -4,11 +4,11 @@ namespace TheresaBot.Main.Model.Config { public class PixivUserSubscribeConfig : BaseSubscribeConfig { - public PixivScanType ScanMode { get; set; } + public PixivScanType ScanMode { get; private set; } - public List SyncCommands { get; set; } + public List SyncCommands { get; private set; } - public int ShelfLife { get; set; } + public int ShelfLife { get; private set; } public PixivUserSubscribeConfig() { diff --git a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/ReminderConfig.cs b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/ReminderConfig.cs index 063fc761..6c4d77b4 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/ReminderConfig.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/ReminderConfig.cs @@ -2,24 +2,24 @@ { public class ReminderConfig : BasePluginConfig { - public List Timers { get; set; } + public List Timers { get; private set; } } public class ReminderTimer { - public bool Enable { get; set; } + public bool Enable { get; private set; } - public string Name { get; set; } + public string Name { get; private set; } - public string Cron { get; set; } + public string Cron { get; private set; } - public List Groups { get; set; } + public List Groups { get; private set; } - public bool AtAll { get; set; } + public bool AtAll { get; private set; } - public List AtMembers { get; set; } + public List AtMembers { get; private set; } - public string Template { get; set; } + public string Template { get; private set; } } diff --git a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/RepeaterConfig.cs b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/RepeaterConfig.cs index 5de4d32a..20bd7315 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/RepeaterConfig.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/RepeaterConfig.cs @@ -2,9 +2,9 @@ { public class RepeaterConfig : BasePluginConfig { - public int RepeatTime { get; set; } + public int RepeatTime { get; private set; } - public int RepeatMode { get; set; } + public int RepeatMode { get; private set; } public RepeaterConfig() { this.RepeatTime = 3; diff --git a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/SaucenaoConfig.cs b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/SaucenaoConfig.cs index d744cbfd..5a243a2d 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/SaucenaoConfig.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/SaucenaoConfig.cs @@ -4,19 +4,19 @@ namespace TheresaBot.Main.Model.Config { public class SaucenaoConfig : BasePluginConfig { - public List Commands { get; set; } - public string NotFoundMsg { get; set; } - public string ProcessingMsg { get; set; } - public string Template { get; set; } - public int MemberCD { get; set; } - public int MaxDaily { get; set; } - public int MaxReceive { get; set; } - public decimal MinSimilarity { get; set; } - public bool PullOrigin { get; set; } - public bool SendPrivate { get; set; } - public int RevokeInterval { get; set; } - public bool RevokeSearched { get; set; } - public YNAType ContinueAscii2d { get; set; } - public int Ascii2dReadCount { get; set; } + public List Commands { get; private set; } + public string NotFoundMsg { get; private set; } + public string ProcessingMsg { get; private set; } + public string Template { get; private set; } + public int MemberCD { get; private set; } + public int MaxDaily { get; private set; } + public int MaxReceive { get; private set; } + public decimal MinSimilarity { get; private set; } + public bool PullOrigin { get; private set; } + public bool SendPrivate { get; private set; } + public int RevokeInterval { get; private set; } + public bool RevokeSearched { get; private set; } + public YNAType ContinueAscii2d { get; private set; } + public int Ascii2dReadCount { get; private set; } } } diff --git a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/SetuConfig.cs b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/SetuConfig.cs index 08878fe4..c9238edf 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/SetuConfig.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/SetuConfig.cs @@ -2,29 +2,29 @@ { public class SetuConfig { - public int GroupCD { get; set; } + public int GroupCD { get; private set; } - public int MemberCD { get; set; } + public int MemberCD { get; private set; } - public string DisableTagsMsg { get; set; } + public string DisableTagsMsg { get; private set; } - public string NotFoundMsg { get; set; } + public string NotFoundMsg { get; private set; } - public string ProcessingMsg { get; set; } + public string ProcessingMsg { get; private set; } - public long MaxDaily { get; set; } + public long MaxDaily { get; private set; } - public int RevokeInterval { get; set; } + public int RevokeInterval { get; private set; } - public bool SendPrivate { get; set; } + public bool SendPrivate { get; private set; } - public SetuPixivConfig Pixiv { get; set; } + public SetuPixivConfig Pixiv { get; private set; } - public LoliconConfig Lolicon { get; set; } + public LoliconConfig Lolicon { get; private set; } - public LolisukiConfig Lolisuki { get; set; } + public LolisukiConfig Lolisuki { get; private set; } - public LocalSetuConfig Local { get; set; } + public LocalSetuConfig Local { get; private set; } } diff --git a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/SetuPixivConfig.cs b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/SetuPixivConfig.cs index c92c7db9..d9a7dccb 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/SetuPixivConfig.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/SetuPixivConfig.cs @@ -4,13 +4,13 @@ namespace TheresaBot.Main.Model.Config { public class SetuPixivConfig : BasePluginConfig { - public List Commands { get; set; } - public PixivRandomType RandomMode { get; set; } - public List RandomTags { get; set; } - public string Template { get; set; } - public int MaxScreen { get; set; } - public double MinBookmark { get; set; } - public double MinBookRate { get; set; } + public List Commands { get; private set; } + public PixivRandomType RandomMode { get; private set; } + public List RandomTags { get; private set; } + public string Template { get; private set; } + public int MaxScreen { get; private set; } + public double MinBookmark { get; private set; } + public double MinBookRate { get; private set; } public SetuPixivConfig() { diff --git a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/SubscribeConfig.cs b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/SubscribeConfig.cs index 93ad9ede..7af733e0 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/SubscribeConfig.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/SubscribeConfig.cs @@ -2,11 +2,11 @@ { public class SubscribeConfig { - public PixivUserSubscribeConfig PixivUser { get; set; } + public PixivUserSubscribeConfig PixivUser { get; private set; } - public PixivTagSubscribeConfig PixivTag { get; set; } + public PixivTagSubscribeConfig PixivTag { get; private set; } - public MysUserSubscribeConfig Miyoushe { get; set; } + public MysUserSubscribeConfig Miyoushe { get; private set; } } } diff --git a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/TimingSetuConfig.cs b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/TimingSetuConfig.cs index d243b3b0..36ee3748 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/TimingSetuConfig.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/TimingSetuConfig.cs @@ -4,24 +4,24 @@ namespace TheresaBot.Main.Model.Config { public class TimingSetuConfig : BasePluginConfig { - public string LocalPath { get; set; } - public bool FromOneDir { get; set; } - public string LolisukiLevel { get; set; } - public List Timers { get; set; } + public string LocalPath { get; private set; } + public bool FromOneDir { get; private set; } + public string LolisukiLevel { get; private set; } + public List Timers { get; private set; } } public class TimingSetuTimer { - public bool Enable { get; set; } - public string Cron { get; set; } - public string Name { get; set; } - public List Groups { get; set; } - public TimingSetuSourceType Source { get; set; } - public bool SendMerge { get; set; } - public List Tags { get; set; } - public int Quantity { get; set; } - public bool AtAll { get; set; } - public string TimingMsg { get; set; } + public bool Enable { get; private set; } + public string Cron { get; private set; } + public string Name { get; private set; } + public List Groups { get; private set; } + public TimingSetuSourceType Source { get; private set; } + public bool SendMerge { get; private set; } + public List Tags { get; private set; } + public int Quantity { get; private set; } + public bool AtAll { get; private set; } + public string TimingMsg { get; private set; } } diff --git a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/WebsiteConfig.cs b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/WebsiteConfig.cs index 84566b5c..1c167c6c 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/WebsiteConfig.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/WebsiteConfig.cs @@ -9,6 +9,5 @@ public class WebsiteConfig public WebsitePO Bili { get; set; } public WebsitePO Saucenao { get; set; } - } } diff --git a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/WelcomeConfig.cs b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/WelcomeConfig.cs index 7292c5de..f07e0479 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Model/Config/WelcomeConfig.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Model/Config/WelcomeConfig.cs @@ -2,16 +2,16 @@ { public class WelcomeConfig : BasePluginConfig { - public string Template { get; set; } + public string Template { get; private set; } - public List Special { get; set; } + public List Special { get; private set; } } public class WelcomeSpecial { - public long GroupId { get; set; } + public long GroupId { get; private set; } - public string Template { get; set; } + public string Template { get; private set; } } diff --git a/Theresa3rd-Bot/TheresaBot.Main/Model/File/HttpFileInfo.cs b/Theresa3rd-Bot/TheresaBot.Main/Model/File/HttpFileInfo.cs new file mode 100644 index 00000000..f0b4a877 --- /dev/null +++ b/Theresa3rd-Bot/TheresaBot.Main/Model/File/HttpFileInfo.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TheresaBot.Main.Helper; + +namespace TheresaBot.Main.Model.File +{ + public class HttpFileInfo + { + public string FullFileName { get; set; } + public string FileName { get; set; } + public string FileExtension { get; set; } + + public HttpFileInfo(string httpUrl) + { + var splitStr = httpUrl.Split('?')[0].Trim(); + var splitArr = splitStr.Split('/'); + FullFileName = splitArr.Last().Trim(); + int pointIndex = FullFileName.IndexOf('.'); + FileName = FullFileName.Substring(0, pointIndex); + FileExtension = String.Empty; + if (pointIndex < FullFileName.Length - 1) + { + FileExtension = FullFileName.Substring(pointIndex + 1, FullFileName.Length - pointIndex - 1); + } + } + + } +} diff --git a/Theresa3rd-Bot/TheresaBot.Main/Session/BaseSession.cs b/Theresa3rd-Bot/TheresaBot.Main/Session/BaseSession.cs index dc900be1..b133a17f 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Session/BaseSession.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Session/BaseSession.cs @@ -22,6 +22,8 @@ public abstract class BaseSession public abstract Task SendGroupSetuAsync(List setuContents, long groupId, bool sendMerge); + public abstract Task SendGroupSetuAsync(List setuContents, long groupId, bool sendMerge, int margeEachPage = 0); + public abstract Task SendGroupMergeSetuAsync(List setuContents, List headerContents, long groupId, int eachPage); public abstract Task SendGroupSetuAsync(List workMsgs, List setuFiles, long groupId); diff --git a/Theresa3rd-Bot/TheresaBot.Main/TheresaBot.Main.csproj b/Theresa3rd-Bot/TheresaBot.Main/TheresaBot.Main.csproj index 3a40b969..a98b2d96 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/TheresaBot.Main.csproj +++ b/Theresa3rd-Bot/TheresaBot.Main/TheresaBot.Main.csproj @@ -17,6 +17,7 @@ + @@ -24,8 +25,6 @@ - - diff --git a/Theresa3rd-Bot/TheresaBot.Main/Timers/TimerManager.cs b/Theresa3rd-Bot/TheresaBot.Main/Timers/TimerManager.cs index 7c6182c1..338b7667 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/Timers/TimerManager.cs +++ b/Theresa3rd-Bot/TheresaBot.Main/Timers/TimerManager.cs @@ -100,7 +100,8 @@ public static async void initClearJobAsync(BaseSession session, BaseReporter rep { try { - string clearCron = "0 0 4 * * ?"; + string clearCron = BotConfig.GeneralConfig.DownPathCleanCron; + if (string.IsNullOrWhiteSpace(clearCron)) return; ICronTrigger trigger = (ICronTrigger)TriggerBuilder.Create().WithCronSchedule(clearCron).Build(); IJobDetail jobDetail = JobBuilder.Create().WithIdentity("ClearJob", "ClearJob").Build();//创建作业 IScheduler scheduler = await StdSchedulerFactory.GetDefaultScheduler(); diff --git a/Theresa3rd-Bot/TheresaBot.Main/botsettings.yml b/Theresa3rd-Bot/TheresaBot.Main/botsettings.yml index 675891b3..ce644c2e 100644 --- a/Theresa3rd-Bot/TheresaBot.Main/botsettings.yml +++ b/Theresa3rd-Bot/TheresaBot.Main/botsettings.yml @@ -1,6 +1,7 @@ General: #基础设置 Prefix: '#' #指令前缀 DownloadPath: 'C:\BotImg\download' #下载文件的存放目录 + DownPathCleanCron: '0 0 4 * * ?' #下载目录清理定时器,Cron表达式,空值表示不清理,格式:0 0 4 * * ? DownErrorImgPath: 'C:\BotImg\face\downError.png' #图片下载失败时的替代图片 ErrorGroups: [284196392] #错误日志群,发生错误时会将日志发送到这些群 ErrorMsg: | #处理异常时返回的消息 @@ -119,7 +120,7 @@ Setu: 标签:{Tags},点击下方链接可以查看原图 {Urls} - Lolisuki: #Lolisuki图床 https://lolisuki.cc + Lolisuki: #Lolisuki图床 https://lolisuki.cn Enable: true #是否启用 Commands: ['setu'] #命令 Level: '0-6' #Level范围,数字越大表示越涩,最小为0,最大为6,5-6为R18 diff --git a/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/Common/MiraiConfig.cs b/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/Common/MiraiConfig.cs new file mode 100644 index 00000000..c84b9f52 --- /dev/null +++ b/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/Common/MiraiConfig.cs @@ -0,0 +1,21 @@ +using TheresaBot.Main.Model.Config; + +namespace TheresaBot.MiraiHttpApi.Common +{ + public class MiraiConfig + { + public static string ConnectionString = string.Empty; + + public static string MiraiHost = string.Empty; + + public static int MiraiPort = 0; + + public static string MiraiAuthKey = string.Empty; + + public static long MiraiBotQQ = 0; + + public static string MiraiBotName = "Bot"; + + + } +} diff --git a/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/Event/DisconnectedEvent.cs b/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/Event/DisconnectedEvent.cs index 30d17743..188985b1 100644 --- a/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/Event/DisconnectedEvent.cs +++ b/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/Event/DisconnectedEvent.cs @@ -3,8 +3,8 @@ using Mirai.CSharp.HttpApi.Session; using System; using System.Threading.Tasks; -using TheresaBot.Main.Common; using TheresaBot.Main.Helper; +using TheresaBot.MiraiHttpApi.Common; namespace TheresaBot.MiraiHttpApi.Event { @@ -18,7 +18,7 @@ public async Task HandleMessageAsync(IMiraiHttpSession session, IDisconnectedEve { try { - await session.ConnectAsync(BotConfig.MiraiConfig.BotQQ); + await session.ConnectAsync(MiraiConfig.MiraiBotQQ); e.BlockRemainingHandlers = true; LogHelper.Info("已重新连接到mcl..."); break; diff --git a/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/Event/FriendMessageEvent.cs b/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/Event/FriendMessageEvent.cs index da40f451..c80a382e 100644 --- a/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/Event/FriendMessageEvent.cs +++ b/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/Event/FriendMessageEvent.cs @@ -13,6 +13,7 @@ using TheresaBot.Main.Model.Content; using TheresaBot.Main.Type; using TheresaBot.MiraiHttpApi.Command; +using TheresaBot.MiraiHttpApi.Common; using TheresaBot.MiraiHttpApi.Helper; using TheresaBot.MiraiHttpApi.Reporter; using TheresaBot.MiraiHttpApi.Session; @@ -27,7 +28,7 @@ public async Task HandleMessageAsync(IMiraiHttpSession session, IFriendMessageEv try { long memberId = args.Sender.Id; - if (memberId == BotConfig.MiraiConfig.BotQQ) return; + if (memberId == MiraiConfig.MiraiBotQQ) return; string prefix = BotConfig.GeneralConfig.Prefix; List chainList = args.Chain.Select(m => m.ToString()).ToList(); List plainList = args.Chain.Where(v => v is PlainMessage && v.ToString().Trim().Length > 0).Select(m => m.ToString().Trim()).ToList(); diff --git a/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/Event/GroupMemberJoinedEvent.cs b/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/Event/GroupMemberJoinedEvent.cs index c780f8aa..e434f1c5 100644 --- a/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/Event/GroupMemberJoinedEvent.cs +++ b/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/Event/GroupMemberJoinedEvent.cs @@ -11,6 +11,7 @@ using TheresaBot.Main.Helper; using TheresaBot.Main.Model.Config; using TheresaBot.Main.Type; +using TheresaBot.MiraiHttpApi.Common; using TheresaBot.MiraiHttpApi.Helper; namespace TheresaBot.MiraiHttpApi.Event @@ -23,7 +24,7 @@ public async Task HandleMessageAsync(IMiraiHttpSession session, IGroupMemberJoin long memberId = message.Member.Id; long groupId = message.Member.Group.Id; if (!BusinessHelper.IsHandleMessage(groupId)) return; - if (memberId == BotConfig.MiraiConfig.BotQQ) return; + if (memberId == MiraiConfig.MiraiBotQQ) return; WelcomeConfig welcomeConfig = BotConfig.WelcomeConfig; if (welcomeConfig is null || welcomeConfig.Enable == false) return; diff --git a/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/Event/GroupMessageEvent.cs b/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/Event/GroupMessageEvent.cs index cd9af75e..582218bd 100644 --- a/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/Event/GroupMessageEvent.cs +++ b/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/Event/GroupMessageEvent.cs @@ -14,6 +14,7 @@ using TheresaBot.Main.Model.Content; using TheresaBot.Main.Type; using TheresaBot.MiraiHttpApi.Command; +using TheresaBot.MiraiHttpApi.Common; using TheresaBot.MiraiHttpApi.Helper; using TheresaBot.MiraiHttpApi.Relay; using TheresaBot.MiraiHttpApi.Reporter; @@ -32,7 +33,7 @@ public async Task HandleMessageAsync(IMiraiHttpSession session, IGroupMessageEve long groupId = args.Sender.Group.Id; long botId = session.QQNumber ?? 0; if (!BusinessHelper.IsHandleMessage(groupId)) return; - if (memberId == BotConfig.MiraiConfig.BotQQ) return; + if (memberId == MiraiConfig.MiraiBotQQ) return; if (BusinessHelper.IsBanMember(memberId)) return; //黑名单成员 string prefix = BotConfig.GeneralConfig.Prefix; diff --git a/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/Helper/MiraiHelper.cs b/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/Helper/MiraiHelper.cs index ddef09d1..4b57d0ce 100644 --- a/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/Helper/MiraiHelper.cs +++ b/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/Helper/MiraiHelper.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; using Mirai.CSharp.Builders; using Mirai.CSharp.HttpApi.Builder; using Mirai.CSharp.HttpApi.Invoking; @@ -20,6 +21,7 @@ using TheresaBot.Main.Model.Invoker; using TheresaBot.Main.Type; using TheresaBot.MiraiHttpApi.Command; +using TheresaBot.MiraiHttpApi.Common; using TheresaBot.MiraiHttpApi.Event; namespace TheresaBot.MiraiHttpApi.Helper @@ -32,12 +34,6 @@ public static class MiraiHelper public static IMiraiHttpSession Session; - public static IBotProfile BotProfile; - - public static long BotNumber; - - public static string BotName; - public static async Task ConnectMirai() { try @@ -58,9 +54,9 @@ public static async Task ConnectMirai() .Services .Configure(options => { - options.Host = BotConfig.MiraiConfig.Host; - options.Port = BotConfig.MiraiConfig.Port; - options.AuthKey = BotConfig.MiraiConfig.AuthKey; + options.Host = MiraiConfig.MiraiHost; + options.Port = MiraiConfig.MiraiPort; + options.AuthKey = MiraiConfig.MiraiAuthKey; options.SuppressAwaitMessageInvoker = true; }) .AddLogging() @@ -68,11 +64,8 @@ public static async Task ConnectMirai() Scope = Services.CreateAsyncScope(); Services = Scope.ServiceProvider; Session = Services.GetRequiredService(); - await Session.ConnectAsync(BotConfig.MiraiConfig.BotQQ); + await Session.ConnectAsync(MiraiConfig.MiraiBotQQ); LogHelper.Info("已成功连接到mirai-console..."); - BotProfile = await GetBotProfileAsync(); - BotNumber = Session.QQNumber ?? 0; - BotName = BotProfile?.Nickname ?? "Bot"; } catch (Exception ex) { @@ -81,8 +74,39 @@ public static async Task ConnectMirai() } } + /// + /// 加载MiraiHttpApi配置 + /// + public static void LoadMiraiConfig(IConfiguration configuration) + { + MiraiConfig.ConnectionString = configuration["Database:ConnectionString"]; + MiraiConfig.MiraiHost = configuration["Mirai:host"]; + MiraiConfig.MiraiPort = Convert.ToInt32(configuration["Mirai:port"]); + MiraiConfig.MiraiAuthKey = configuration["Mirai:authKey"]; + MiraiConfig.MiraiBotQQ = Convert.ToInt64(configuration["Mirai:botQQ"]); + } + + /// + /// 获取机器人信息 + /// + /// + public static async Task LoadBotProfileAsync() + { + try + { + IBotProfile profile = await MiraiHelper.Session.GetBotProfileAsync(); + MiraiConfig.MiraiBotName = profile?.Nickname ?? "Bot"; + LogHelper.Info($"Bot名片获取完毕,QQNumber={Session.QQNumber},Nickname={profile?.Nickname ?? ""}"); + } + catch (Exception ex) + { + LogHelper.Error(ex, "Bot名片获取失败"); + } + } + public static async Task SendStartUpMessageAsync() { + await Task.Delay(3000); List msgList = new List(); StringBuilder msgBuilder=new StringBuilder(); msgBuilder.AppendLine($"欢迎使用【Theresa3rd-Bot {BotConfig.BotVersion}】"); @@ -95,11 +119,14 @@ public static async Task SendStartUpMessageAsync() try { await Session.SendFriendMessageAsync(memberId, welcomeMessage); - await Task.Delay(1000); } catch (Exception) { } + finally + { + await Task.Delay(1000); + } } } @@ -286,6 +313,7 @@ public static async Task> UploadPictureAsync(this List private static async Task UploadPictureAsync(LocalImageContent imageContent) { + if (imageContent?.FileInfo == null) return null; return imageContent.SendTarget switch { SendTarget.Group => (IImageMessage)await Session.UploadPictureAsync(UploadTarget.Group, imageContent.FileInfo.FullName), @@ -295,23 +323,5 @@ private static async Task UploadPictureAsync(LocalImageContent ima }; } - /// - /// 获取机器人信息 - /// - /// - private static async Task GetBotProfileAsync() - { - try - { - return await MiraiHelper.Session.GetBotProfileAsync(); - } - catch (Exception ex) - { - LogHelper.Error(ex, "获取Bot资料失败"); - return null; - } - } - - } } diff --git a/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/Session/MiraiSession.cs b/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/Session/MiraiSession.cs index c634ad01..07cf947f 100644 --- a/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/Session/MiraiSession.cs +++ b/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/Session/MiraiSession.cs @@ -1,17 +1,15 @@ using Mirai.CSharp.HttpApi.Models.ChatMessages; using Mirai.CSharp.Models; -using SqlSugar; using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Linq; -using System.Text.RegularExpressions; using System.Threading.Tasks; using TheresaBot.Main.Common; using TheresaBot.Main.Helper; using TheresaBot.Main.Model.Content; using TheresaBot.Main.Session; +using TheresaBot.MiraiHttpApi.Common; using TheresaBot.MiraiHttpApi.Helper; namespace TheresaBot.MiraiHttpApi.Session @@ -77,7 +75,7 @@ public override async Task SendGroupMergeMessageAsync(long groupId, params List nodeList = new(); foreach (var contentList in contentLists) { - nodeList.Add(new ForwardMessageNode(MiraiHelper.BotName, MiraiHelper.BotNumber, DateTime.Now, await contentList.ToMiraiMessageAsync())); + nodeList.Add(new ForwardMessageNode(MiraiConfig.MiraiBotName, MiraiConfig.MiraiBotQQ, DateTime.Now, await contentList.ToMiraiMessageAsync())); } return await MiraiHelper.Session.SendGroupMessageAsync(groupId, new ForwardMessage(nodeList.ToArray())); } @@ -90,11 +88,29 @@ public override async Task SendGroupMergeMessageAsync(long groupId, List msgList = new List(); msgList.AddRange(await content.SetuInfos.ToMiraiMessageAsync()); msgList.AddRange(await content.SetuImages.UploadPictureAsync(UploadTarget.Group)); - nodeList.Add(new ForwardMessageNode(MiraiHelper.BotName, MiraiHelper.BotNumber, DateTime.Now, msgList.ToArray())); + nodeList.Add(new ForwardMessageNode(MiraiConfig.MiraiBotName, MiraiConfig.MiraiBotQQ, DateTime.Now, msgList.ToArray())); } return await MiraiHelper.Session.SendGroupMessageAsync(groupId, new ForwardMessage(nodeList.ToArray())); } + public override async Task SendGroupSetuAsync(List setuContents, long groupId, bool sendMerge, int margeEachPage = 0) + { + if (sendMerge == false || margeEachPage <= 0) + { + return await SendGroupSetuAsync(setuContents, groupId, sendMerge); + } + + int startIndex = 0; + List msgIds = new List(); + while (startIndex < setuContents.Count) + { + List pageContents = setuContents.Skip(startIndex).Take(margeEachPage).ToList(); + msgIds.AddRange(await SendGroupSetuAsync(pageContents, groupId, sendMerge)); + startIndex += margeEachPage; + } + return msgIds.ToArray(); + } + public override async Task SendGroupSetuAsync(List setuContents, long groupId, bool sendMerge) { if (sendMerge) diff --git a/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/Startup.cs b/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/Startup.cs index 0f0d2b26..47ac19ae 100644 --- a/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/Startup.cs +++ b/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/Startup.cs @@ -11,6 +11,7 @@ using TheresaBot.Main.Dao; using TheresaBot.Main.Helper; using TheresaBot.Main.Timers; +using TheresaBot.MiraiHttpApi.Common; using TheresaBot.MiraiHttpApi.Helper; using TheresaBot.MiraiHttpApi.Reporter; using TheresaBot.MiraiHttpApi.Session; @@ -24,7 +25,6 @@ public class Startup public Startup(IConfiguration configuration) { Configuration = configuration; - ConfigHelper.setConfiguration(Configuration); } public void ConfigureServices(IServiceCollection services) @@ -34,17 +34,20 @@ public void ConfigureServices(IServiceCollection services) LogHelper.ConfigureLog(); LogHelper.Info($"־..."); - ConfigHelper.LoadMiraiConfig(); + MiraiHelper.LoadMiraiConfig(Configuration); ConfigHelper.LoadBotConfig(); - LogHelper.Info($"ļȡ..."); + LogHelper.Info($"ļ..."); MiraiHelper.ConnectMirai().Wait(); + LogHelper.Info($"ԶȡBotƬ..."); + Task.Delay(1000).Wait(); + MiraiHelper.LoadBotProfileAsync().Wait(); LogHelper.Info($"ʼʼݿ..."); services.AddSqlSugar(new IocConfig()//עSqlsuger { DbType = IocDbType.MySql, - ConnectionString = BotConfig.DBConfig.ConnectionString, + ConnectionString = MiraiConfig.ConnectionString, IsAutoCloseConnection = true//Զͷ }); new DBClient().CreateDB(); diff --git a/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/TheresaBot.MiraiHttpApi.csproj b/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/TheresaBot.MiraiHttpApi.csproj index 098f3cce..2f950dd9 100644 --- a/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/TheresaBot.MiraiHttpApi.csproj +++ b/Theresa3rd-Bot/TheresaBot.MiraiHttpApi/TheresaBot.MiraiHttpApi.csproj @@ -5,7 +5,7 @@ TheresaBot.MiraiHttpApi - 0.8.0 + 0.8.1 disable 3 @@ -18,9 +18,6 @@ - - -