public static void AppEnable(object sender, CQAppEnableEventArgs e) { try { //打开控制台 //ConsoleLog.AllocConsole(); Console.Title = @"SuiseiBot"; //初始化配置文件 Config config = new Config(e.CQApi.GetLoginQQ().Id); //数据库初始化 ConsoleLog.Info("初始化", "SuiseiBot初始化"); //设置Log等级 ConsoleLog.SetLogLevel(config.LoadedConfig.LogLevel); //读取应用信息 ConsoleLog.Debug("APP AuthCode(native plugin ID)", e.CQApi.AppInfo.AuthCode); //修改环境文件夹,初始化环境 ConsoleLog.Debug("获取到环境路径", Directory.GetCurrentDirectory()); Environment.SetEnvironmentVariable("Path", Directory.GetCurrentDirectory()); //显示Log等级 ConsoleLog.Debug("Log Level", config.LoadedConfig.LogLevel); //在控制台显示启用模块 ConsoleLog.Info("已启用的模块", $"\n{config.LoadedConfig.ModuleSwitch}"); DatabaseInit.Init(e); //将关键词和帮助文本写入内存 WholeMatchCmd.KeywordInit(); PCRGuildCmd.PCRGuildCommandInit(); GuildCommandHelp.InitHelpText(); KeywordCmd.SpecialKeywordsInit(e.CQApi); //初始化定时器线程 if (config.LoadedConfig.ModuleSwitch.Bili_Subscription || config.LoadedConfig.ModuleSwitch.PCR_Subscription) { timer = new TimerInit(e.CQApi, config.LoadedConfig.SubscriptionConfig.FlashTime); } e.Handler = true; } catch (Exception exception) { ConsoleLog.Error("error", ConsoleLog.ErrorLogBuilder(exception)); } }
/// <summary> /// 收到群消息 /// </summary> /// <param name="sender">事件来源</param> /// <param name="e">事件参数</param> public void GroupMessage(object sender, CQGroupMessageEventArgs e) { if (sender == null || e == null) { return; } this.eventArgs = e; ConsoleLog.Info($"收到信息[群:{eventArgs.FromGroup.Id}]", $"{(eventArgs.Message.Text).Replace("\r\n", "\\r\\n")}"); //读取配置文件 ConfigIO config = new ConfigIO(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) { SendDisableMessage(); 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) { //输入debug case WholeMatchCmdType.Debug: if (!config.LoadedConfig.ModuleSwitch.Debug) { SendDisableMessage(); return; } DefaultHandle dh = new DefaultHandle(sender, eventArgs); dh.GetChat(cmdType); return; //娱乐功能 case WholeMatchCmdType.SurpriseMFK_Random: case WholeMatchCmdType.SurpriseMFK_Ban: case WholeMatchCmdType.SurpriseMFK_RedTea: case WholeMatchCmdType.SurpriseMFK_24YearsOld: if (!config.LoadedConfig.ModuleSwitch.HaveFun) { SendDisableMessage(); return; } SurpriseMFKHandle smfh = new SurpriseMFKHandle(sender, eventArgs); smfh.GetChat(cmdType); return; //慧酱签到啦 case WholeMatchCmdType.Suisei_SignIn: if (!config.LoadedConfig.ModuleSwitch.Suisei) { SendDisableMessage(); return; } SuiseiHanlde suisei = new SuiseiHanlde(sender, eventArgs); suisei.GetChat(cmdType); return; //来点色图! case WholeMatchCmdType.Setu: if (!config.LoadedConfig.ModuleSwitch.Setu) { SendDisableMessage(); return; } return; default: break; } //参数指令匹配 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) { SendDisableMessage(); return; } PCRToolsHandle pcrTools = new PCRToolsHandle(sender, eventArgs); pcrTools.GetChat(keywordType); return; case KeywordCmdType.At_Bot: ConsoleLog.Info("机器人事件", "机器人被AT"); break; default: break; } eventArgs.Handler = true; }