i have not committed in years
diff --git a/src/utils/confirmationMessage.ts b/src/utils/confirmationMessage.ts
index 7deb5f5..fc8b76c 100644
--- a/src/utils/confirmationMessage.ts
+++ b/src/utils/confirmationMessage.ts
@@ -1,5 +1,5 @@
import Discord, { CommandInteraction, MessageActionRow, Message } from "discord.js";
-import EmojiEmbed from "./generateEmojiEmbed.js"
+import generateEmojiEmbed from "./generateEmojiEmbed.js"
import getEmojiByName from "./getEmojiByName.js";
class confirmationMessage {
@@ -8,6 +8,12 @@
emoji: string;
description: string;
color: string;
+ customCallback: () => any;
+ customButtonTitle: string;
+ customButtonDisabled: boolean;
+ customCallbackString: string = "";
+ customCallbackClicked: boolean = false;
+ customCallbackResponse: any = null;
constructor(interaction: CommandInteraction) {
this.interaction = interaction;
@@ -16,54 +22,81 @@
this.emoji = "";
this.description = "";
this.color = "";
+ this.customCallback = () => {}
}
setTitle(title: string) { this.title = title; return this }
setEmoji(emoji: string) { this.emoji = emoji; return this }
setDescription(description: string) { this.description = description; return this }
setColor(color: string) { this.color = color; return this }
+ addCustomCallback(title: string, disabled: boolean, callback: () => any, callbackClicked: string) {
+ this.customButtonTitle = title;
+ this.customButtonDisabled = disabled;
+ this.customCallback = callback;
+ this.customCallbackString = callbackClicked;
+ return this;
+ }
async send(editOnly?: boolean) {
- let object = {
- embeds: [
- new EmojiEmbed()
- .setEmoji(this.emoji)
- .setTitle(this.title)
- .setDescription(this.description)
- .setStatus(this.color)
- ],
- components: [
- new MessageActionRow().addComponents([
- new Discord.MessageButton()
- .setCustomId("yes")
- .setLabel("Yes")
- .setStyle("SUCCESS")
- .setEmoji(getEmojiByName("CONTROL.TICK", "id")),
- new Discord.MessageButton()
- .setCustomId("no")
- .setLabel("Cancel")
- .setStyle("DANGER")
- .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
- ])
- ],
- ephemeral: true,
- fetchReply: true
+ while (true) {
+ let object = {
+ embeds: [
+ new generateEmojiEmbed()
+ .setEmoji(this.emoji)
+ .setTitle(this.title)
+ .setDescription(this.description)
+ .setStatus(this.color)
+ .setFooter({text: this.customCallbackClicked ? this.customCallbackString : ""})
+ ],
+ components: [
+ new MessageActionRow().addComponents([
+ new Discord.MessageButton()
+ .setCustomId("yes")
+ .setLabel("Yes")
+ .setStyle("SUCCESS")
+ .setEmoji(getEmojiByName("CONTROL.TICK", "id")),
+ new Discord.MessageButton()
+ .setCustomId("no")
+ .setLabel("Cancel")
+ .setStyle("DANGER")
+ .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
+ ].concat(this.customButtonTitle ? [new Discord.MessageButton()
+ .setCustomId("custom")
+ .setLabel(this.customButtonTitle)
+ .setStyle("SECONDARY")
+ .setDisabled(this.customButtonDisabled)
+ .setEmoji(getEmojiByName("CONTROL.RIGHT", "id")) // TODO: add an emoji
+ ] : []))
+ ],
+ ephemeral: true,
+ fetchReply: true
+ }
+ let m;
+ if ( editOnly ) {
+ m = await this.interaction.editReply(object);
+ } else {
+ m = await this.interaction.reply(object)
+ }
+ let component;
+ try {
+ component = await (m as Message).awaitMessageComponent({filter: (m) => m.user.id === this.interaction.user.id, time: 2.5 * 60 * 1000});
+ } catch (e) {
+ return {success: false, buttonClicked: this.customCallbackClicked, response: this.customCallbackResponse}; // TODO: Check the type of the error; change the error message here
+ }
+ if (component.customId === "yes") {
+ component.deferUpdate();
+ return {success: true, buttonClicked: this.customCallbackClicked, response: this.customCallbackResponse};
+ } else if (component.customId === "no") {
+ component.deferUpdate();
+ return {success: false, buttonClicked: this.customCallbackClicked, response: this.customCallbackResponse};
+ } else if (component.customId === "custom") {
+ component.deferUpdate();
+ this.customCallbackResponse = this.customCallback();
+ this.customCallbackClicked = true;
+ this.customButtonDisabled = true;
+ editOnly = true;
+ }
}
- let m;
- if ( editOnly ) {
- m = await this.interaction.editReply(object);
- } else {
- m = await this.interaction.reply(object)
- }
- let component;
- try {
- component = await (m as Message).awaitMessageComponent({filter: (m) => m.user.id === this.interaction.user.id, time: 2.5 * 60 * 1000});
- } catch (e) {
- return false; // TODO: Check the type of the error; change the error message here
- }
- component.deferUpdate();
-
- return component.customId === "yes"
}
}