示例#1
0
        public async Task ProcessCommand(ObsidianContext ctx)
        {
            ctx.Commands = this;

            // split the command message into command and args.
            if (_commandParser.IsCommandQualified(ctx.Message, out string qualified))
            {
                // if string is "command-qualified" we'll try to execute it.
                var command = _commandParser.SplitQualifiedString(qualified); // first, parse the command

                // [0] is the command name, all other values are arguments.
                await executeCommand(command, ctx);
            }
            await Task.Yield();
        }
示例#2
0
        private async Task executeCommand(string[] command, ObsidianContext ctx)
        {
            Command cmd  = null;
            var     args = command;

            // Search for correct Command class in this._commands.
            while (_commands.Any(x => x.CheckCommand(args, cmd)))
            {
                cmd  = _commands.First(x => x.CheckCommand(args, cmd));
                args = args.Skip(1).ToArray();
            }

            if (cmd != null)
            {
                await cmd.ExecuteAsync(ctx, args);
            }
            else
            {
                throw new CommandNotFoundException("No such command was found!");
            }
        }