From 26e7b76fdc2ce2b38fc1946653dce06fe5b40f82 Mon Sep 17 00:00:00 2001 From: Still Hsu <341464@gmail.com> Date: Sun, 21 Oct 2018 17:24:22 +0800 Subject: [PATCH] Revise post-execution docs * Fix incorrect Optional usage * Indent some sample code and add a comment reminding the user that the post-execution basic sample code is not ideal. --- .../samples/post-execution/command_executed_demo.cs | 10 +++++++--- .../samples/post-execution/post-execution_basic.cs | 7 +++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/docs/guides/commands/samples/post-execution/command_executed_demo.cs b/docs/guides/commands/samples/post-execution/command_executed_demo.cs index b0895f53d..a0b26183e 100644 --- a/docs/guides/commands/samples/post-execution/command_executed_demo.cs +++ b/docs/guides/commands/samples/post-execution/command_executed_demo.cs @@ -20,15 +20,19 @@ public async Task OnCommandExecutedAsync(Optional command, ICommand // ...or even log the result (the method used should fit into // your existing log handler) - var commandName = command.HasValue ? command.Name : "A command"; - await _log.LogAsync(new LogMessage(LogSeverity.Info, "CommandExecution", $"{commandName} was executed at {DateTime.UtcNow}.")); + var commandName = command.IsSpecified ? command.Value.Name : "A command"; + await _log.LogAsync(new LogMessage(LogSeverity.Info, + "CommandExecution", + $"{commandName} was executed at {DateTime.UtcNow}.")); } public async Task HandleCommandAsync(SocketMessage msg) { var message = messageParam as SocketUserMessage; if (message == null) return; int argPos = 0; - if (!(message.HasCharPrefix('!', ref argPos) || message.HasMentionPrefix(_client.CurrentUser, ref argPos)) || message.Author.IsBot) return; + if (!(message.HasCharPrefix('!', ref argPos) || + message.HasMentionPrefix(_client.CurrentUser, ref argPos)) || + message.Author.IsBot) return; var context = new SocketCommandContext(_client, message); await _commands.ExecuteAsync(context, argPos, _services); } diff --git a/docs/guides/commands/samples/post-execution/post-execution_basic.cs b/docs/guides/commands/samples/post-execution/post-execution_basic.cs index 19c7bed59..d1361a1f2 100644 --- a/docs/guides/commands/samples/post-execution/post-execution_basic.cs +++ b/docs/guides/commands/samples/post-execution/post-execution_basic.cs @@ -1,11 +1,14 @@ +// Bad code!!! var result = await _commands.ExecuteAsync(context, argPos, _services); if (result.CommandError != null) switch(result.CommandError) { case CommandError.BadArgCount: - await context.Channel.SendMessageAsync("Parameter count does not match any command's."); + await context.Channel.SendMessageAsync( + "Parameter count does not match any command's."); break; default: - await context.Channel.SendMessageAsync($"An error has occurred {result.ErrorReason}"); + await context.Channel.SendMessageAsync( + $"An error has occurred {result.ErrorReason}"); break; } \ No newline at end of file