public async Task HandleMessageAsync(DepressedBotContext ctx)
        {
            var confessional = ctx.Client.GetGuild(385902350432206849)
                               .GetTextChannel(726990911082594344);

            if (ctx.Message.Content.StartsWith($"{Config.CommandPrefix}confess"))
            {
                var confession = ctx.Message.Content.Replace($"{Config.CommandPrefix}confess", "",
                                                             StringComparison.OrdinalIgnoreCase);
                if (confession.IsNullOrEmpty())
                {
                    await ctx.Message.Channel.SendMessageAsync("You didn't confess anything.");

                    return;
                }
                if (ctx.Channel is null)
                {
                    var m = await confessional.SendMessageAsync(embed : new EmbedBuilder()
                                                                .WithAuthor(x =>
                    {
                        x.IconUrl = confessional.Guild.IconUrl;
                        x.Name = "DepressedBot Confessional";
                    })
                                                                .WithColor(Config.SuccessColor)
                                                                .WithDescription(confession)
                                                                .WithCurrentTimestamp()
                                                                .Build());

                    await ctx.Message.Channel.SendMessageAsync(embed : new EmbedBuilder()
                                                               .WithDescription($"[Confession Accepted]({m.GetJumpUrl()})").Build());
                }
                else
                {
                    await ctx.Message.Channel.SendMessageAsync("You must send that command in my DM so it stays classified.");
                }
            }
        }
示例#2
0
        private async Task OnCommandFailureAsync(Command c, FailedResult res, DepressedBotContext ctx, string args,
                                                 Stopwatch sw)
        {
            var    embed = new EmbedBuilder();
            string reason;

            switch (res)
            {
            case CommandNotFoundResult _:
                reason = "Unknown command.";
                break;

            case ExecutionFailedResult efr:
                reason = $"Execution of this command failed.\nFull error message: {efr.Exception.Message}";
                await _logger.Log(LogSeverity.Error, LogSource.Module, string.Empty, efr.Exception);

                break;

            case ChecksFailedResult _:
                reason = "Insufficient permission.";
                break;

            case ParameterChecksFailedResult pcfr:
                reason = $"Checks failed on parameter *{pcfr.Parameter.Name}**.";
                break;

            case ArgumentParseFailedResult apfr:
                reason = $"Parsing for arguments failed on argument **{apfr.Parameter?.Name}**.";
                break;

            case TypeParseFailedResult tpfr:
                reason =
                    $"Failed to parse type **{tpfr.Parameter.Type.FullName}** from parameter **{tpfr.Parameter.Name}**.";
                break;

            default:
                reason = "Unknown error.";
                break;
            }

            if (reason != "Insufficient permission." && reason != "Unknown command.")
            {
                await embed.AddField("Error in Command:", c.Name)
                .AddField("Error Reason:", reason)
                .AddField("Correct Usage", c.SanitizeUsage())
                .WithAuthor(ctx.User)
                .WithErrorColor()
                .SendToAsync(ctx.Channel);

                if (!Config.LogAllCommands)
                {
                    return;
                }

                await _logger.Log(LogSeverity.Error, LogSource.Module,
                                  $"|  -Command from user: {ctx.User.Username}#{ctx.User.Discriminator} ({ctx.User.Id})");

                await _logger.Log(LogSeverity.Error, LogSource.Module,
                                  $"|     -Command Issued: {c.Name}");

                await _logger.Log(LogSeverity.Error, LogSource.Module,
                                  $"|        -Args Passed: {args.Trim()}");

                await _logger.Log(LogSeverity.Error, LogSource.Module,
                                  $"|           -In Guild: {ctx.Guild.Name} ({ctx.Guild.Id})");

                await _logger.Log(LogSeverity.Error, LogSource.Module,
                                  $"|         -In Channel: #{ctx.Channel.Name} ({ctx.Channel.Id})");

                await _logger.Log(LogSeverity.Error, LogSource.Module,
                                  $"|        -Time Issued: {DateTime.Now}");

                await _logger.Log(LogSeverity.Error, LogSource.Module,
                                  $"|           -Executed: {res.IsSuccessful} | Reason: {reason}");

                await _logger.Log(LogSeverity.Error, LogSource.Module,
                                  $"|              -After: {sw.Elapsed.Humanize()}");

                await _logger.Log(LogSeverity.Error, LogSource.Module,
                                  "-------------------------------------------------");
            }
        }
示例#3
0
 public MessageReceivedEventArgs(SocketUserMessage s)
 {
     Message = s;
     Context = new DepressedBotContext(Discord.DepressedBot.Client, Message, Discord.DepressedBot.ServiceProvider);
 }