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 CommandBadRequestEventArgs(BadRequestResult res, ResultCompletionData data, VolteContext ctx, string args, Stopwatch sw) { Result = res; ResultCompletionData = data; Context = ctx; Arguments = args; Stopwatch = sw; }
public void Add(ulong id, ResultCompletionData data) { _responseCache.Set(id, data, new MemoryCacheEntryOptions { Size = 1, AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(1) }); }
public CommandBadRequestEventArgs(BadRequestResult res, ResultCompletionData data, CommandCalledEventArgs args) { Result = res; ResultCompletionData = data; Context = args.Context; Arguments = args.Arguments; Command = args.Command; Stopwatch = args.Stopwatch; }
private string ResultMessage(ResultCompletionData data) => $" | -Result Message: {data.Message?.Id}";