示例#1
0
        /// <summary>
        /// 群聊处理和事件触发分发
        /// </summary>
        public static async ValueTask GroupMessageParse(object sender, GroupMessageEventArgs groupMessage)
        {
            //配置文件实例
            Config config = new Config(groupMessage.LoginUid);

            //读取配置文件
            if (!config.LoadUserConfig(out UserConfig userConfig))
            {
                await groupMessage.SourceGroup.SendGroupMessage("读取配置文件(User)时发生错误\r\n请联系机器人管理员");

                ConsoleLog.Error("AntiRain会战管理", "无法读取用户配置文件");
                return;
            }
            //指令匹配
            //#开头的指令(会战) -> 关键词 -> 正则
            //会战管理
            if (Command.GetPCRGuildBattlecmdType(groupMessage.Message.RawText, out PCRGuildBattleCommand battleCommand))
            {
                ConsoleLog.Info("PCR会战管理", $"获取到指令[{battleCommand}]");
                //判断模块使能
                if (userConfig.ModuleSwitch.PCR_GuildManager)
                {
                    PcrGuildBattleChatHandle chatHandle = new PcrGuildBattleChatHandle(sender, groupMessage, battleCommand);
                    chatHandle.GetChat();
                }
                else
                {
                    ConsoleLog.Warning("AntiRain会战管理", "会战功能未开启");
                }
            }

            //聊天关键词
            if (Command.GetKeywordType(groupMessage.Message.RawText, out KeywordCommand keywordCommand))
            {
                ConsoleLog.Info("关键词触发", $"触发关键词[{keywordCommand}]");
                switch (keywordCommand)
                {
                case KeywordCommand.Hso:
                    if (userConfig.ModuleSwitch.Hso)
                    {
                        HsoHandle hso = new HsoHandle(sender, groupMessage);
                        hso.GetChat();
                    }
                    break;

                //将其他的的全部交给娱乐模块处理
                default:
                    if (userConfig.ModuleSwitch.HaveFun)
                    {
                        Surprise surprise = new Surprise(sender, groupMessage);
                        surprise.GetChat(keywordCommand);
                    }
                    break;
                }
            }

            //正则匹配
            if (Command.GetRegexType(groupMessage.Message.RawText, out RegexCommand regexCommand))
            {
                ConsoleLog.Info("正则触发", $"触发正则匹配[{regexCommand}]");
                switch (regexCommand)
                {
                case RegexCommand.CheruDecode:
                case RegexCommand.CheruEncode:
                    //判断模块使能
                    if (userConfig.ModuleSwitch.Cheru)
                    {
                        CheruHandle cheru = new CheruHandle(sender, groupMessage);
                        cheru.GetChat(regexCommand);
                    }
                    break;

                case RegexCommand.GetGuildRank:
                    //判断模块使能
                    if (userConfig.ModuleSwitch.PCR_GuildRank)
                    {
                        GuildRankHandle guildRank = new GuildRankHandle(sender, groupMessage);
                        guildRank.GetChat(regexCommand);
                    }
                    break;

                //调试
                case RegexCommand.Debug:
                    if (groupMessage.SenderInfo.Role == MemberRoleType.Member)
                    {
                        ConsoleLog.Warning("Auth Warning", $"成员[{groupMessage.Sender.Id}]正尝试执行调试指令");
                    }
                    else
                    {
                    }
                    break;

                //将其他的的全部交给娱乐模块处理
                default:
                    if (userConfig.ModuleSwitch.HaveFun)
                    {
                        Surprise surprise = new Surprise(sender, groupMessage);
                        surprise.GetChat(regexCommand);
                    }
                    break;
                }
            }
        }
