Example #1
0
 public void HandleHelp(MessageHandlerArgs msgArgs, string[] helpArgs)
 {
     if (helpArgs.Length == 0)
     {
         msgArgs.Writer.SendMessage(
             this.rootHelpMessage,
             msgArgs.Channel
             );
     }
     else if (helpArgs.Length == 1)
     {
         CommandDefinitionFindResult result = this.cmdDefs.Find(helpArgs[0]);
         if (result == null)
         {
             msgArgs.Writer.SendMessage(
                 $"'{helpArgs[0]}' is not a command I know.  Try the help command with no arguments to see what commands I know.",
                 msgArgs.Channel
                 );
         }
         else
         {
             msgArgs.Writer.SendMessage(
                 result.FoundDefinition.GetFullHelpText(result.CommandPrefix),
                 msgArgs.Channel
                 );
         }
     }
 }
        /// <summary>
        /// Takes in a string to parse.  If the string
        /// matches a regex, the found <see cref="CommandDefinition"/> is returned.
        /// Otherwise, this returns null.
        /// </summary>
        public CommandDefinitionFindResult Find(string command)
        {
            foreach (KeyValuePair <Regex, CommandDefinition> def in this.regexDefs)
            {
                Match match = def.Key.Match(command);
                if (match.Success)
                {
                    CommandDefinitionFindResult result = new CommandDefinitionFindResult
                    {
                        CommandPrefix   = match.Groups["command"].Value,
                        CommandArgs     = match.Groups["args"].Value,
                        FoundDefinition = def.Value
                    };

                    return(result);
                }
            }

            // Couldn't find anything, return null.
            return(null);
        }