From 733855ac7067d0c4d806cfceceedfaf90a27b58c Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Sat, 10 Aug 2019 00:13:35 +0300 Subject: [PATCH] Add standardized function for asking the user to confirm an action --- src/utils.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/utils.ts b/src/utils.ts index 33fb6af3..1cfdfe8b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -6,6 +6,7 @@ import { GuildAuditLog, GuildAuditLogEntry, Member, + MessageContent, TextableChannel, TextChannel, User, @@ -21,7 +22,7 @@ const fsp = fs.promises; import https from "https"; import tmp from "tmp"; -import { logger } from "knub"; +import { logger, waitForReaction } from "knub"; const delayStringMultipliers = { w: 1000 * 60 * 60 * 24 * 7, @@ -707,3 +708,10 @@ export async function resolveMember(bot: Client, guild: Guild, value: string): P } export type StrictMessageContent = { content?: string; tts?: boolean; disableEveryone?: boolean; embed?: EmbedOptions }; + +export async function confirm(bot: Client, channel: TextableChannel, userId: string, content: MessageContent) { + const msg = await channel.createMessage(content); + const reply = await waitForReaction(bot, msg, ["✅", "❌"], userId); + msg.delete().catch(noop); + return reply && reply.name === "✅"; +}