示例#2
0
        /// <summary>
        /// 群聊处理和事件触发分发
        /// </summary>
        public static async ValueTask GroupMessageParse(object sender, GroupMessageEventArgs groupMessage)
        {
            //配置文件实例
            ConfigManager configManager = new ConfigManager(groupMessage.LoginUid);

            //读取配置文件
            if (!configManager.LoadUserConfig(out UserConfig userConfig))
            {
                await groupMessage.SourceGroup.SendGroupMessage("读取配置文件(User)时发生错误\r\n请联系机器人管理员");

                Log.Error("AntiRain会战管理", "无法读取用户配置文件");
                return;
            }

            //指令匹配
            //#开头的指令(会战) -> 关键词 -> 正则
            //会战管理
            if (CommandAdapter.GetPCRGuildBattlecmdType(groupMessage.Message.RawText,
                                                        out PCRGuildBattleCommand battleCommand))
            {
                Log.Info("PCR会战管理", $"获取到指令[{battleCommand}]");
                //判断模块使能
                if (userConfig.ModuleSwitch.PCR_GuildManager)
                {
                    PcrGuildBattleChatHandle chatHandle =
                        new PcrGuildBattleChatHandle(sender, groupMessage, battleCommand);
                    chatHandle.GetChat();
                }
                else
                {
                    Log.Warning("AntiRain会战管理", "会战功能未开启");
                }
            }

            //聊天关键词
            if (CommandAdapter.GetKeywordType(groupMessage.Message.RawText, out KeywordCommand keywordCommand))
            {
                Log.Info("关键词触发", $"触发关键词[{keywordCommand}]");
                switch (keywordCommand)
                {
                case KeywordCommand.Hso:
                    if (userConfig.ModuleSwitch.Hso)
                    {
                        HsoHandle hso = new HsoHandle(sender, groupMessage);
                        hso.GetChat();
                    }

                    break;

                //将其他的的全部交给娱乐模块处理
                default:
                    if (userConfig.ModuleSwitch.HaveFun)
                    {
                        Surprise surprise = new Surprise(sender, groupMessage);
                        surprise.GetChat(keywordCommand);
                    }

                    break;
                }
            }

            //正则匹配
            if (CommandAdapter.GetRegexType(groupMessage.Message.RawText, out RegexCommand regexCommand))
            {
                Log.Info("正则触发", $"触发正则匹配[{regexCommand}]");
                switch (regexCommand)
                {
                case RegexCommand.CheruDecode:
                case RegexCommand.CheruEncode:
                    //判断模块使能
                    if (userConfig.ModuleSwitch.Cheru)
                    {
                        CheruHandle cheru = new CheruHandle(sender, groupMessage);
                        cheru.GetChat(regexCommand);
                    }

                    break;

                case RegexCommand.GetGuildRank:
                    //判断模块使能
                    if (userConfig.ModuleSwitch.PCR_GuildRank)
                    {
                        GuildRankHandle guildRank = new GuildRankHandle(sender, groupMessage);
                        guildRank.GetChat(regexCommand);
                    }

                    break;

                //调试
                case RegexCommand.Debug:
                    if (groupMessage.SenderInfo.Role == MemberRoleType.Member)
                    {
                        Log.Warning("Auth Warning", $"成员[{groupMessage.Sender.Id}]正尝试执行调试指令");
                    }
                    else
                    {
                        // if (groupMessage.Message.RawText.Length <= 5) return;
                        // string para =
                        //     groupMessage.Message.RawText.Substring(5, groupMessage.Message.RawText.Length - 5);
                        // if (int.TryParse(para, out int id))
                        // {
                        //     CharaParser charaParser = new CharaParser();
                        //     List<CQCode> message = new List<CQCode>();
                        //     message.Add(CQCode.CQText(id.ToString()));
                        //     message.Add(CQCode.CQText(charaParser.FindChara(id)?.GetCharaNameCN() ?? string.Empty));
                        //     message.Add(CQCode.CQImage($"https://redive.estertion.win/icon/unit/{id}31.webp"));
                        //     await groupMessage.SourceGroup.SendGroupMessage(message);
                        // }
                    }

                    break;

                //将其他的的全部交给娱乐模块处理
                default:
                    if (userConfig.ModuleSwitch.HaveFun)
                    {
                        Surprise surprise = new Surprise(sender, groupMessage);
                        surprise.GetChat(regexCommand);
                    }

                    break;
                }
            }
        }
