From fdbc3f4612a0848057dbdbee14c1f8aa16077f77 Mon Sep 17 00:00:00 2001 From: milimoe Date: Sat, 21 Dec 2024 23:53:35 +0800 Subject: [PATCH] p1 --- src/Command/MasterCommand.cs | 1 + src/ListeningTask/GroupMessageTask.cs | 331 +++++++++++++++++++++++++- 2 files changed, 319 insertions(+), 13 deletions(-) diff --git a/src/Command/MasterCommand.cs b/src/Command/MasterCommand.cs index cb66eb6..25c6c3f 100644 --- a/src/Command/MasterCommand.cs +++ b/src/Command/MasterCommand.cs @@ -242,6 +242,7 @@ namespace Milimoe.RainBOT.Command Daily.InitDaily(); SayNo.InitSayNo(); Ignore.InitIgnore(); + Bot.FunGameSimulation = false; SendMessage(send_group, target_id, "参数设定以及权限组重新加载完成。"); } else Access_Denied(send_group, target_id); diff --git a/src/ListeningTask/GroupMessageTask.cs b/src/ListeningTask/GroupMessageTask.cs index 3c4a685..6400a6b 100644 --- a/src/ListeningTask/GroupMessageTask.cs +++ b/src/ListeningTask/GroupMessageTask.cs @@ -1,4 +1,5 @@ -using Milimoe.OneBot.Framework; +using System.Text.RegularExpressions; +using Milimoe.OneBot.Framework; using Milimoe.OneBot.Model.Content; using Milimoe.OneBot.Model.Event; using Milimoe.OneBot.Model.Message; @@ -116,6 +117,18 @@ namespace Milimoe.RainBOT.ListeningTask } return quick_reply; } + + if (e.detail.StartsWith("查询任务计划")) + { + if (!await Bot.CheckBlackList(true, e.user_id, e.group_id)) return quick_reply; + string detail = e.detail.Replace("查询任务计划", "").Trim(); + string msg = await Bot.HttpGet($"https://api.milimoe.com/test/gettask?name={detail}") ?? ""; + if (msg != "") + { + await Bot.SendGroupMessage(e.group_id, "查询任务计划", msg); + } + return quick_reply; + } if (e.detail.Length >= 9 && e.detail[..9].Equals("FunGame模拟", StringComparison.CurrentCultureIgnoreCase)) { @@ -634,27 +647,319 @@ namespace Milimoe.RainBOT.ListeningTask } return quick_reply; } - - if (e.detail.Length >= 2 && e.detail[..2].Equals("决斗", StringComparison.CurrentCultureIgnoreCase)) + + if (e.detail.Length >= 4 && e.detail[..4].Equals("角色升级", StringComparison.CurrentCultureIgnoreCase)) { - string detail = e.detail.Replace("决斗", "").Replace("@", "").Trim(); - if (long.TryParse(detail.Trim(), out long eqq)) + string detail = e.detail.Replace("角色升级", "").Trim(); + string msg = ""; + if (int.TryParse(detail, out int cid)) { - List strings = await Bot.HttpPost>($"https://api.milimoe.com/fungame/fightcustom?qq={e.user_id}&eqq={eqq}") ?? []; - foreach (string msg in strings) + msg = (await Bot.HttpPost($"https://api.milimoe.com/fungame/characterlevelup?qq={e.user_id}&c={cid}") ?? "").Trim(); + } + else + { + msg = (await Bot.HttpPost($"https://api.milimoe.com/fungame/characterlevelup?qq={e.user_id}&c=1") ?? "").Trim(); + } + if (msg != "") + { + await Bot.SendGroupMessage(e.group_id, "角色升级", msg); + } + return quick_reply; + } + + if (e.detail.Length >= 4 && e.detail[..4].Equals("角色突破", StringComparison.CurrentCultureIgnoreCase)) + { + string detail = e.detail.Replace("角色突破", "").Trim(); + string msg = ""; + if (int.TryParse(detail, out int cid)) + { + msg = (await Bot.HttpPost($"https://api.milimoe.com/fungame/characterlevelbreak?qq={e.user_id}&c={cid}") ?? "").Trim(); + } + else + { + msg = (await Bot.HttpPost($"https://api.milimoe.com/fungame/characterlevelbreak?qq={e.user_id}&c=1") ?? "").Trim(); + } + if (msg != "") + { + await Bot.SendGroupMessage(e.group_id, "角色突破", msg); + } + return quick_reply; + } + + if (e.detail.Length >= 4 && e.detail[..4].Equals("突破信息", StringComparison.CurrentCultureIgnoreCase)) + { + string detail = e.detail.Replace("突破信息", "").Trim(); + string msg = ""; + if (int.TryParse(detail, out int cid)) + { + msg = (await Bot.HttpPost($"https://api.milimoe.com/fungame/getlevelbreakneedy?qq={e.user_id}&id={cid}") ?? "").Trim(); + } + else + { + msg = (await Bot.HttpPost($"https://api.milimoe.com/fungame/getlevelbreakneedy?qq={e.user_id}&id=1") ?? "").Trim(); + } + if (msg != "") + { + await Bot.SendGroupMessage(e.group_id, "突破信息", msg); + } + return quick_reply; + } + + if (e.detail.Length >= 2 && e.detail[..2].Equals("使用", StringComparison.CurrentCultureIgnoreCase)) + { + string detail = e.detail.Replace("使用", "").Trim(); + char[] chars = [',', ' ']; + string pattern = @"\s*(?[^\d]+)\s*(?\d+)\s*(?:角色\s*(?[\d\s]*))?"; + Match match = Regex.Match(detail, pattern); + if (match.Success) + { + string itemName = match.Groups["itemName"].Value.Trim(); + if (int.TryParse(match.Groups["count"].Value, out int count)) { - await Bot.SendGroupMessage(e.group_id, "决斗", msg.Trim()); - await Task.Delay(800); + string characterIdsString = match.Groups["characterIds"].Value; + int[] characterIds = characterIdsString != "" ? [.. characterIdsString.Split(chars, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse)] : [1]; + string msg = (await Bot.HttpPost($"https://api.milimoe.com/fungame/useitem2?qq={e.user_id}&name={itemName}&count={count}", System.Text.Json.JsonSerializer.Serialize(characterIds)) ?? "").Trim(); + if (msg != "") + { + await Bot.SendGroupMessage(e.group_id, "使用", msg); + } } } else { - List strings = await Bot.HttpPost>($"https://api.milimoe.com/fungame/fightcustom2?qq={e.user_id}&name={detail.Trim()}") ?? []; - foreach (string msg in strings) + pattern = @"\s*(?\d+)\s*(?:角色\s*(?[\d\s]*))?"; + match = Regex.Match(detail, pattern); + if (match.Success) { - await Bot.SendGroupMessage(e.group_id, "决斗", msg.Trim()); - await Task.Delay(800); + if (int.TryParse(match.Groups["itemId"].Value, out int itemId)) + { + string characterIdsString = match.Groups["characterIds"].Value; + int[] characterIds = characterIdsString != "" ? [.. characterIdsString.Split(chars, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse)] : [1]; + string msg = (await Bot.HttpPost($"https://api.milimoe.com/fungame/useitem?qq={e.user_id}&id={itemId}", System.Text.Json.JsonSerializer.Serialize(characterIds)) ?? "").Trim(); + if (msg != "") + { + await Bot.SendGroupMessage(e.group_id, "使用", msg); + } + } } + else + { + pattern = @"\s*(?[^\d]+)\s*(?\d+)\s*"; + match = Regex.Match(detail, pattern); + if (match.Success) + { + string itemName = match.Groups["itemName"].Value.Trim(); + if (int.TryParse(match.Groups["count"].Value, out int count)) + { + string msg = (await Bot.HttpPost($"https://api.milimoe.com/fungame/useitem2?qq={e.user_id}&name={itemName}&count={count}") ?? "").Trim(); + if (msg != "") + { + await Bot.SendGroupMessage(e.group_id, "使用", msg); + } + } + } + else + { + pattern = @"\s*(?\d+)\s*"; + match = Regex.Match(detail, pattern); + if (match.Success) + { + if (int.TryParse(match.Groups["itemId"].Value, out int itemId)) + { + string msg = (await Bot.HttpPost($"https://api.milimoe.com/fungame/useitem?qq={e.user_id}&id={itemId}") ?? "").Trim(); + if (msg != "") + { + await Bot.SendGroupMessage(e.group_id, "使用", msg); + } + } + } + } + } + } + + return quick_reply; + } + + if (e.detail.Length >= 4 && e.detail[..4].Equals("分解物品", StringComparison.CurrentCultureIgnoreCase)) + { + string detail = e.detail.Replace("分解物品", "").Trim(); + List ids = []; + foreach (string str in detail.Split(' ')) + { + if (int.TryParse(str, out int id)) + { + ids.Add(id); + } + } + string msg = (await Bot.HttpPost($"https://api.milimoe.com/fungame/decomposeitem?qq={e.user_id}", System.Text.Json.JsonSerializer.Serialize(ids)) ?? "").Trim(); + if (msg != "") + { + await Bot.SendGroupMessage(e.group_id, "分解物品", msg); + } + + return quick_reply; + } + + if (e.detail.Length >= 2 && e.detail[..2].Equals("分解", StringComparison.CurrentCultureIgnoreCase)) + { + string detail = e.detail.Replace("分解", "").Trim(); + string pattern = @"\s*(?[^\d]+)\s*(?\d+)\s*"; + Match match = Regex.Match(detail, pattern); + if (match.Success) + { + string itemName = match.Groups["itemName"].Value.Trim(); + if (int.TryParse(match.Groups["count"].Value, out int count)) + { + string msg = (await Bot.HttpPost($"https://api.milimoe.com/fungame/decomposeitem2?qq={e.user_id}&name={itemName}&count={count}") ?? "").Trim(); + if (msg != "") + { + await Bot.SendGroupMessage(e.group_id, "分解", msg); + } + } + } + + return quick_reply; + } + + if (e.detail.Length >= 4 && e.detail[..4].Equals("品质分解", StringComparison.CurrentCultureIgnoreCase)) + { + string detail = e.detail.Replace("品质分解", "").Trim(); + if (int.TryParse(detail, out int q)) + { + string msg = (await Bot.HttpPost($"https://api.milimoe.com/fungame/decomposeitem3?qq={e.user_id}&q={q}") ?? "").Trim(); + if (msg != "") + { + await Bot.SendGroupMessage(e.group_id, "品质分解", msg); + } + } + + return quick_reply; + } + + if (e.detail.Length >= 4 && e.detail[..4].Equals("熟圣之力", StringComparison.CurrentCultureIgnoreCase)) + { + string detail = e.detail.Replace("熟圣之力", "").Trim(); + string[] strings = detail.Split(" "); + int count = -1; + if (strings.Length > 1 && int.TryParse(strings[1].Trim(), out count)) + { + string name = strings[0].Trim(); + if (count > 0) + { + long userid = e.user_id; + if (strings.Length > 2 && long.TryParse(strings[2].Replace("@", "").Trim(), out long temp)) + { + userid = temp; + } + string msg = (await Bot.HttpPost($"https://api.milimoe.com/fungame/createitem?qq={e.user_id}&name={name}&count={count}&target={userid}") ?? "").Trim(); + if (msg != "") + { + await Bot.SendGroupMessage(e.group_id, "熟圣之力", msg); + } + } + else + { + await Bot.SendGroupMessage(e.group_id, "熟圣之力", "数量不能为0,请重新输入。"); + } + } + return quick_reply; + } + + if (e.detail.Length >= 4 && e.detail[..4].Equals("完整决斗", StringComparison.CurrentCultureIgnoreCase)) + { + string detail = e.detail.Replace("完整决斗", "").Replace("@", "").Trim(); + List msgs = []; + if (long.TryParse(detail.Trim(), out long eqq)) + { + msgs = await Bot.HttpPost>($"https://api.milimoe.com/fungame/fightcustom?qq={e.user_id}&eqq={eqq}&all=true") ?? []; + } + else + { + msgs = await Bot.HttpPost>($"https://api.milimoe.com/fungame/fightcustom2?qq={e.user_id}&name={detail.Trim()}&all=true") ?? []; + } + List real = []; + if (msgs.Count > 2) + { + if (msgs.Count < 20) + { + int remain = 7; + string merge = ""; + for (int i = 0; i < msgs.Count - 1; i++) + { + remain--; + merge += msgs[i] + "\r\n"; + if (remain == 0) + { + real.Add(merge); + merge = ""; + if ((msgs.Count - i - 2) < 7) + { + remain = msgs.Count - i - 2; + } + else remain = 7; + } + } + } + else + { + real.Add(msgs[^2]); + } + real.Add(msgs[^1]); + } + else + { + real = msgs; + } + foreach (string msg in real) + { + await Bot.SendGroupMessage(e.group_id, "完整决斗", msg.Trim()); + await Task.Delay(1500); + } + return quick_reply; + } + + if (e.detail.Length >= 2 && e.detail[..2].Equals("决斗", StringComparison.CurrentCultureIgnoreCase)) + { + string detail = e.detail.Replace("决斗", "").Replace("@", "").Trim(); + List msgs = []; + if (long.TryParse(detail.Trim(), out long eqq)) + { + msgs = await Bot.HttpPost>($"https://api.milimoe.com/fungame/fightcustom?qq={e.user_id}&eqq={eqq}&all=false") ?? []; + } + else + { + msgs = await Bot.HttpPost>($"https://api.milimoe.com/fungame/fightcustom2?qq={e.user_id}&name={detail.Trim()}&all=false") ?? []; + } + List real = []; + if (msgs.Count > 2) + { + int remain = 7; + string merge = ""; + for (int i = 0; i < msgs.Count - 1; i++) + { + remain--; + merge += msgs[i] + "\r\n"; + if (remain == 0) + { + real.Add(merge); + merge = ""; + if ((msgs.Count - i - 3) < 7) + { + remain = msgs.Count - i - 3; + } + else remain = 7; + } + } + real.Add(msgs[^1]); + } + else + { + real = msgs; + } + foreach (string msg in real) + { + await Bot.SendGroupMessage(e.group_id, "决斗", msg.Trim()); + await Task.Delay(1500); } return quick_reply; }