Esempio n. 1
0
        private async Task ExecuteCommand(string input, CommandContext context)
        {
            SearchResult searchResult = _commandService.Search(context, input);

            if (!searchResult.IsSuccess)
            {
                return;
            }

            CommandMatch       commandMatch       = searchResult.Commands[0];
            PreconditionResult preconditionResult = await commandMatch.CheckPreconditionsAsync(context, _provider);

            if (!preconditionResult.IsSuccess)
            {
                return;
            }

            ParseResult parseResult =
                await commandMatch.ParseAsync(context, searchResult, preconditionResult, _provider);

            await commandMatch.ExecuteAsync(context, parseResult, _provider);
        }
Esempio n. 2
0
        public async Task HandleErrorAsync(IResult result, ShardedCommandContext context, string parameters,
                                           Server server)
        {
            EmbedBuilder embed = new EmbedBuilder().NormalizeEmbed(ColorType.Normal, _services.GetService <Random>(), server);

            switch (result.Error)
            {
            case CommandError.UnknownCommand:
                break;

            case CommandError.BadArgCount:
            case CommandError.ParseFailed:
                break;

            case CommandError.ObjectNotFound:
                SearchResult searchResult = _commands.Search(context, parameters);
                if (result.Error == CommandError.BadArgCount)
                {
                    CommandMatch       command            = searchResult.Commands.First();
                    PreconditionResult preconditionResult = await command.CheckPreconditionsAsync(context, _services);

                    if (!preconditionResult.IsSuccess && preconditionResult.Error != CommandError.BadArgCount)
                    {
                        embed.WithTitle("Missing Permissions")
                        .WithDescription(preconditionResult.ErrorReason);
                        await context.Channel.SendMessageAsync(embed : embed.Build());

                        break;
                    }
                }

                embed.WithTitle(
                    $"{searchResult.Commands.First().Command.Name.Humanize(LetterCasing.Title)} Command Usage")
                .WithDescription(string.IsNullOrWhiteSpace(searchResult.Commands.First().Command.Module.Group)
                            ? searchResult.Commands.Select(x => x.Command).GetUsage(context).InlineCode()
                            : searchResult.Commands.First().Command.Module.GetUsage(context).InlineCode());
                await context.Channel.SendMessageAsync(embed : embed.Build());

                break;

            case CommandError.MultipleMatches:
                break;

            case CommandError.UnmetPrecondition:
                embed.WithTitle("Unmet Precondition")
                .WithDescription(result.ErrorReason);
                await context.Channel.SendMessageAsync(embed : embed.Build());

                break;

            case CommandError.Unsuccessful:
            case CommandError.Exception:
            case null:
                embed.WithTitle("Internal Error")
                .WithDescription($"Error: {result.ErrorReason}");
                await context.Channel.SendMessageAsync(embed : embed.Build());

                break;

            default:
                break;
            }
        }