示例#3
0
        /// <summary>
        /// 收到群消息
        /// </summary>
        /// <param name="sender">事件来源</param>
        /// <param name="eventArgs">事件参数</param>
        public static void GroupMessage(object sender, CQGroupMessageEventArgs eventArgs)
        {
            //与MiraiLog信息重复暂不显示
            //ConsoleLog.Info($"收到信息[群:{eventArgs.FromGroup.Id}]",$"{(eventArgs.Message.Text).Replace("\r\n", "\\r\\n")}");
            //读取配置文件
            Config config = new Config(eventArgs.CQApi.GetLoginQQ().Id, false);

            //Module moduleEnable = config.LoadedConfig.ModuleSwitch;

            //以#开头的消息全部交给PCR处理
            if (eventArgs.Message.Text.Trim().StartsWith("#") && //检查指令开头
                config.LoadConfig()                              //加载配置文件
                )
            {
                //检查模块使能
                if (!config.LoadedConfig.ModuleSwitch.PCR_GuildManager)
                {
                    eventArgs.FromGroup.SendGroupMessage("此模块未启用");
                    return;
                }
                PCRGuildHandle pcrGuild = new PCRGuildHandle(sender, eventArgs);
                pcrGuild.GetChat();
                return;
            }

            //全字指令匹配
            WholeMatchCmd.KeyWords.TryGetValue(eventArgs.Message, out WholeMatchCmdType cmdType); //查找关键字
            if (cmdType != 0)
            {
                ConsoleLog.Info("触发关键词", $"消息类型={cmdType}");
                //加载配置文件
                if (!config.LoadConfig())
                {
                    return;
                }
            }
            switch (cmdType)
            {
            //娱乐功能
            case WholeMatchCmdType.SurpriseMFK_Random:
            case WholeMatchCmdType.SurpriseMFK_Ban:
            case WholeMatchCmdType.SurpriseMFK_RedTea:
            case WholeMatchCmdType.SurpriseMFK_24YearsOld:
                if (!config.LoadedConfig.ModuleSwitch.HaveFun)
                {
                    eventArgs.FromGroup.SendGroupMessage("此模块未启用");
                    return;
                }
                SurpriseMFKHandle smfh = new SurpriseMFKHandle(sender, eventArgs);
                smfh.GetChat(cmdType);
                return;

            //慧酱签到啦
            case WholeMatchCmdType.Suisei_SignIn:
                if (!config.LoadedConfig.ModuleSwitch.Suisei)
                {
                    eventArgs.FromGroup.SendGroupMessage("此模块未启用");
                    return;
                }
                SuiseiHanlde suisei = new SuiseiHanlde(sender, eventArgs);
                suisei.GetChat(cmdType);
                return;

            //来点色图!
            case WholeMatchCmdType.Hso:
                if (!config.LoadedConfig.ModuleSwitch.Hso)
                {
                    eventArgs.FromGroup.SendGroupMessage("此模块未启用");
                    return;
                }
                HsoHandle hso = new HsoHandle(sender, eventArgs);
                hso.GetChat(cmdType);
                return;

            //输入debug
            case WholeMatchCmdType.Debug:
                if (!config.LoadedConfig.ModuleSwitch.Debug)
                {
                    eventArgs.FromGroup.SendGroupMessage("此模块未启用");
                    return;
                }
                DefaultHandle dh = new DefaultHandle(sender, eventArgs);
                dh.GetChat();
                return;
            }

            //参数指令匹配
            KeywordCmdType keywordType = KeywordCmd.TryGetKeywordType(eventArgs.Message.Text);

            if (keywordType != 0)
            {
                ConsoleLog.Info("触发关键词", $"消息类型={cmdType}");
                //加载配置文件
                if (!config.LoadConfig())
                {
                    return;
                }
            }
            switch (keywordType)
            {
            case KeywordCmdType.PCRTools_GetGuildRank:
                if (!config.LoadedConfig.ModuleSwitch.PCR_GuildRank)
                {
                    eventArgs.FromGroup.SendGroupMessage("此模块未启用");
                    return;
                }
                GuildRankHandle pcrTools = new GuildRankHandle(sender, eventArgs);
                pcrTools.GetChat(keywordType);
                return;

            case KeywordCmdType.At_Bot:
                ConsoleLog.Info("机器人事件", "机器人被AT");
                break;

            case KeywordCmdType.Cheru_Encode:
            case KeywordCmdType.Cheru_Decode:
                if (!config.LoadedConfig.ModuleSwitch.Cheru)
                {
                    eventArgs.FromGroup.SendGroupMessage("此模块未启用");
                    return;
                }
                CheruHandle cheru = new CheruHandle(sender, eventArgs);
                cheru.GetChat(keywordType);
                break;

            case KeywordCmdType.Debug_Echo:
                if (!config.LoadedConfig.ModuleSwitch.Debug)
                {
                    eventArgs.FromGroup.SendGroupMessage("此模块未启用");
                    return;
                }
                DefaultHandle dh = new DefaultHandle(sender, eventArgs);
                dh.GetChat();
                return;
            }

            eventArgs.Handler = true;
        }