/// <summary> /// Post-command execution handling. /// </summary> private async Task OnCommandExecutedAsync(Optional <CommandInfo> commandInfo, ICommandContext context, IResult result) { // Bails if the generic result doesn't have an error reason, or if it's an unknown command error. if (string.IsNullOrEmpty(result.ErrorReason) || result.Error == CommandError.UnknownCommand) { return; } var embed = new EmbedBuilder(); switch (result) { case CommandRuntimeResult customResult: switch (customResult.Type) { case ResultType.Unknown: break; case ResultType.Info: embed = EmbedHelper.FromInfo(description: customResult.Reason); break; case ResultType.Warning: embed = EmbedHelper.FromWarning(description: customResult.Reason); break; case ResultType.Error: embed = EmbedHelper.FromError(description: customResult.Reason); break; case ResultType.Success: embed = EmbedHelper.FromSuccess(description: customResult.Reason); break; default: throw new ArgumentOutOfRangeException(); } break; default: embed = EmbedHelper.FromError(description: result.ErrorReason); break; } await context.Channel.SendMessageAsync("", embed : embed.Build()).ConfigureAwait(false); if (commandInfo.IsSpecified) { _loggingService.Log( $"{context.User} executed \"{commandInfo.Value.Aliases.FirstOrDefault()}\" in {context.Message.GetPostedAt()}." + Environment.NewLine + $"Result: {result.ErrorReason}" + Environment.NewLine + $"Result Type: {result.GetType().Name}", LogSeverity.Verbose); } }
private async Task HandlePostCommandExecutionAsync(Optional <CommandInfo> commandInfo, ICommandContext context, IResult result) { if (result.Error == CommandError.UnknownCommand) { return; } if (!string.IsNullOrEmpty(result.ErrorReason)) { Embed embed; switch (result) { case CommonResult commonResult: switch (commonResult.CommonResultType) { default: embed = EmbedHelper.FromInfo(description: commonResult.Reason); break; case CommonResultType.Warning: embed = EmbedHelper.FromWarning(description: commonResult.Reason); break; case CommonResultType.Error: embed = EmbedHelper.FromError(description: commonResult.Reason); break; case CommonResultType.Success: embed = EmbedHelper.FromSuccess(description: commonResult.Reason); break; } break; default: embed = EmbedHelper.FromError(description: result.ErrorReason); break; } var message = await context.Channel.SendMessageAsync("", embed : embed).ConfigureAwait(false); if (result.Error.HasValue) { _ = Task.Delay(TimeSpan.FromSeconds(5)) .ContinueWith(_ => message?.DeleteAsync().ConfigureAwait(false)); } } }
private async Task <RuntimeResult> RemindAsync(SocketUser user, DateTimeOffset dateTime, string remindContent) { if (DateTimeOffset.Now > dateTime) { return(CommandRuntimeResult.FromError($"{dateTime} has already passed!")); } var userTimeOffset = GetUserTimeOffset(user); await ReminderService.AddReminderAsync(user, Context.Channel, dateTime, remindContent).ConfigureAwait(false); await ReplyAsync(string.Empty, embed : EmbedHelper.FromSuccess() .WithAuthor(new EmbedAuthorBuilder { IconUrl = Context.Client.CurrentUser.GetAvatarUrlOrDefault(), Name = "New Reminder Set!" }) .AddField("Reminder", remindContent, true) .AddField("At", dateTime.ToOffset(userTimeOffset)).Build()).ConfigureAwait(false); return(CommandRuntimeResult.FromSuccess()); }