/// <summary> /// 获取关键词模式匹配指令类型 /// </summary> /// <param name="rawString">消息字符串</param> /// <param name="commandType">触发类型</param> /// <returns>匹配是否成功</returns> public static bool GetKeywordType(string rawString, out KeywordCommand commandType) { IEnumerable <KeywordCommand> matchResult = KeywordList.Where(regexList => regexList.Value.Any(regex => regex.IsMatch(rawString))) .Select(regexList => regexList.Key) .ToList(); if (!matchResult.Any()) { commandType = (KeywordCommand)(-1); return(false); } else { commandType = matchResult.First(); return(true); } }
public async ValueTask LianHandle(object sender, GroupMessageEventArgs e, KeywordCommand command) { if (e == null || sender == null) { return; } Config config = new(e.LoginUid); config.LoadUserConfig(out UserConfig userConfig); //var _lianService = new DealInstruction(userConfig); //判断指令类型并分发 if (command is KeywordCommand keywordCmdType) { switch (keywordCmdType) { case KeywordCommand.Sign: if (IsTrigger(e.Message.RawText, KeywordCommand.Sign.GetDescription())) { await _lianService.SignIn(e, userConfig); } break; case KeywordCommand.Search: if (IsTrigger(e.Message.RawText, KeywordCommand.Search.GetDescription())) { await _lianService.SearchRank(e, userConfig); } break; case KeywordCommand.Fenlai: await _lianService.Fenlai(e, userConfig); break; case KeywordCommand.Skill: await _lianService.Skill(e, userConfig); break; case KeywordCommand.RankList: if (IsTrigger(e.Message.RawText, KeywordCommand.RankList.GetDescription())) { await _lianService.RankList(e); } break; case KeywordCommand.SpecialEvent: if (IsTrigger(e.Message.RawText, KeywordCommand.SpecialEvent.GetDescription())) { await _lianService.SpecialEvent(e); } break; case KeywordCommand.LogsRecord: await _lianService.LogsRecord(e); break; case KeywordCommand.Giving: await _lianService.Giving(e); break; case KeywordCommand.Morning: if (IsTrigger(e.Message.RawText, KeywordCommand.Morning.GetDescription())) { await _lianService.Morning(e, userConfig); } break; case KeywordCommand.Night: if (IsTrigger(e.Message.RawText, KeywordCommand.Night.GetDescription())) { await _lianService.Night(e, userConfig); } break; case KeywordCommand.BonusPoint: await _lianService.BonusPoint(e, userConfig); break; case KeywordCommand.DeductPoint: await _lianService.DeductPoint(e, userConfig); break; case KeywordCommand.AllBonusPoint: await _lianService.AllBonusPoint(e, userConfig); break; case KeywordCommand.AllDeductPoint: await _lianService.AllDeductPoint(e, userConfig); break; case KeywordCommand.RedTea: await _lianService.RedTea(e); break; case KeywordCommand.Raffle: await _lianService.Raffle(e, userConfig); break; case KeywordCommand.Rob: await _lianService.Rob(e, userConfig); break; case KeywordCommand.Rescur: await _lianService.Rescur(e, userConfig); break; case KeywordCommand.Lian: if (IsTrigger(e.Message.RawText, KeywordCommand.Lian.GetDescription())) { await _lianService.Lian(e); } break; case KeywordCommand.AddKeys: await _lianService.AddKeys(e); break; case KeywordCommand.AddThesaurus: await _lianService.AddThesaurus(e); break; case KeywordCommand.RollDice: await _lianService.RollDice(e); break; case KeywordCommand.WordCloud: if (IsTrigger(e.Message.RawText, KeywordCommand.WordCloud.GetDescription())) { await _lianService.WordCloud(e); } break; case KeywordCommand.NonsenseKing: if (IsTrigger(e.Message.RawText, KeywordCommand.NonsenseKing.GetDescription())) { await _lianService.NonsenseKing(e); } break; } } }