示例#1
0
        private bool TestHelpMessage(ISummonable middleware,
                                     IChatServiceConnection chatServiceConnection,
                                     ChatMessageModel message)
        {
            // expect exactly 1 instance of the action verb
            var helpMatchPattern = string.Concat(middleware.GetSummonVerb(), "{1}\\s?help\\s*");
            // match for message format "<bot mention> <verb> *rest of message*" and return *rest of message* to middleware
            Regex testRegex = new Regex(helpMatchPattern, RegexOptions.IgnoreCase);

            Match match = testRegex.Match(message.Body);

            return(match.Success);
        }
示例#2
0
        private string ProcessSummonMessage(ISummonable middleware,
                                            IChatServiceConnection chatServiceConnection,
                                            ChatMessageModel message)
        {
            // expect exactly 1 instance of the action verb
            var verbMatchPattern = string.Concat(middleware.GetSummonVerb(), "{1}\\s?(");
            // match for message format "<bot mention> <verb> *rest of message*" and return *rest of message* to middleware
            var   testPattern = string.Concat(verbMatchPattern, middleware.MentionRegex, ")");
            Regex testRegex   = new Regex(testPattern, RegexOptions.IgnoreCase);

            Match match = testRegex.Match(message.Body);

            if (!match.Success)
            {
                return(null);
            }

            var strippedMessageMatchGroup = match.Groups[1];

            return(strippedMessageMatchGroup.Value == null ? string.Empty
                                                           : strippedMessageMatchGroup.Value);
        }