diff --git a/dll/FunGame.Core.dll b/dll/FunGame.Core.dll index ae7e4e7..7817bf5 100644 Binary files a/dll/FunGame.Core.dll and b/dll/FunGame.Core.dll differ diff --git a/dll/FunGame.Core.xml b/dll/FunGame.Core.xml index 618604f..6d37edb 100644 --- a/dll/FunGame.Core.xml +++ b/dll/FunGame.Core.xml @@ -535,11 +535,22 @@ - + + + 获取技能实例 + + + + + + 获取技能特效实例 + + + + 获取物品实例 - Item类型 主动 或 被动 @@ -847,6 +858,22 @@ + + + 发送 GET 请求 + + + + + + + 发送 POST 请求 + + + + + + 时间服务工具箱 @@ -1983,6 +2010,11 @@ 角色的详细资料 + + + 角色的详细资料 + + 魔法属性 @@ -2473,7 +2505,7 @@ - 比较一个角色(只比较 ) + 比较一个角色(只比较 @@ -2523,6 +2555,22 @@ + + + 角色的一些个人信息 + + + + + + + + 角色的一些个人信息 + + + + + 角色的姓 @@ -2578,12 +2626,149 @@ 角色的故事 - + - 特殊效果类,需要继承 + 角色的装备槽位 - + + + 角色的装备槽位 + + + + + 魔法卡包 + + + + + 武器 + + + + + 防具 + + + + + 鞋子 + + + + + 饰品1 + + + + + 饰品2 + + + + + 角色的魔法抗性,对不同的魔法类型有不同抗性 + + + + + 角色的魔法抗性,对不同的魔法类型有不同抗性 + + + + + 和 一样,需要继承构造 + + + + + 物品的描述 + + + + + 物品类型 + + + + + 物品槽位 + + + + + 物品的价格 + + + + + 快捷键 + + + + + 是否是主动物品 + + + + + 是否可用(涉及冷却和禁用等) + + + + + 物品所属的角色 + + + + + 物品拥有的技能 + + + + + 当获得物品时 + + + + + 局内使用物品触发 + + + + + 局外(库存)使用物品触发 + + + + + 当物品被使用时 + + + + + 判断两个物品是否相同 检查Id.Name + + + + + + + 物品只有一个主动技能,但是可以有很多个被动技能 + + + + + 唯一的主动技能 + + + + + 被动技能组 + + + 特殊效果类,需要继承 @@ -2977,11 +3162,6 @@ 技能描述 - - - 快捷键 - - 技能等级,等于 0 时可以称之为尚未学习 @@ -2989,7 +3169,7 @@ - 技能 [ 此项为最高优先级 ] + 技能类型 [ 此项为最高优先级 ] @@ -3072,6 +3252,18 @@ 游戏中的行动顺序表实例,在技能效果被触发时,此实例会获得赋值,使用时需要判断其是否存在 + + + 继承此类实现时,调用基类的构造函数 + + + + + + + 用于构造 JSON + + 触发技能升级 @@ -3105,6 +3297,13 @@ + + + 判断两个技能是否相同 检查Id.Name + + + + 等级 diff --git a/dll/OneBot-HTTPClient.dll b/dll/OneBot-HTTPClient.dll index 378cc78..aca3482 100644 Binary files a/dll/OneBot-HTTPClient.dll and b/dll/OneBot-HTTPClient.dll differ diff --git a/src/ListeningTask/FriendMessageTask.cs b/src/ListeningTask/FriendMessageTask.cs index d6edbfe..b05b980 100644 --- a/src/ListeningTask/FriendMessageTask.cs +++ b/src/ListeningTask/FriendMessageTask.cs @@ -55,6 +55,27 @@ namespace Milimoe.RainBOT.ListeningTask return quick_reply; } + if (e.detail.Length >= 9 && e.detail[..9].Equals("FunGame模拟", StringComparison.CurrentCultureIgnoreCase)) + { + if (!await Bot.CheckBlackList(true, e.user_id, e.user_id)) return quick_reply; + if (!Bot.FunGameSimulation) + { + Bot.FunGameSimulation = true; + List msgs = await Bot.HttpGet>("https://api.milimoe.com/fungame/test?isweb=false") ?? []; + foreach (string msg in msgs) + { + await Bot.SendFriendMessage(e.user_id, "FunGame模拟", msg.Trim()); + await Task.Delay(5500); + } + Bot.FunGameSimulation = false; + } + else + { + await Bot.SendFriendMessage(e.user_id, "FunGame模拟", "游戏正在模拟中,请勿重复请求!"); + } + return quick_reply; + } + if (GeneralSettings.IsMute && e.detail == "忏悔") { if (!await Bot.CheckBlackList(false, e.user_id, e.user_id)) return quick_reply; diff --git a/src/ListeningTask/GroupMessageTask.cs b/src/ListeningTask/GroupMessageTask.cs index fdfea38..144d5c0 100644 --- a/src/ListeningTask/GroupMessageTask.cs +++ b/src/ListeningTask/GroupMessageTask.cs @@ -24,6 +24,11 @@ namespace Milimoe.RainBOT.ListeningTask Sender sender = e.sender; if (e.user_id == 0 || e.sender.user_id == 0) return quick_reply; + if (GeneralSettings.DebugGroupID != 0 && e.group_id != GeneralSettings.DebugGroupID) + { + Console.WriteLine($"{e.group_id} 不是沙盒群聊,已经过滤。"); + return quick_reply; + } Console.WriteLine($"{DateTime.Now:yyyy/MM/dd HH:mm:ss} G/{e.group_id}{(e.detail.Trim() == "" ? "" : " -> " + e.detail)} by {sender.user_id}({(sender.card != "" ? sender.card : sender.nickname)})"); if (GeneralSettings.IsDebug) { @@ -73,6 +78,27 @@ namespace Milimoe.RainBOT.ListeningTask } } + // 精华消息 + if ((e.user_id == GeneralSettings.Master || Bot.IsAdmin(e.group_id, e.user_id)) && e.detail.Contains("精华;") && e.message.Any(m => m.type == "reply")) + { + ReplyMessage reply = (ReplyMessage)e.message.Where(m => m.type == "reply").First(); + if (int.TryParse(reply.data.id, out int id)) + { + if (e.detail.Contains("取消精华;")) + { + await Bot.SendMessage(SupportedAPI.delete_essence_msg, e.group_id, "取消精华", new DeleteEssenceMsgContent(id), true); + await Bot.SendMessage(SupportedAPI.delete_msg, e.group_id, "撤回", new DeleteMsgContent(e.real_id), true); + return quick_reply; + } + else + { + await Bot.SendMessage(SupportedAPI.set_essence_msg, e.group_id, "设置精华", new EssenceMsgContent(id), true); + await Bot.SendMessage(SupportedAPI.delete_msg, e.group_id, "撤回", new DeleteMsgContent(e.real_id), true); + return quick_reply; + } + } + } + if (!GeneralSettings.IsRun) { return quick_reply; @@ -114,37 +140,89 @@ namespace Milimoe.RainBOT.ListeningTask return quick_reply; } + if (e.detail.Length >= 9 && e.detail[..9].Equals("FunGame模拟", StringComparison.CurrentCultureIgnoreCase)) + { + if (!await Bot.CheckBlackList(true, e.user_id, e.group_id)) return quick_reply; + if (!Bot.FunGameSimulation) + { + Bot.FunGameSimulation = true; + List msgs = await Bot.HttpGet>("https://api.milimoe.com/fungame/test?isweb=false") ?? []; + foreach (string msg in msgs) + { + await Bot.SendGroupMessage(e.group_id, "FunGame模拟", msg.Trim()); + await Task.Delay(5500); + } + Bot.FunGameSimulation = false; + } + else + { + await Bot.SendGroupMessage(e.group_id, "FunGame模拟", "游戏正在模拟中,请勿重复请求!"); + } + return quick_reply; + } + + if (e.detail.Length >= 3 && e.detail[..3].Equals("查数据", StringComparison.CurrentCultureIgnoreCase)) + { + if (!await Bot.CheckBlackList(true, e.user_id, e.group_id)) return quick_reply; + string detail = e.detail.Replace("查数据", "").Trim(); + if (int.TryParse(detail, out int id)) + { + string msg = (await Bot.HttpGet("https://api.milimoe.com/fungame/stats?id=" + id) ?? "").Trim(); + if (msg != "") + { + await Bot.SendGroupMessage(e.group_id, "查询FunGame数据", msg); + } + } + return quick_reply; + } + // 发图API if (e.detail == "来图") { if (!await Bot.CheckBlackList(true, e.user_id, e.group_id)) return quick_reply; - GroupMessageContent content = new(e.group_id); - content.message.Add(new ImageMessage("https://iw233.cn/api.php?sort=random")); - await Bot.SendGroupMessage(e.group_id, "Image", content); + Guid guid = await Bot.DownloadImageStream("https://iw233.cn/api.php?sort=random", "https://weibo.com/"); + if (guid != Guid.Empty) + { + GroupMessageContent content = new(e.group_id); + content.message.Add(new ImageMessage("file:///" + AppDomain.CurrentDomain.BaseDirectory.ToString() + @"img\download\" + guid.ToString() + ".jpg")); + await Bot.SendGroupMessage(e.group_id, "Image", content); + } return quick_reply; } if (e.detail.Contains("白毛")) { if (!await Bot.CheckBlackList(true, e.user_id, e.group_id)) return quick_reply; - GroupMessageContent content = new(e.group_id); - content.message.Add(new ImageMessage("https://iw233.cn/api.php?sort=yin")); - await Bot.SendGroupMessage(e.group_id, "Image", content); + Guid guid = await Bot.DownloadImageStream("https://iw233.cn/api.php?sort=yin", "https://weibo.com/"); + if (guid != Guid.Empty) + { + GroupMessageContent content = new(e.group_id); + content.message.Add(new ImageMessage("file:///" + AppDomain.CurrentDomain.BaseDirectory.ToString() + @"img\download\" + guid.ToString() + ".jpg")); + await Bot.SendGroupMessage(e.group_id, "Image", content); + } return quick_reply; } if (e.detail == "猫耳") { if (!await Bot.CheckBlackList(true, e.user_id, e.group_id)) return quick_reply; - GroupMessageContent content = new(e.group_id); - content.message.Add(new ImageMessage("https://iw233.cn/api.php?sort=cat")); - await Bot.SendGroupMessage(e.group_id, "Image", content); + Guid guid = await Bot.DownloadImageStream("https://iw233.cn/api.php?sort=cat", "https://weibo.com/"); + if (guid != Guid.Empty) + { + GroupMessageContent content = new(e.group_id); + content.message.Add(new ImageMessage("file:///" + AppDomain.CurrentDomain.BaseDirectory.ToString() + @"img\download\" + guid.ToString() + ".jpg")); + await Bot.SendGroupMessage(e.group_id, "Image", content); + } return quick_reply; } if (e.detail == "壁纸") { if (!await Bot.CheckBlackList(true, e.user_id, e.group_id)) return quick_reply; - GroupMessageContent content = new(e.group_id); - content.message.Add(new ImageMessage("https://iw233.cn/api.php?sort=pc")); - await Bot.SendGroupMessage(e.group_id, "Image", content); + Guid guid = await Bot.DownloadImageStream("https://iw233.cn/api.php?sort=pc", "https://weibo.com/"); + if (guid != Guid.Empty) + { + GroupMessageContent content = new(e.group_id); + content.message.Add(new ImageMessage("file:///" + AppDomain.CurrentDomain.BaseDirectory.ToString() + @"img\download\" + guid.ToString() + ".jpg")); + await Bot.SendGroupMessage(e.group_id, "Image", content); + } return quick_reply; } if (e.detail == "新闻") diff --git a/src/Main.cs b/src/Main.cs index 5176dc4..ab5ecb0 100644 --- a/src/Main.cs +++ b/src/Main.cs @@ -1,4 +1,5 @@ -using Milimoe.OneBot.Framework; +using System.IO; +using Milimoe.OneBot.Framework; using Milimoe.OneBot.Model.Content; using Milimoe.OneBot.Model.Message; using Milimoe.OneBot.Model.Other; @@ -17,6 +18,19 @@ try Console.ForegroundColor = ConsoleColor.Gray; } + if (args.Any(a => a.StartsWith("-g"))) + { + string debug_group = args.Where(a => a.StartsWith("-g")).FirstOrDefault() ?? ""; + debug_group = debug_group.Replace("-g", "").Trim(); + if (long.TryParse(debug_group, out long group_id)) + { + GeneralSettings.DebugGroupID = group_id; + Console.ForegroundColor = ConsoleColor.Cyan; + Console.WriteLine("已指定Debug调试沙盒群聊:" + GeneralSettings.DebugGroupID); + Console.ForegroundColor = ConsoleColor.Gray; + } + } + HTTPListener? listener = default; // 首先需要创建一个HTTP监听器 @@ -170,6 +184,19 @@ try { BlackList.Times.Remove(uid); } + // 清空所有已下载的图片,释放空间 + string directory = AppDomain.CurrentDomain.BaseDirectory.ToString() + @"img\download\"; + if (Directory.Exists(directory)) + { + foreach (string file in Directory.GetFiles(directory)) + { + try + { + File.Delete(file); + } + catch { } + } + } } catch (Exception e) { diff --git a/src/Properties/launchSettings.json b/src/Properties/launchSettings.json index 7bea3be..5f55d09 100644 --- a/src/Properties/launchSettings.json +++ b/src/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "RainBOT": { "commandName": "Project", - "commandLineArgs": "--debug" + "commandLineArgs": "--debug -g667678970" } } } \ No newline at end of file diff --git a/src/RainBOT.csproj b/src/RainBOT.csproj index e3c36d4..4be1eca 100644 --- a/src/RainBOT.csproj +++ b/src/RainBOT.csproj @@ -22,7 +22,7 @@ - ..\..\OneBot-HTTPClient\bin\Release\net8.0\win-x64\OneBot-HTTPClient.dll + ..\dll\OneBot-HTTPClient.dll diff --git a/src/Settings/Bot.cs b/src/Settings/Bot.cs index 04ef297..e5cfbba 100644 --- a/src/Settings/Bot.cs +++ b/src/Settings/Bot.cs @@ -1,4 +1,5 @@ -using System.Text.Json; +using System.Text; +using System.Text.Json; using System.Text.RegularExpressions; using Milimoe.OneBot.Framework; using Milimoe.OneBot.Framework.Interface; @@ -22,6 +23,8 @@ namespace Milimoe.RainBOT.Settings public static Dictionary> GroupMembers { get; set; } = []; + public static bool FunGameSimulation { get; set; } = false; + public static bool IsAdmin(long group_id, long user_id) { if (GroupMembers.TryGetValue(group_id, out List? members) && members != null && members.Any(m => m.user_id == user_id && (m.role == "owner" || m.role == "admin"))) @@ -176,7 +179,7 @@ namespace Milimoe.RainBOT.Settings } await SendMessage(SupportedAPI.send_group_msg, group_id, function, content, true); } - + public static async Task SendGroupMessage(long group_id, string function, IEnumerable contents) => await SendMessage(SupportedAPI.send_group_msg, group_id, function, contents, true); public static async Task SendFriendMessage(long user_id, string function, string text) @@ -190,10 +193,10 @@ namespace Milimoe.RainBOT.Settings public static async Task SendFriendMessage(long user_id, string function, IEnumerable contents) => await SendMessage(SupportedAPI.send_private_msg, user_id, function, contents, false); - public static async Task SendMessage(string api, long target_id, string function, IContent content, bool send_group) + public static async Task SendMessage(string api, long target_id, string function, IContent content, bool send_group, string referrer = "") { string msg_type = send_group ? "G" : "P"; - string result = (await HTTPPost.Post(api, content)).ReasonPhrase ?? ""; + string result = (await HTTPPost.Post(api, content, referrer)).ReasonPhrase ?? ""; Console.Write($"{DateTime.Now:yyyy/MM/dd HH:mm:ss} F/"); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write(function); @@ -208,10 +211,10 @@ namespace Milimoe.RainBOT.Settings } } - public static async Task SendMessage(string api, long target_id, string function, IEnumerable contents, bool send_group) + public static async Task SendMessage(string api, long target_id, string function, IEnumerable contents, bool send_group, string referrer = "") { string msg_type = send_group ? "G" : "P"; - await HTTPPost.Post(api, contents); + await HTTPPost.Post(api, contents, referrer); Console.Write($"{DateTime.Now:yyyy/MM/dd HH:mm:ss} F/"); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write(function); @@ -378,5 +381,59 @@ namespace Milimoe.RainBOT.Settings Console.WriteLine("已解禁所有参与12点大挑战的成员。"); Console.ForegroundColor = ConsoleColor.Gray; } + + private static readonly HttpClient client = new(); + + public static async Task HttpGet(string url) + { + HttpResponseMessage response = await client.GetAsync(url); + response.EnsureSuccessStatusCode(); + + string content = await response.Content.ReadAsStringAsync(); + T? result = JsonSerializer.Deserialize(content); + return result; + } + + public static async Task HttpPost(string url, string json) + { + HttpContent content = new StringContent(json, Encoding.UTF8, "application/json"); + HttpResponseMessage response = await client.PostAsync(url, content); + response.EnsureSuccessStatusCode(); + + string read = await response.Content.ReadAsStringAsync(); + T? result = JsonSerializer.Deserialize(read); + return result; + } + + public static async Task DownloadImageStream(string url, string referrer) + { + try + { + HttpClient client = new(); + if (referrer.Trim() != "") client.DefaultRequestHeaders.Referrer = new Uri(referrer); + using HttpResponseMessage response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead); + response.EnsureSuccessStatusCode(); + + // 使用流的方式处理图片数据 + string directory = AppDomain.CurrentDomain.BaseDirectory.ToString() + @"img\download\"; + if (!Directory.Exists(directory)) + { + Directory.CreateDirectory(directory); + } + + Guid guid = Guid.NewGuid(); + using Stream contentStream = await response.Content.ReadAsStreamAsync(), fileStream = new FileStream(directory + guid.ToString() + ".jpg", FileMode.Create, FileAccess.Write, FileShare.None, 16384, true); + await contentStream.CopyToAsync(fileStream); + client.Dispose(); + return guid; + } + catch (Exception e) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine(e); + Console.ForegroundColor = ConsoleColor.Gray; + return Guid.Empty; + } + } } } diff --git a/src/Settings/GeneralSettings.cs b/src/Settings/GeneralSettings.cs index 23a576a..8f7f52b 100644 --- a/src/Settings/GeneralSettings.cs +++ b/src/Settings/GeneralSettings.cs @@ -38,6 +38,8 @@ namespace Milimoe.RainBOT.Settings public static bool IsDebug { get; set; } = false; + public static long DebugGroupID { get; set; } = 0; + public static long BlackTimes { get; set; } = 5; public static int BlackFrozenTime { get; set; } = 150; diff --git a/src/Settings/OSMCore.cs b/src/Settings/OSMCore.cs index 67837e7..a3da413 100644 --- a/src/Settings/OSMCore.cs +++ b/src/Settings/OSMCore.cs @@ -4,7 +4,7 @@ { public const string version = "v1.0"; public const string version2 = "Patch10"; - public const string time = "Sep. 12th 2024"; + public const string time = "Sep. 22nd 2024"; public static string Info => $"OSM Core {version} {version2}\r\nAuthor: Milimoe\r\nBuilt on {time}\r\nSee: https://github.com/milimoe"; }