Exemplo n.º 1
0
        private async Task CommandExecuted(Discord.Optional <CommandInfo> command, ICommandContext context, IDiscordResult result)
        {
            if (result is DiscordResult commandResult)
            {
                await HandleResult(commandResult.Inner, context);

                return;
            }

            if (!result.IsSuccess)
            {
                if (!command.IsSpecified)
                {
                    await context.Channel.SendMessageAsync($"Unknown command!");
                }
                else if (result is ExecuteResult executeResult && executeResult.Exception != null)
                {
                    Log.Error(executeResult.Exception, "Error while executing {command}", command.Value.Name);
                    SentrySdk.CaptureException(executeResult.Exception);
                    await context.Channel.SendMessageAsync(
                        $"There has been a problem while running this command, sorry :disappointed:"
                        + "\nMy caretaker has been informed and should take a look."
                        + "\nPlease do not delete your message! It can help understanding what went wrong."
                        );
                }
                else
                {
                    await context.Channel.SendMessageAsync($"There has been an error :(\n```{result.Error}```");
                }
            }
Exemplo n.º 2
0
 private async Task _commands_CommandExecuted(Discord.Optional <CommandInfo> arg1, ICommandContext arg2, IResult arg3)
 {
     if (!arg3.IsSuccess)
     {
         Console.WriteLine("COMMAND: " + arg3.ErrorReason);
     }
 }
Exemplo n.º 3
0
        private async Task CommandExecutedAsync(Discord.Optional <CommandInfo> command, ICommandContext context, IResult result)
        {
            if (!command.IsSpecified)
            {
                return;
            }

            if (!result.IsSuccess && result.Error != null)
            {
                switch (result.Error.Value)
                {
                case CommandError.UnmetPrecondition:
                case CommandError.ParseFailed:
                case CommandError.Unsuccessful:
                    await context.Channel.SendMessageAsync(result.ErrorReason.PreventMassTags());

                    break;

                case CommandError.BadArgCount:
                    await SendCommandHelp(context, 1);

                    break;
                }
            }

            LogCommand(command, context);
        }
Exemplo n.º 4
0
 private async Task CommandExecutedAsync(Discord.Optional <CommandInfo> commandInfo, ICommandContext context, IResult result)
 {
     if (!result.IsSuccess)
     {
         if (result.Error != CommandError.UnknownCommand)
         {
             await context.Channel.SendMessageAsync(
                 $"{context.User.Mention}, command failed.\n{result.ErrorReason}");
         }
     }
 }
Exemplo n.º 5
0
        private void LogCommand(Discord.Optional <CommandInfo> command, ICommandContext context)
        {
            var cmd = command.Value;

            var guild       = context.Guild == null ? "NoGuild" : $"{context.Guild.Name} ({context.Guild.Id})";
            var channel     = context.Channel == null ? "NoChannel" : $"#{context.Channel.Name} ({context.Channel.Id})";
            var args        = $"{guild}, {channel}, @{context.User}, ({context.Message.Content})";
            var commandName = $"{cmd.Module.Group} {cmd.Name}".Trim();

            Logger.LogInformation("Executed {0}.\t{1}", commandName, args);
            InternalStatistics.IncrementCommand(commandName);

            if (context.Guild != null)
            {
                using var scope            = Services.CreateScope();
                using var configRepository = scope.ServiceProvider.GetService <ConfigRepository>();
                configRepository.IncrementUsageCounter(context.Guild, cmd.Module.Group, cmd.Name);
            }
        }
Exemplo n.º 6
0
 public async static Task OnExecutedCommand(Discord.Optional <CommandInfo> arg1, ICommandContext arg2, IResult arg3)
 {
     //throw new NotImplementedException();
 }