From e4fcca8431847e2beaa12f317e21623c833a7e7e Mon Sep 17 00:00:00 2001 From: milimoe Date: Fri, 7 Mar 2025 19:10:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E4=B9=8B=E5=89=8D=E7=9A=84=E6=94=B9?= =?UTF-8?q?=E5=8A=A8=E9=83=BD=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ListeningTask/FriendMessageTask.cs | 3 +- src/ListeningTask/GroupMessageTask.cs | 92 ++++++++++++++++---------- src/ListeningTask/GroupRecallTask.cs | 33 +++++++++ src/Main.cs | 12 ++++ src/Settings/Ignore.cs | 4 ++ src/Settings/OshimaController.cs | 30 ++++++++- src/Settings/QQOpenID.cs | 3 +- 7 files changed, 137 insertions(+), 40 deletions(-) create mode 100644 src/ListeningTask/GroupRecallTask.cs diff --git a/src/ListeningTask/FriendMessageTask.cs b/src/ListeningTask/FriendMessageTask.cs index d2a00f4..dbbba8f 100644 --- a/src/ListeningTask/FriendMessageTask.cs +++ b/src/ListeningTask/FriendMessageTask.cs @@ -48,8 +48,7 @@ namespace Milimoe.RainBOT.ListeningTask string msg = QQOpenID.Bind(detail, e.user_id); await Bot.SendFriendMessage(e.user_id, "绑定", msg); } - - if (e.detail.StartsWith("解绑")) + else if (e.detail.StartsWith("解绑")) { string detail = e.detail.Replace("解绑", ""); string msg = QQOpenID.Unbind(detail, e.user_id); diff --git a/src/ListeningTask/GroupMessageTask.cs b/src/ListeningTask/GroupMessageTask.cs index 3072cfc..45fb4b7 100644 --- a/src/ListeningTask/GroupMessageTask.cs +++ b/src/ListeningTask/GroupMessageTask.cs @@ -1,6 +1,4 @@ -using System.Text.RegularExpressions; -using Microsoft.VisualBasic; -using Milimoe.OneBot.Framework; +using Milimoe.OneBot.Framework; using Milimoe.OneBot.Model.Content; using Milimoe.OneBot.Model.Event; using Milimoe.OneBot.Model.Message; @@ -102,7 +100,7 @@ namespace Milimoe.RainBOT.ListeningTask } } - if (Ignore.CustomIgnore.Any(e.detail.Contains) && Bot.BotIsAdmin(e.group_id)) + if (e.user_id != GeneralSettings.Master && Ignore.CustomIgnore.Any(e.detail.Contains) && Bot.BotIsAdmin(e.group_id)) { await Bot.SendMessage(SupportedAPI.delete_msg, e.group_id, "撤回", new DeleteMsgContent(e.real_id), true); await Bot.SendMessage(SupportedAPI.set_group_ban, e.group_id, "禁言", new SetGroupBanContent(e.group_id, e.user_id, 120), true); @@ -112,7 +110,19 @@ namespace Milimoe.RainBOT.ListeningTask if (e.detail.Contains("圣人榜")) { if (!await Bot.CheckBlackList(true, e.user_id, e.group_id)) return quick_reply; - _ = OshimaController.Instance.SCList(e.group_id); + _ = OshimaController.Instance.SCList(e.group_id, e.user_id); + } + + if (e.detail.Contains("出生榜")) + { + if (!await Bot.CheckBlackList(true, e.user_id, e.group_id)) return quick_reply; + _ = OshimaController.Instance.SCList(e.group_id, e.user_id, true); + } + + if (e.detail.Contains("圣人点数") || e.detail == "查询sc" || e.detail == "sc查询") + { + if (!await Bot.CheckBlackList(true, e.user_id, e.group_id)) return quick_reply; + _ = OshimaController.Instance.SCRecord(e.group_id, e.user_id); } if (e.detail == "查询服务器启动时间") @@ -356,14 +366,17 @@ namespace Milimoe.RainBOT.ListeningTask if (!await Bot.CheckBlackList(true, e.user_id, e.group_id) || !Bot.BotIsAdmin(e.group_id)) return quick_reply; if (e.user_id != GeneralSettings.Master) { - await Bot.SendGroupMessage(e.group_id, "禁言抽奖", "2秒后开奖~\r\n如需要忏悔,请在开奖后3秒内发送忏悔,开奖前发送无效。"); - await Task.Delay(2000); - if (!MuteRecall.WillMute.ContainsKey(e.user_id)) MuteRecall.WillMute.Add(e.user_id, e.user_id); - long mute_time = GeneralSettings.MuteTime[0] + new Random().NextInt64(GeneralSettings.MuteTime[1] - GeneralSettings.MuteTime[0]); - await Bot.SendGroupMessage(e.group_id, "禁言抽奖", "开奖啦!禁言时长:" + (mute_time / 60) + "分钟" + (mute_time % 60) + "秒。\r\n" + "你现在有3秒时间发送忏悔拒绝领奖!"); - await Task.Delay(3200); - await Bot.SendMessage(SupportedAPI.set_group_ban, e.group_id, "禁言抽奖", new SetGroupBanContent(e.group_id, e.user_id, mute_time), true); - MuteRecall.WillMute.Remove(e.user_id); + _ = Task.Run(async () => + { + await Bot.SendGroupMessage(e.group_id, "禁言抽奖", "2秒后开奖~\r\n如需要忏悔,请在开奖后3秒内发送忏悔,开奖前发送无效。"); + await Task.Delay(2000); + if (!MuteRecall.WillMute.ContainsKey(e.user_id)) MuteRecall.WillMute.Add(e.user_id, e.user_id); + long mute_time = GeneralSettings.MuteTime[0] + new Random().NextInt64(GeneralSettings.MuteTime[1] - GeneralSettings.MuteTime[0]); + await Bot.SendGroupMessage(e.group_id, "禁言抽奖", "开奖啦!禁言时长:" + (mute_time / 60) + "分钟" + (mute_time % 60) + "秒。\r\n" + "你现在有3秒时间发送忏悔拒绝领奖!"); + await Task.Delay(3200); + await Bot.SendMessage(SupportedAPI.set_group_ban, e.group_id, "禁言抽奖", new SetGroupBanContent(e.group_id, e.user_id, mute_time), true); + MuteRecall.WillMute.Remove(e.user_id); + }); } else { @@ -375,10 +388,13 @@ namespace Milimoe.RainBOT.ListeningTask else if (GeneralSettings.IsMute && e.detail == "忏悔" && MuteRecall.WillMute.ContainsKey(e.user_id)) { if (!await Bot.CheckBlackList(true, e.user_id, e.group_id) || !Bot.BotIsAdmin(e.group_id)) return quick_reply; - await Task.Delay(3800); - MuteRecall.WillMute.Remove(e.user_id); - await Bot.SendMessage(SupportedAPI.set_group_ban, e.group_id, "忏悔", new SetGroupBanContent(e.group_id, e.user_id, 0), true); - await Bot.SendGroupMessage(e.group_id, "忏悔", "忏悔成功!!希望你保持纯真,保持野性的美。"); + _ = Task.Run(async () => + { + await Task.Delay(3800); + MuteRecall.WillMute.Remove(e.user_id); + await Bot.SendMessage(SupportedAPI.set_group_ban, e.group_id, "忏悔", new SetGroupBanContent(e.group_id, e.user_id, 0), true); + await Bot.SendGroupMessage(e.group_id, "忏悔", "忏悔成功!!希望你保持纯真,保持野性的美。"); + }); return quick_reply; } @@ -457,7 +473,7 @@ namespace Milimoe.RainBOT.ListeningTask if (content.message.Count > 0) { await Bot.SendGroupMessage(e.group_id, "随机反驳不", content); - _ = OshimaController.Instance.SCAdd(e.user_id, e.group_id); + _ = OshimaController.Instance.SCAdd(e.user_id, e.group_id, e.detail); } } else if (SayNo.TriggerBeforeNo.Any(e.detail.Contains) && GeneralSettings.IsSayNo && e.CheckThrow(GeneralSettings.PSayNo, out dice)) @@ -511,7 +527,7 @@ namespace Milimoe.RainBOT.ListeningTask if (content.message.Count > 0) { await Bot.SendGroupMessage(e.group_id, "随机反驳不", content); - _ = OshimaController.Instance.SCAdd(e.user_id, e.group_id); + _ = OshimaController.Instance.SCAdd(e.user_id, e.group_id, e.detail); } } else if (e.detail.Contains("可以") && !e.detail.Contains('不') && e.CheckThrow(GeneralSettings.PSayNo, out dice)) @@ -520,12 +536,12 @@ namespace Milimoe.RainBOT.ListeningTask if (dice < (GeneralSettings.PSayNo / 2)) { await Bot.SendGroupMessage(e.group_id, "随机反驳不", "可以"); - _ = OshimaController.Instance.SCAdd(e.user_id, e.group_id); + _ = OshimaController.Instance.SCAdd(e.user_id, e.group_id, e.detail); } else { await Bot.SendGroupMessage(e.group_id, "随机反驳不", "不可以"); - _ = OshimaController.Instance.SCAdd(e.user_id, e.group_id); + _ = OshimaController.Instance.SCAdd(e.user_id, e.group_id, e.detail); } } else if (e.detail.Contains('能') && !e.detail.Contains('不') && !SayNo.IgnoreTriggerBeforeCan.Any(e.detail.Contains) && e.CheckThrow(GeneralSettings.PSayNo, out dice)) @@ -534,12 +550,12 @@ namespace Milimoe.RainBOT.ListeningTask if (dice < (GeneralSettings.PSayNo / 2)) { await Bot.SendGroupMessage(e.group_id, "随机反驳不", "能"); - _ = OshimaController.Instance.SCAdd(e.user_id, e.group_id); + _ = OshimaController.Instance.SCAdd(e.user_id, e.group_id, e.detail); } else { await Bot.SendGroupMessage(e.group_id, "随机反驳不", "不能"); - _ = OshimaController.Instance.SCAdd(e.user_id, e.group_id); + _ = OshimaController.Instance.SCAdd(e.user_id, e.group_id, e.detail); } } else if (e.detail.Contains("可能") && !e.detail.Contains('不') && e.CheckThrow(GeneralSettings.PSayNo, out dice)) @@ -548,25 +564,25 @@ namespace Milimoe.RainBOT.ListeningTask if (dice < (GeneralSettings.PSayNo / 2)) { await Bot.SendGroupMessage(e.group_id, "随机反驳不", "可能"); - _ = OshimaController.Instance.SCAdd(e.user_id, e.group_id); + _ = OshimaController.Instance.SCAdd(e.user_id, e.group_id, e.detail); } else { await Bot.SendGroupMessage(e.group_id, "随机反驳不", "不可能"); - _ = OshimaController.Instance.SCAdd(e.user_id, e.group_id); + _ = OshimaController.Instance.SCAdd(e.user_id, e.group_id, e.detail); } } else if (e.detail.Contains('要') && !e.detail.Contains('不') && e.CheckThrow(GeneralSettings.PSayNo, out dice)) { Bot.ColorfulCheckPass(sender, "随机反驳不", dice, GeneralSettings.PSayNo); await Bot.SendGroupMessage(e.group_id, "随机反驳不", SayNo.SayWantWords[new Random().Next(SayNo.SayWantWords.Count)]); - _ = OshimaController.Instance.SCAdd(e.user_id, e.group_id); + _ = OshimaController.Instance.SCAdd(e.user_id, e.group_id, e.detail); } else if (e.detail.Contains('想') && !e.detail.Contains('不') && e.CheckThrow(GeneralSettings.PSayNo, out dice)) { Bot.ColorfulCheckPass(sender, "随机反驳不", dice, GeneralSettings.PSayNo); await Bot.SendGroupMessage(e.group_id, "随机反驳不", SayNo.SayThinkWords[new Random().Next(SayNo.SayThinkWords.Count)]); - _ = OshimaController.Instance.SCAdd(e.user_id, e.group_id); + _ = OshimaController.Instance.SCAdd(e.user_id, e.group_id, e.detail); } // 反向艾特 @@ -600,20 +616,20 @@ namespace Milimoe.RainBOT.ListeningTask }; content.message.Add(new ImageMessage(img)); await Bot.SendGroupMessage(e.group_id, "Image", content); - _ = OshimaController.Instance.SCAdd(e.user_id, e.group_id); + _ = OshimaController.Instance.SCAdd(e.user_id, e.group_id, e.detail); return quick_reply; } // 随机复读 - if (GeneralSettings.IsRepeat && !Ignore.RepeatIgnore.Any(e.detail.Contains) && !Ignore.RepeatQQIgnore.Contains(e.user_id) && e.CheckThrow(GeneralSettings.PRepeat, out dice)) + if (GeneralSettings.IsRepeat && !Ignore.RepeatIgnore.Any(e.detail.Contains) && !Ignore.RepeatQQIgnore.Contains(e.user_id) && e.CheckThrow(GeneralSettings.PRepeat, out dice) && !GroupRecallTask.Recalls.ContainsKey(e.detail)) { // 出现了@at就直接触发复读,没有延迟 int delay = e.message.Where(m => m.type == "at").Any() ? 0 : GeneralSettings.RepeatDelay[0] + new Random().Next(GeneralSettings.RepeatDelay[1] - GeneralSettings.RepeatDelay[0]); Bot.ColorfulCheckPass(sender, "随机复读", dice, GeneralSettings.PRepeat, delay); GroupMessageContent content = new(e.group_id); content.message.AddRange(e.message); - await Bot.SendGroupMessage(e.group_id, "随机复读", content, delay * 1000); - _ = OshimaController.Instance.SCAdd(e.user_id, e.group_id); + _ = Bot.SendGroupMessage(e.group_id, "随机复读", content, delay * 1000); + _ = OshimaController.Instance.SCAdd(e.user_id, e.group_id, e.detail); return quick_reply; } @@ -629,7 +645,7 @@ namespace Milimoe.RainBOT.ListeningTask GroupMessageContent content = new(e.group_id); content.message.Add(new AtMessage(e.user_id)); int sc = 0; - switch (Random.Shared.Next(4)) + switch (Random.Shared.Next(6)) { case 0: content.message.Add(new TextMessage(string.Concat(name.AsSpan(pos, name.Length > 1 ? 2 : name.Length), "哥"))); @@ -642,13 +658,21 @@ namespace Milimoe.RainBOT.ListeningTask sc = Random.Shared.Next(1, 4); break; case 3: + content.message.Add(new TextMessage(string.Concat(name.AsSpan(pos, name.Length > 0 ? 1 : name.Length), "亲"))); + break; + case 4: + content.message.Add(new TextMessage(string.Concat(name.AsSpan(pos, name.Length > 1 ? 2 : name.Length), "亲"))); + break; + case 5: + content.message.Add(new TextMessage(string.Concat("哈基", name.AsSpan(pos, name.Length > 0 ? 1 : name.Length)))); + break; default: content.message.Add(new TextMessage(string.Concat(name.AsSpan(pos, name.Length > 0 ? 1 : name.Length), "出"))); sc = -Random.Shared.Next(1, 4); break; } - await Bot.SendGroupMessage(e.group_id, "随机叫哥", content, delay * 1000); - _ = OshimaController.Instance.SCAdd(e.user_id, e.group_id, sc); + _ = Bot.SendGroupMessage(e.group_id, "随机叫哥", content, delay * 1000); + _ = OshimaController.Instance.SCAdd(e.user_id, e.group_id, e.detail, sc); return quick_reply; } } diff --git a/src/ListeningTask/GroupRecallTask.cs b/src/ListeningTask/GroupRecallTask.cs new file mode 100644 index 0000000..eb261d4 --- /dev/null +++ b/src/ListeningTask/GroupRecallTask.cs @@ -0,0 +1,33 @@ +using Milimoe.OneBot.Model.Event; +using Milimoe.RainBOT.Settings; + +namespace Milimoe.RainBOT.ListeningTask +{ + public class GroupRecallTask + { + public static Dictionary Recalls { get; } = []; + + public static async Task ListeningTask_handler(GroupRecallEvent e) + { + try + { + Console.WriteLine($"{DateTime.Now:yyyy/MM/dd HH:mm:ss} N/Group_Recall G/{e.group_id}{(e.detail.Trim() == "" ? "" : " -> " + e.detail)}"); + if (GeneralSettings.IsDebug) + { + Console.ForegroundColor = ConsoleColor.Magenta; + Console.WriteLine($"DEBUG:{e.original_msg}"); + Console.ForegroundColor = ConsoleColor.Gray; + } + + Recalls[e.detail] = DateTime.Now; + await Task.CompletedTask; + } + catch (Exception ex) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine(ex); + Console.ForegroundColor = ConsoleColor.Gray; + } + } + } +} \ No newline at end of file diff --git a/src/Main.cs b/src/Main.cs index d1683e9..7abab8b 100644 --- a/src/Main.cs +++ b/src/Main.cs @@ -131,6 +131,7 @@ try listener.GroupMessageListening += GroupMessageTask.ListeningTask_handler; listener.GroupBanNoticeListening += GroupBanTask.ListeningTask_handler; listener.FriendMessageListening += FriendMessageTask.ListeningTask_handler; + listener.GroupRecallNoticeListening += GroupRecallTask.ListeningTask_handler; TaskScheduler.Shared.AddTask("发送每日新闻", new TimeSpan(8, 30, 0), async () => { @@ -198,6 +199,17 @@ try Console.WriteLine("清空所有已下载的图片,释放空间。"); Console.ForegroundColor = ConsoleColor.Gray; } + // 清除超时的撤回记录 + DateTime now = DateTime.Now.AddMinutes(-5); + List recalls = [.. GroupRecallTask.Recalls.Keys]; + foreach (string recall in recalls) + { + DateTime recallTime = GroupRecallTask.Recalls[recall]; + if (now > recallTime) + { + GroupRecallTask.Recalls.Remove(recall); + } + } } catch (Exception e) { diff --git a/src/Settings/Ignore.cs b/src/Settings/Ignore.cs index 25cb6da..093da92 100644 --- a/src/Settings/Ignore.cs +++ b/src/Settings/Ignore.cs @@ -45,6 +45,10 @@ namespace Milimoe.RainBOT.Settings { ReverseAtIgnore = (List)value; } + if (configs.TryGetValue("CustomIgnore", out value) && value != null) + { + CustomIgnore = new HashSet((List)value); + } } public static void SaveConfig() diff --git a/src/Settings/OshimaController.cs b/src/Settings/OshimaController.cs index 37d82ac..9f458dd 100644 --- a/src/Settings/OshimaController.cs +++ b/src/Settings/OshimaController.cs @@ -5,6 +5,7 @@ using Milimoe.FunGame.Core.Library.Common.Network; using Milimoe.FunGame.Core.Library.Constant; using Milimoe.FunGame.Core.Model; using Milimoe.OneBot.Model.Other; +using Milimoe.RainBOT.ListeningTask; namespace Milimoe.RainBOT.Settings { @@ -216,30 +217,53 @@ namespace Milimoe.RainBOT.Settings } } - public async Task SCAdd(long qq, long groupid, double sc = 0) + public async Task SCAdd(long qq, long groupid, string content, double sc = 0) { - if (HTTPClient != null) + if (HTTPClient != null && !GroupRecallTask.Recalls.ContainsKey(content)) { if (sc == 0) { sc = Random.Shared.Next(-3, 4); + if (sc == 0) + { + return; + } } Dictionary data = []; data.Add("command", "scadd"); data.Add("qq", qq); data.Add("groupid", groupid); + if (content.Length > 8) + { + content = content[..8] + "..."; + } + data.Add("content", content); data.Add("sc", sc); await HTTPClient.Send(SocketMessageType.AnonymousGameServer, ServerName, data); } } - public async Task SCList(long groupid) + public async Task SCList(long groupid, long qq, bool reverse = false) { if (HTTPClient != null) { Dictionary data = []; data.Add("command", "sclist"); data.Add("groupid", groupid); + data.Add("qq", qq); + data.Add("reverse", reverse); + await HTTPClient.Send(SocketMessageType.AnonymousGameServer, ServerName, data); + } + } + + public async Task SCRecord(long groupid, long qq) + { + if (HTTPClient != null) + { + Dictionary data = []; + data.Add("command", "screcord"); + data.Add("groupid", groupid); + data.Add("qq", qq); await HTTPClient.Send(SocketMessageType.AnonymousGameServer, ServerName, data); } } diff --git a/src/Settings/QQOpenID.cs b/src/Settings/QQOpenID.cs index 8653dbd..850face 100644 --- a/src/Settings/QQOpenID.cs +++ b/src/Settings/QQOpenID.cs @@ -60,8 +60,9 @@ namespace Milimoe.RainBOT.Settings public static string Unbind(string openid, long qq) { - if (QQOpenID.QQAndOpenID.TryGetValue(openid, out long bindqq) && bindqq == qq && QQOpenID.QQAndOpenID.Remove(openid)) + if (QQAndOpenID.TryGetValue(openid, out long bindqq) && bindqq == qq && QQAndOpenID.Remove(openid)) { + SaveConfig(); return NetworkUtility.JsonSerialize($"解绑成功!"); }