diff --git a/src/Command/MasterCommand.cs b/src/Command/MasterCommand.cs index fcb9a8e..47af594 100644 --- a/src/Command/MasterCommand.cs +++ b/src/Command/MasterCommand.cs @@ -367,6 +367,34 @@ namespace Milimoe.RainBOT.Command } return; } + else if (command.Contains(".osm sc")) + { + if (send_group) + { + if (user_id == GeneralSettings.Master) + { + string pattern = @"^\.osm\s+sc\s+(\d+)\s+([+-])(\d+)(?:\s+(.+))?$"; + Match match = Regex.Match(command.ToLower().Trim().Replace("@", ""), pattern); + if (match.Success) + { + long qq = long.Parse(match.Groups[1].Value); + bool isAdd = match.Groups[2].Value == "+"; + int sc = Math.Abs(int.Parse(match.Groups[3].Value)); + string reason = match.Groups.Count > 4 ? match.Groups[4].Value : ""; + _ = OshimaController.Instance.SCAdd(qq, target_id, reason, isAdd ? sc : -sc); + } + else + { + SendMessage(send_group, target_id, "OSM Core:指令格式不正确或传入的参数不支持。\r\n格式:.osm sc (+/-) [reason]"); + } + } + else Access_Denied(send_group, target_id); + } + else + { + SendMessage(send_group, target_id, "OSM Core:此命令仅允许在群聊中使用。"); + } + } else { SendMessage(send_group, target_id, Execute_Worker(".osm missingcommand", "")); diff --git a/src/ListeningTask/GroupMessageTask.cs b/src/ListeningTask/GroupMessageTask.cs index 03925bb..6ddaa9a 100644 --- a/src/ListeningTask/GroupMessageTask.cs +++ b/src/ListeningTask/GroupMessageTask.cs @@ -42,7 +42,7 @@ namespace Milimoe.RainBOT.ListeningTask if (NoSpamming.NoSpammingData.TryGetValue(e.group_id, out NoSpamming? value) && value != null) { - if (await value.Check(e.user_id)) + if (await value.Check(e.user_id, e.message.Any(e => e.type == "image"))) { await Bot.SendGroupMessage(e.group_id, "刷屏检测", "喜欢刷屏?吔屎啦你!"); return quick_reply; diff --git a/src/Main.cs b/src/Main.cs index 2804406..8d57735 100644 --- a/src/Main.cs +++ b/src/Main.cs @@ -217,11 +217,8 @@ try foreach (NoSpamming ns in NoSpamming.NoSpammingData.Values) { ns.Times.Clear(); - if (NoSpamming.Refresh++ > 4) - { - ns.History.Clear(); - NoSpamming.Refresh = 0; - } + ns.History.Clear(); + ns.HistoryImage.Clear(); } } catch (Exception e) diff --git a/src/Settings/NoSpamming.cs b/src/Settings/NoSpamming.cs index b909622..1d2235e 100644 --- a/src/Settings/NoSpamming.cs +++ b/src/Settings/NoSpamming.cs @@ -11,6 +11,7 @@ namespace Milimoe.RainBOT.Settings public static ConcurrentDictionary NoSpammingData { get; } = []; public List History { get; } = []; + public List HistoryImage { get; } = []; public long GroupId { get; set; } = groupId; public Dictionary Times { get; } = []; @@ -26,19 +27,20 @@ namespace Milimoe.RainBOT.Settings } } - public async Task Check(long qq) + public async Task Check(long qq, bool isImage = false) { if (!Bot.BotIsAdmin(GroupId)) { return false; } - History.Add(qq); + if (!isImage) History.Add(qq); + else HistoryImage.Add(qq); if (Times.TryGetValue(qq, out int times)) { Times[qq] = ++times; int total = Times.Values.Sum(); - double check = total > 8 ? times / total : 0; - if (qq != GeneralSettings.Master && (check > 0.9 || (History.Count > 8 && History.TakeLast(8).All(q => q == qq)))) + double check = total > 12 ? times / total : 0; + if (qq != GeneralSettings.Master && (check > 0.9 || (History.Count > 15 && History.TakeLast(15).All(q => q == qq))) || (HistoryImage.Count > 8 && HistoryImage.TakeLast(8).All(q => q == qq))) { Times.Remove(qq); await Bot.SendMessage(SupportedAPI.set_group_ban, GroupId, "禁言", new SetGroupBanContent(GroupId, qq, 120), true); @@ -54,6 +56,10 @@ namespace Milimoe.RainBOT.Settings { History.Clear(); } + if (HistoryImage.Count > 200) + { + HistoryImage.Clear(); + } return false; } }