示例#1
0
        /// <summary>
        /// 收到信息的函数
        /// 并匹配相应指令
        /// </summary>
        public async void GetChat(RegexCommand cmdType)
        {
            if (PCREventArgs == null || Sender == null)
            {
                return;
            }
            switch (cmdType)
            {
            //查询公会排名
            case RegexCommand.GetGuildRank:
                //以群名为查询名
                if (PCREventArgs.Message.RawText.Length <= 6)
                {
                    var groupInfo = await QQGroup.GetGroupInfo();

                    if (groupInfo.apiStatus != APIStatusType.OK)
                    {
                        await QQGroup.SendGroupMessage("调用onebot API时发生错误");

                        Log.Error("api error", $"调用onebot API时发生错误 Status={groupInfo.apiStatus}");
                        return;
                    }

                    await KyoukaRank(DBHelper.GetGuildName(PCREventArgs.SourceGroup));
                }
                else     //手动指定
                {
                    await KyoukaRank(PCREventArgs.Message.RawText.Substring(6));
                }

                break;
            }
        }
示例#2
0
        /// <summary>
        /// 获取正则模式匹配指令类型
        /// </summary>
        /// <param name="rawString">消息字符串</param>
        /// <param name="commandType">触发类型</param>
        /// <returns>匹配是否成功</returns>
        public static bool GetRegexType(string rawString, out RegexCommand commandType)
        {
            IEnumerable <RegexCommand> matchResult = RegexList.Where(regexList => regexList.Value.Any(regex => regex.IsMatch(rawString)))
                                                     .Select(regexList => regexList.Key)
                                                     .ToList();

            if (!matchResult.Any())
            {
                commandType = (RegexCommand)(-1);
                return(false);
            }
            else
            {
                commandType = matchResult.First();
                return(true);
            }
        }
示例#3
0
        /// <summary>
        /// 获取到群消息
        /// </summary>
        public void GetChat(RegexCommand cmdType)
        {
            if (CheruEventArgs == null || Sender == null)
            {
                return;
            }
            //检查参数
            switch (cmdType)
            {
            case RegexCommand.CheruDecode:
                if (CheruEventArgs.Message.RawText.Length > 3)
                {
                    CheruToString(CheruEventArgs.Message.RawText.Substring(3));
                }
                break;

            case RegexCommand.CheruEncode:
                if (CheruEventArgs.Message.RawText.Length > 4)
                {
                    StringToCheru(CheruEventArgs.Message.RawText.Substring(4));
                }
                break;
            }
        }