From 5024755e1770f08bc55d21e3b94c23fc4a0c73c9 Mon Sep 17 00:00:00 2001 From: milimoe Date: Mon, 1 Jul 2024 20:31:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0ignore=E7=9A=84=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Command/MasterCommand.cs | 54 ++++++++++++++++++++++++++ src/Settings/Ignore.cs | 73 ++++++++++++++++++++++++++++++++++-- src/Settings/OSMCore.cs | 4 +- 3 files changed, 126 insertions(+), 5 deletions(-) diff --git a/src/Command/MasterCommand.cs b/src/Command/MasterCommand.cs index 4f6e19b..c85e97e 100644 --- a/src/Command/MasterCommand.cs +++ b/src/Command/MasterCommand.cs @@ -159,6 +159,46 @@ namespace Milimoe.RainBOT.Command SendMessage(send_group, target_id, msg); } } + else if (command.Contains(".osm ignore")) + { + if (user_id == GeneralSettings.Master) + { + string str = command.Replace(".osm ignore", "").Trim(); + string[] strs = Regex.Split(str, @"\s+"); + if (strs.Length >= 3) + { + string part = strs[0].ToString().Trim(); + string addorremove = strs[1].ToString().Trim(); + string value = string.Join("", strs[2..]).Trim(); + if (addorremove == "add" || addorremove == "remove" || addorremove == "+" || addorremove == "-") + { + bool isadd = addorremove == "add" || addorremove == "+"; + bool access = GeneralSettings.Master == user_id; + if (access) + { + if (Ignore.AddValue(part, isadd, value)) + { + string msg = AddValue_Ignore(part, isadd, value); + SendMessage(send_group, target_id, msg); + return; + } + } + else + { + Access_Denied(send_group, target_id); + return; + } + } + } + } + else + { + Access_Denied(send_group, target_id); + return; + } + SendMessage(send_group, target_id, Execute_Worker(".osm missingcommand", "")); + return; + } else if (command.Contains(".osm showlist")) { string str = command.Replace(".osm showlist", "").Trim(); @@ -170,6 +210,10 @@ namespace Milimoe.RainBOT.Command { GeneralSettings.ShowAccessGroupMemberList(target_id, part, send_group); } + if (part.Contains("ignore")) + { + Ignore.ShowList(target_id, part, send_group); + } else { SayNo.ShowList(target_id, part, send_group); @@ -603,5 +647,15 @@ namespace Milimoe.RainBOT.Command SayNo.SaveConfig(); return msg; } + + public static string AddValue_Ignore(string part, bool isadd, string value, ConsoleColor color = ConsoleColor.Cyan) + { + string msg = "OSM Core:" + part + $"已{(isadd ? "添加" : "移除")}:" + value + "。"; + Console.ForegroundColor = color; + Console.WriteLine(msg); + Console.ForegroundColor = ConsoleColor.Gray; + Ignore.SaveConfig(); + return msg; + } } } diff --git a/src/Settings/Ignore.cs b/src/Settings/Ignore.cs index 961b201..984881e 100644 --- a/src/Settings/Ignore.cs +++ b/src/Settings/Ignore.cs @@ -6,7 +6,14 @@ namespace Milimoe.RainBOT.Settings { public static HashSet RepeatIgnore { get; set; } = []; - public static List IgnoreQQGroup { get; set; } = []; + public static List CallBrotherQQIgnore { get; set; } = []; + + /// + /// 这个属性暂时没用到 标记一下 + /// + public static List QQGroupIgnore { get; set; } = []; + + public static PluginConfig Configs { get; set; } = new("rainbot", "ignore"); public static void InitIgnore() { @@ -16,10 +23,70 @@ namespace Milimoe.RainBOT.Settings { RepeatIgnore = new HashSet((List)value); } - if (configs.TryGetValue("IgnoreQQGroup", out value) && value != null) + if (configs.TryGetValue("CallBrotherQQIgnore", out value) && value != null) { - IgnoreQQGroup = (List)value; + CallBrotherQQIgnore = new List((List)value); } + if (configs.TryGetValue("QQGroupIgnore", out value) && value != null) + { + QQGroupIgnore = (List)value; + } + } + + public static void SaveConfig() + { + Configs.Add("RepeatIgnore", RepeatIgnore); + Configs.Add("CallBrotherQQIgnore", CallBrotherQQIgnore); + Configs.Add("QQGroupIgnore", QQGroupIgnore); + Configs.Save(); + } + + public static bool AddValue(string part, bool isadd, object value) + { + try + { + switch (part.ToLower()) + { + case "repeatignore": + if (isadd) RepeatIgnore.Add((string)value); + else RepeatIgnore.Remove((string)value); + break; + case "callbrotherqqignore": + if (isadd) CallBrotherQQIgnore.Add((string)value); + else CallBrotherQQIgnore.Remove((string)value); + break; + case "qqgroupignore": + if (isadd) QQGroupIgnore.Add((long)value); + else QQGroupIgnore.Remove((long)value); + break; + default: + return false; + } + } + catch + { + return false; + } + return true; + } + + public static void ShowList(long target, string group, bool isgroup) + { + List list = []; + switch (group.ToLower()) + { + case "repeatignore": + list = [..RepeatIgnore]; + break; + case "callbrotherqqignore": + list = CallBrotherQQIgnore; + break; + case "qqgroupignore": + list = QQGroupIgnore.Select(x => x.ToString()).ToList(); + break; + } + string msg = list.Count > 0 ? "列表" + group + "拥有一下成员:" + "\r\n" + string.Join("\r\n", list) : "此列表不存在或没有任何成员。"; + _ = isgroup ? Bot.SendGroupMessage(target, "显示列表成员", msg) : Bot.SendFriendMessage(target, "显示列表成员", msg); } } } diff --git a/src/Settings/OSMCore.cs b/src/Settings/OSMCore.cs index fcd5891..18d9dbf 100644 --- a/src/Settings/OSMCore.cs +++ b/src/Settings/OSMCore.cs @@ -3,8 +3,8 @@ public class OSMCore { public const string version = "v1.0"; - public const string version2 = "Patch7 Test"; - public const string time = "Jun. 30th, 2024"; + public const string version2 = "Patch7 Test2"; + public const string time = "July 1st, 2024"; public static string Info => $"OSM Core {version} {version2}\r\nAuthor: Milimoe\r\nBuilt on {time}\r\nSee: https://github.com/milimoe"; }