public async Task OnCommandAsync(CommandCalledEventArgs args) { var commandName = args.Context.Message.Content.Split(" ")[0]; var commandArgs = args.Context.Message.Content.Replace($"{commandName}", "").Trim(); if (string.IsNullOrEmpty(commandArgs)) { commandArgs = "None"; } ResultCompletionData data = null; switch (args.Result) { case ActionResult actionRes: { data = await actionRes.ExecuteResultAsync(args.Context); _logger.Debug(LogSource.Volte, $"Executed {args.Context.Command.Name}'s resulting ActionResult."); if (actionRes is BadRequestResult badreq) { await OnBadRequestAsync(new CommandBadRequestEventArgs(badreq, data, args.Context, commandArgs, args.Stopwatch)); return; } break; } case FailedResult failedRes: await OnCommandFailureAsync(new CommandFailedEventArgs(failedRes, args.Context, commandArgs, args.Stopwatch)); return; } if (!Config.LogAllCommands) { return; } Executor.Execute(() => { SuccessfulCommandCalls += 1; var sb = new StringBuilder() .AppendLine($"| -Command from user: {args.Context.User} ({args.Context.User.Id})") //yes, the spaces in front of each string are indeed intentional on all lines after this .AppendLine($" | -Command Issued: {args.Context.Command.Name}") .AppendLine($" | -Args Passed: {commandArgs}".PadLeft(20)) .AppendLine($" | -In Guild: {args.Context.Guild.Name} ({args.Context.Guild.Id})") .AppendLine($" | -In Channel: #{args.Context.Channel.Name} ({args.Context.Channel.Id})") .AppendLine($" | -Time Issued: {args.Context.Now.FormatFullTime()}, {args.Context.Now.FormatDate()}") .AppendLine($" | -Executed: {args.Result.IsSuccessful}") .AppendLine($" | -After: {args.Stopwatch.Elapsed.Humanize()}") .AppendLineIf($" | -Result Message: {data.Message?.Id}", data != null) .Append(" -------------------------------------------------"); _logger.Info(LogSource.Module, sb.ToString()); }); }
public async Task OnCommandAsync(CommandCalledEventArgs args) { ResultCompletionData data; switch (args.Result) { case ActionResult actionRes: { data = await actionRes.ExecuteResultAsync(args.Context); Logger.Debug(LogSource.Service, $"Executed {args.Context.Command.Name}'s resulting {actionRes.GetType().AsPrettyString()}."); if (actionRes is BadRequestResult badreq) { FailedCommandCalls += 1; OnBadRequest(new CommandBadRequestEventArgs(badreq, data, args)); return; } break; } case FailedResult failedRes: { FailedCommandCalls += 1; await OnCommandFailureAsync(new CommandFailedEventArgs(failedRes, args)); return; } default: { Logger.Error(LogSource.Service, $"The command {args.Context.Command.Name} didn't return some form of ActionResult. " + "This is developer error. " + "Please report this to Volte's developers: https://github.com/Ultz/Volte. Thank you!"); return; } } SuccessfulCommandCalls += 1; if (!Config.LogAllCommands) { return; } var sb = new StringBuilder() .AppendLine(CommandFrom(args)) .AppendLine(CommandIssued(args)) .AppendLine(FullMessage(args)) .AppendLine(InGuild(args)) .AppendLine(InChannel(args)) .AppendLine(TimeIssued(args)) .AppendLine(args.ExecutedLogMessage()) .AppendLine(After(args)); if (data != null) { sb.AppendLine(ResultMessage(data)); } sb.Append(Separator); Logger.Info(LogSource.Volte, sb.ToString()); }