From 5a4f31550e7460f590f95f0de56e0ebf1bd1b3d5 Mon Sep 17 00:00:00 2001 From: milimoe Date: Thu, 21 Mar 2024 00:01:40 +0800 Subject: [PATCH] new --- src/Command/MasterCommand.cs | 14 +++ src/ListeningTask/GroupBanTask.cs | 13 +-- src/ListeningTask/GroupMessageTask.cs | 124 ++++++++++++++++++++------ src/Settings/Bot.cs | 28 +++++- src/Settings/GeneralSettings.cs | 7 ++ src/Settings/Music.cs | 8 ++ 6 files changed, 156 insertions(+), 38 deletions(-) diff --git a/src/Command/MasterCommand.cs b/src/Command/MasterCommand.cs index cc35644..760339c 100644 --- a/src/Command/MasterCommand.cs +++ b/src/Command/MasterCommand.cs @@ -275,6 +275,20 @@ namespace Milimoe.RainBOT.Command } } break; + case "osmcoregroup": + if (args.Length > 1 && long.TryParse(args[1].Trim(), out long osmcoregroup_id)) + { + string args0 = args[0].ToString().Trim(); + if (args0 == "add" || args0 == "remove" || args0 == "+" || args0 == "-") + { + isadd = args0 == "add" || args0 == "+"; + if (isadd) GeneralSettings.OSMCoreGroup.Add(osmcoregroup_id); + else GeneralSettings.OSMCoreGroup.Remove(osmcoregroup_id); + msg = AddRemoveAccessGroupMember("OSM核心启用群聊", isadd, osmcoregroup_id); + return msg; + } + } + break; } return "OSM Core:指令格式不正确或传入的参数不支持。\r\n格式:.osm [part] [args...]"; } diff --git a/src/ListeningTask/GroupBanTask.cs b/src/ListeningTask/GroupBanTask.cs index fed7163..41364a5 100644 --- a/src/ListeningTask/GroupBanTask.cs +++ b/src/ListeningTask/GroupBanTask.cs @@ -1,4 +1,5 @@ -using Milimoe.OneBot.Framework; +using System.Reflection; +using Milimoe.OneBot.Framework; using Milimoe.OneBot.Model.Content; using Milimoe.OneBot.Model.Event; using Milimoe.OneBot.Model.Other; @@ -27,14 +28,8 @@ namespace Milimoe.RainBOT.ListeningTask SetGroupBanContent content_unmute_master = new(e.group_id, GeneralSettings.Master, 0); SetGroupBanContent content_mute_operator = new(e.group_id, e.operator_id, 60); await GroupMessageTask.Post(SupportedAPI.set_group_ban, e.group_id, "反制禁言", [content_unmute_master, content_mute_operator]); - if (Bot.GroupMembers.TryGetValue(e.group_id, out List? list) && list != null) - { - Member? sender = list.Where(m => m.user_id == e.operator_id).FirstOrDefault(); - if (sender != null) - { - await e.SendMessage($"检测到主人被{sender.user_id}({(sender.card != "" ? sender.card : sender.nickname)})禁言!"); - } - } + Member sender = Bot.GetMember(e.group_id, e.operator_id); + await e.SendMessage($"检测到主人被{sender.user_id}({(sender.card != "" ? sender.card : sender.nickname)})禁言!"); } else if (e.sub_type == "ban" && e.duration > 0) { diff --git a/src/ListeningTask/GroupMessageTask.cs b/src/ListeningTask/GroupMessageTask.cs index 5aea4d0..a3169f1 100644 --- a/src/ListeningTask/GroupMessageTask.cs +++ b/src/ListeningTask/GroupMessageTask.cs @@ -36,40 +36,49 @@ namespace Milimoe.RainBOT.ListeningTask Console.ForegroundColor = ConsoleColor.Gray; } - MuteRecall.Muted[e.group_id].Remove(e.user_id); + if (MuteRecall.Muted.TryGetValue(e.group_id, out Dictionary? mute_group) && mute_group != null) mute_group.Remove(e.user_id); + bool onOSMCore = GeneralSettings.OSMCoreGroup.Contains(e.group_id); // OSM指令 if (e.detail.Length >= 4 && e.detail[..4] == ".osm") { if (GeneralSettings.IsRun && e.detail.Contains(".osm info")) { // OSM核心状态 - string msg = "OSM插件运行状态:" + "\r\n本群已启用OSM核心"; - if (GeneralSettings.IsRepeat) + string msg = "OSM插件运行状态:"; + if (onOSMCore) { - msg += "\r\n随机复读:开启"; - msg += $"\r\n随机复读概率:{GeneralSettings.PRepeat}%" + - $"\r\n随机复读延迟区间:{GeneralSettings.RepeatDelay[0]}至{GeneralSettings.RepeatDelay[1]}秒"; + msg += "\r\n本群已启用OSM核心"; + if (GeneralSettings.IsRepeat) + { + msg += "\r\n随机复读:开启"; + msg += $"\r\n随机复读概率:{GeneralSettings.PRepeat}%" + + $"\r\n随机复读延迟区间:{GeneralSettings.RepeatDelay[0]}至{GeneralSettings.RepeatDelay[1]}秒"; + } + else msg += "\r\n随机复读:关闭"; + if (GeneralSettings.IsOSM) + { + msg += "\r\n随机OSM:开启"; + msg += $"\r\n随机OSM概率:{GeneralSettings.POSM}%"; + } + else msg += "\r\n随机OSM:关闭"; + if (GeneralSettings.IsSayNo) + { + msg += "\r\n随机反驳不:开启"; + msg += $"\r\n随机反驳不概率:{GeneralSettings.PSayNo}%"; + } + else msg += "\r\n随机反驳不:关闭"; + if (GeneralSettings.IsMute) + { + msg += "\r\n禁言抽奖:开启"; + msg += $"\r\n禁言抽奖时长区间:{GeneralSettings.MuteTime[0]}至{GeneralSettings.MuteTime[1]}秒"; + } + else msg += "\r\n禁言抽奖:关闭"; } - else msg += "\r\n随机复读:关闭"; - if (GeneralSettings.IsOSM) + else { - msg += "\r\n随机OSM:开启"; - msg += $"\r\n随机OSM概率:{GeneralSettings.POSM}%"; + msg += "\r\n本群未启用OSM核心"; } - else msg += "\r\n随机OSM:关闭"; - if (GeneralSettings.IsSayNo) - { - msg += "\r\n随机反驳不:开启"; - msg += $"\r\n随机反驳不概率:{GeneralSettings.PSayNo}%"; - } - else msg += "\r\n随机反驳不:关闭"; - if (GeneralSettings.IsMute) - { - msg += "\r\n禁言抽奖:开启"; - msg += $"\r\n禁言抽奖时长区间:{GeneralSettings.MuteTime[0]}至{GeneralSettings.MuteTime[1]}秒"; - } - else msg += "\r\n禁言抽奖:关闭"; _ = Post(e, "OSM状态", msg); } else if (GeneralSettings.IsRun && e.detail.Contains(".osm stop")) @@ -226,6 +235,7 @@ namespace Milimoe.RainBOT.ListeningTask if (int.TryParse(reply.data.id, out int id)) { TaskUtility.NewTask(async () => await Post(SupportedAPI.delete_msg, e.group_id, "撤回", new DeleteMsgContent(id))); + TaskUtility.NewTask(async () => await Post(SupportedAPI.delete_msg, e.group_id, "撤回", new DeleteMsgContent(e.real_id))); return; } } @@ -366,6 +376,61 @@ namespace Milimoe.RainBOT.ListeningTask }); return; } + if (e.detail.Contains("马云", StringComparison.CurrentCultureIgnoreCase)) + { + TaskUtility.NewTask(async () => + { + if (!await CheckBlackList(e)) return; + GroupMessageContent content = new(e.group_id); + content.message.Add(new RecordMessage(Music.MusicList["马云"])); + await Post(e, "Record", content); + }); + return; + } + if (e.detail.Contains("电锯", StringComparison.CurrentCultureIgnoreCase)) + { + TaskUtility.NewTask(async () => + { + if (!await CheckBlackList(e)) return; + GroupMessageContent content = new(e.group_id); + content.message.Add(new RecordMessage(Music.MusicList["电锯"])); + await Post(e, "Record", content); + }); + return; + } + if (e.detail.Contains("疤王", StringComparison.CurrentCultureIgnoreCase)) + { + TaskUtility.NewTask(async () => + { + if (!await CheckBlackList(e)) return; + GroupMessageContent content = new(e.group_id); + content.message.Add(new RecordMessage(Music.MusicList["疤王"])); + await Post(e, "Record", content); + }); + return; + } + if (e.detail.Contains("终极", StringComparison.CurrentCultureIgnoreCase)) + { + TaskUtility.NewTask(async () => + { + if (!await CheckBlackList(e)) return; + GroupMessageContent content = new(e.group_id); + content.message.Add(new RecordMessage(Music.MusicList["终极"])); + await Post(e, "Record", content); + }); + return; + } + if (e.detail.Contains("音乐", StringComparison.CurrentCultureIgnoreCase)) + { + TaskUtility.NewTask(async () => + { + if (!await CheckBlackList(e)) return; + GroupMessageContent content = new(e.group_id); + content.message.Add(new RecordMessage(Music.MusicList[Music.MusicList.Keys.ToArray()[new Random().Next(Music.MusicList.Count)]])); + await Post(e, "Record", content); + }); + return; + } // 我的运势 if (e.detail == "我的运势") @@ -452,7 +517,7 @@ namespace Milimoe.RainBOT.ListeningTask if (Daily.UserDailys.TryGetValue(qq, out string? daily) && daily != null) { GroupMessageContent content = new(e.group_id); - content.message.Add(new TextMessage(qq + "的今日运势是:\r\n" + daily)); + content.message.Add(new TextMessage(qq + "(" + Bot.GetMemberNickName(e.group_id, e.user_id) + ")的今日运势是:\r\n" + daily)); await Post(e, "查看运势", content); } else @@ -465,6 +530,9 @@ namespace Milimoe.RainBOT.ListeningTask return; } + // 下面是开启了OSM Core的群组才能使用的功能 + if (!onOSMCore) return; + // 禁言抽奖 if (GeneralSettings.IsMute && e.detail == "禁言抽奖" && !MuteRecall.WillMute.ContainsKey(e.user_id)) { @@ -636,7 +704,7 @@ namespace Milimoe.RainBOT.ListeningTask else if (e.detail.Contains("可以") && !e.detail.Contains('不') && e.CheckThrow(GeneralSettings.PSayNo, out dice)) { ColorfulCheckPass(sender, "随机反驳不", dice, GeneralSettings.PSayNo); - if (dice < 20) + if (dice < (GeneralSettings.PSayNo / 2)) { _ = Post(e, "随机反驳不", "可以"); } @@ -645,10 +713,10 @@ namespace Milimoe.RainBOT.ListeningTask _ = Post(e, "随机反驳不", "不可以"); } } - else if (e.detail.Contains('能') && !e.detail.Contains('不') && !e.detail.Contains('可') && e.CheckThrow(GeneralSettings.PSayNo, out dice)) + else if (e.detail.Contains('能') && !e.detail.Contains('不') && !e.detail.Contains('技') && !e.detail.Contains('可') && e.CheckThrow(GeneralSettings.PSayNo, out dice)) { ColorfulCheckPass(sender, "随机反驳不", dice, GeneralSettings.PSayNo); - if (dice < 20) + if (dice < (GeneralSettings.PSayNo / 2)) { _ = Post(e, "随机反驳不", "能"); } @@ -660,7 +728,7 @@ namespace Milimoe.RainBOT.ListeningTask else if (e.detail.Contains("可能") && !e.detail.Contains('不') && e.CheckThrow(GeneralSettings.PSayNo, out dice)) { ColorfulCheckPass(sender, "随机反驳不", dice, GeneralSettings.PSayNo); - if (dice < 20) + if (dice < (GeneralSettings.PSayNo / 2)) { _ = Post(e, "随机反驳不", "可能"); } diff --git a/src/Settings/Bot.cs b/src/Settings/Bot.cs index 35ea80a..7e3b62c 100644 --- a/src/Settings/Bot.cs +++ b/src/Settings/Bot.cs @@ -1,4 +1,5 @@ -using System.Text.Json; +using System.Reflection; +using System.Text.Json; using Milimoe.OneBot.Framework; using Milimoe.OneBot.Framework.Utility; using Milimoe.OneBot.Model.Content; @@ -55,5 +56,30 @@ namespace Milimoe.RainBOT.Settings } } } + + public static Member GetMember(long group_id, long user_id) + { + if (GroupMembers.TryGetValue(group_id, out List? members) && members != null) + { + Member? member = members.Where(m => m.user_id == user_id).FirstOrDefault(); + if (member != null) + { + return member; + } + } + return new(); + } + + public static string GetMemberNickName(long group_id, long user_id) + { + Member member = GetMember(group_id, user_id); + if (member.user_id != 0) return member.card != "" ? member.card : member.nickname; + return ""; + } + + public static string GetMemberNickName(Member member) + { + return member.card != "" ? member.card : member.nickname; + } } } diff --git a/src/Settings/GeneralSettings.cs b/src/Settings/GeneralSettings.cs index d2bcd17..a7dea0d 100644 --- a/src/Settings/GeneralSettings.cs +++ b/src/Settings/GeneralSettings.cs @@ -48,6 +48,8 @@ namespace Milimoe.RainBOT.Settings public static List RecallAccessGroup { get; set; } = []; + public static List OSMCoreGroup { get; set; } = []; + public static PluginConfig Configs { get; set; } = new("rainbot", "config"); public static void LoadSetting() @@ -138,6 +140,10 @@ namespace Milimoe.RainBOT.Settings { RecallAccessGroup = (List)value; } + if (configs.TryGetValue("OSMCoreGroup", out value) && value != null) + { + OSMCoreGroup = (List)value; + } } public static void SaveConfig() @@ -162,6 +168,7 @@ namespace Milimoe.RainBOT.Settings Configs.Add("MuteAccessGroup", MuteAccessGroup); Configs.Add("UnMuteAccessGroup", UnMuteAccessGroup); Configs.Add("RecallAccessGroup", RecallAccessGroup); + Configs.Add("OSMCoreGroup", OSMCoreGroup); Configs.Save(); } } diff --git a/src/Settings/Music.cs b/src/Settings/Music.cs index 4c89e69..d76acf8 100644 --- a/src/Settings/Music.cs +++ b/src/Settings/Music.cs @@ -8,6 +8,10 @@ /// 懂CSGO /// 令人沮丧的游戏 /// man + /// 马云 + /// 疤王 + /// 电锯/追命 + /// 终极 /// public static Dictionary MusicList { get; set; } = []; @@ -17,6 +21,10 @@ MusicList.Add("懂CSGO", "file:///" + AppDomain.CurrentDomain.BaseDirectory.ToString() + @"music\懂CSGO.mp3"); MusicList.Add("令人沮丧的游戏", "file:///" + AppDomain.CurrentDomain.BaseDirectory.ToString() + @"music\令人沮丧的游戏.mp3"); MusicList.Add("man", "file:///" + AppDomain.CurrentDomain.BaseDirectory.ToString() + @"music\man.mp3"); + MusicList.Add("马云", "file:///" + AppDomain.CurrentDomain.BaseDirectory.ToString() + @"music\马云.mp3"); + MusicList.Add("疤王", "file:///" + AppDomain.CurrentDomain.BaseDirectory.ToString() + @"music\疤王.mp3"); + MusicList.Add("电锯", "file:///" + AppDomain.CurrentDomain.BaseDirectory.ToString() + @"music\电锯.mp3"); + MusicList.Add("终极", "file:///" + AppDomain.CurrentDomain.BaseDirectory.ToString() + @"music\终极.mp3"); } } }