/// <summary> /// Update the interactivity reaction message, and then send a new result /// message to the original channel that the command was sent from. /// </summary> /// <param name="reactionMessage"></param> /// <param name="reactionEvent"></param> public async Task Result(ReactionMessage reactionMessage, InteractivityResult <MessageReactionAddEventArgs> reactionEvent) { DateTime timestamp = DateTime.UtcNow; string resultText = "Denied"; var emoji = new ConfirmOrDenyEmojiModel(_ctx); var embedBuilder = new DiscordEmbedBuilder() .WithTimestamp(timestamp) .WithColor(DiscordColor.Red); if (reactionEvent.Result.Emoji == emoji.Confirmed) { resultText = "Confirmed"; embedBuilder.Color = DiscordColor.Green; } string username = reactionEvent.Result.User?.Username ?? "<unknown username>"; string footerText = $"{reactionEvent.Result.Emoji} {resultText} by {username}"; embedBuilder.WithFooter(footerText); if (_ctx.Channel.Id != reactionMessage.Channel?.Id) { await SendResultsToUserDefinedChannel(embedBuilder, resultText).ConfigureAwait(false); } embedBuilder.AddField("Jump Link", $"[Original Message]({_ctx.Message.JumpLink})"); await reactionMessage.DeleteAllReactions().ConfigureAwait(false); await reactionMessage.Update(embedBuilder).ConfigureAwait(false); }
/// <summary> /// Update reaction message with a timeout notice, and then notify the user /// who executed the command in a direct message that the command timed out. /// </summary> /// <param name="reactionMessage"></param> public async Task TimeOut(ReactionMessage reactionMessage) { DateTime timestamp = DateTime.UtcNow; DiscordEmoji errorEmoji = DiscordEmoji.FromName(_ctx.Client, ":no_entry:"); var embedBuilder = new DiscordEmbedBuilder() .WithTimestamp(timestamp) .WithFooter($"{errorEmoji} Request timed out") .WithColor(DiscordColor.Red); await reactionMessage.DeleteAllReactions().ConfigureAwait(false); await reactionMessage.Update(embedBuilder).ConfigureAwait(false); throw new InteractivityTimedOutException("Command timed out. No one neither confirmed nor denied."); }
public async Task Execute(CommandContext ctx, [Description("A question you would like anyone in the channel to either confirm or deny. " + "Sentences must be surrounded with double-quotes. ie; \"Is this real?\"")] string question, [Description("**(Optional)** Name of the channel that the question will be sent to, and answered in.")] string channelName = "", [Description("**(Optional)** Number of seconds to wait for an answer before the command times out.")] int delay = 60) { var message = new ReactionMessage(ctx); await message.Send(channelName, question).ConfigureAwait(false); var result = await message.WaitForResult(delay).ConfigureAwait(false); var handle = new ReactionResultHandler(ctx); if (result.TimedOut) { await handle.TimeOut(message).ConfigureAwait(false); } else { await handle.Result(message, result).ConfigureAwait(false); } }