添加ignore的列表操作

This commit is contained in:
milimoe 2024-07-01 20:31:42 +08:00
parent ad1aceb96c
commit 5024755e17
Signed by: milimoe
GPG Key ID: 05D280912DA6C69E
3 changed files with 126 additions and 5 deletions

View File

@ -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;
}
}
}

View File

@ -6,7 +6,14 @@ namespace Milimoe.RainBOT.Settings
{
public static HashSet<string> RepeatIgnore { get; set; } = [];
public static List<long> IgnoreQQGroup { get; set; } = [];
public static List<string> CallBrotherQQIgnore { get; set; } = [];
/// <summary>
/// 这个属性暂时没用到 标记一下
/// </summary>
public static List<long> 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<string>((List<string>)value);
}
if (configs.TryGetValue("IgnoreQQGroup", out value) && value != null)
if (configs.TryGetValue("CallBrotherQQIgnore", out value) && value != null)
{
IgnoreQQGroup = (List<long>)value;
}
CallBrotherQQIgnore = new List<string>((List<string>)value);
}
if (configs.TryGetValue("QQGroupIgnore", out value) && value != null)
{
QQGroupIgnore = (List<long>)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<string> 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);
}
}
}

View File

@ -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";
}