Fix a bunch of linter errors
diff --git a/src/utils/confirmationMessage.ts b/src/utils/confirmationMessage.ts
index fd58d12..728cc52 100644
--- a/src/utils/confirmationMessage.ts
+++ b/src/utils/confirmationMessage.ts
@@ -1,9 +1,14 @@
-import Discord, { CommandInteraction, MessageActionRow, MessageButton, TextInputComponent } from "discord.js";
+import Discord, {
+ CommandInteraction,
+ Message,
+ MessageActionRow,
+ MessageButton,
+ TextInputComponent
+} from "discord.js";
import { modalInteractionCollector } from "./dualCollector.js";
import EmojiEmbed from "./generateEmojiEmbed.js";
import getEmojiByName from "./getEmojiByName.js";
-
interface CustomBoolean<T> {
title: string;
disabled: boolean;
@@ -19,8 +24,8 @@
title = "";
emoji = "";
description = "";
- color = "";
- customButtons: {[index:string]: CustomBoolean<unknown>} = {};
+ color: "Danger" | "Warning" | "Success" = "Success";
+ customButtons: Record<string, CustomBoolean<unknown>> = {};
inverted = false;
reason: string | null = null;
@@ -28,21 +33,45 @@
this.interaction = interaction;
}
- 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; }
- setInverted(inverted: boolean) { this.inverted = inverted; return this; }
- addCustomBoolean(customId: string, title: string, disabled: boolean, callback: () => Promise<unknown> | null, callbackClicked: string | null, emoji?: string, initial?: boolean) { this.customButtons[customId] = {
- title: title,
- disabled: disabled,
- value: callbackClicked,
- emoji: emoji,
- active: initial ?? false,
- onClick: callback ?? (() => null),
- response: null
- };
- return this;
+ 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: "Danger" | "Warning" | "Success") {
+ this.color = color;
+ return this;
+ }
+ setInverted(inverted: boolean) {
+ this.inverted = inverted;
+ return this;
+ }
+ addCustomBoolean(
+ customId: string,
+ title: string,
+ disabled: boolean,
+ callback: () => Promise<unknown> = async () => null,
+ callbackClicked: string | null,
+ emoji?: string,
+ initial?: boolean
+ ) {
+ this.customButtons[customId] = {
+ title: title,
+ disabled: disabled,
+ value: callbackClicked,
+ emoji: emoji,
+ active: initial ?? false,
+ onClick: callback,
+ response: null
+ };
+ return this;
}
addReasonButton(reason: string) {
this.reason = reason;
@@ -63,50 +92,71 @@
.setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
];
Object.entries(this.customButtons).forEach(([k, v]) => {
- fullComponents.push(new Discord.MessageButton()
+ const button = new Discord.MessageButton()
.setCustomId(k)
.setLabel(v.title)
.setStyle(v.active ? "SUCCESS" : "PRIMARY")
- .setEmoji(getEmojiByName(v.emoji, "id"))
- .setDisabled(v.disabled));
+ .setDisabled(v.disabled);
+ if (v.emoji !== undefined)
+ button.setEmoji(getEmojiByName(v.emoji, "id"));
+ fullComponents.push(button);
});
- if (this.reason !== null) fullComponents.push(new Discord.MessageButton()
- .setCustomId("reason")
- .setLabel("Edit Reason")
- .setStyle("PRIMARY")
- .setEmoji(getEmojiByName("ICONS.EDIT", "id"))
- .setDisabled(false)
- );
+ if (this.reason !== null)
+ fullComponents.push(
+ new Discord.MessageButton()
+ .setCustomId("reason")
+ .setLabel("Edit Reason")
+ .setStyle("PRIMARY")
+ .setEmoji(getEmojiByName("ICONS.EDIT", "id"))
+ .setDisabled(false)
+ );
const components = [];
for (let i = 0; i < fullComponents.length; i += 5) {
- components.push(new MessageActionRow().addComponents(fullComponents.slice(i, i + 5)));
+ components.push(
+ new MessageActionRow().addComponents(
+ fullComponents.slice(i, i + 5)
+ )
+ );
}
const object = {
embeds: [
new EmojiEmbed()
.setEmoji(this.emoji)
.setTitle(this.title)
- .setDescription(this.description + "\n\n" + Object.values(this.customButtons).map(v => {
- if (v.value === null) return "";
- return v.active ? `*${v.value}*\n` : "";
- }).join(""))
+ .setDescription(
+ this.description +
+ "\n\n" +
+ Object.values(this.customButtons)
+ .map((v) => {
+ if (v.value === null) return "";
+ return v.active ? `*${v.value}*\n` : "";
+ })
+ .join("")
+ )
.setStatus(this.color)
],
components: components,
ephemeral: true,
fetchReply: true
};
- let m;
+ let m: Message;
try {
- if ( editOnly ) {
- m = await this.interaction.editReply(object);
+ if (editOnly) {
+ m = (await this.interaction.editReply(object)) as Message;
} else {
- m = await this.interaction.reply(object);
+ m = (await this.interaction.reply(
+ object
+ )) as unknown as Message;
}
- } catch { return { cancelled: true }; }
+ } catch {
+ return { cancelled: true };
+ }
let component;
try {
- component = await m.awaitMessageComponent({filter: (m) => m.user.id === this.interaction.user.id, time: 300000});
+ component = await m.awaitMessageComponent({
+ filter: (m) => m.user.id === this.interaction.user.id,
+ time: 300000
+ });
} catch (e) {
return { success: false, components: this.customButtons };
}
@@ -114,47 +164,75 @@
component.deferUpdate();
for (const v of Object.values(this.customButtons)) {
if (!v.active) continue;
- try { v.response = await v.onClick(); }
- catch (e) { console.log(e); }
+ try {
+ v.response = await v.onClick();
+ } catch (e) {
+ console.log(e);
+ }
}
return { success: true, components: this.customButtons };
} else if (component.customId === "no") {
component.deferUpdate();
return { success: false, components: this.customButtons };
} else if (component.customId === "reason") {
- await component.showModal(new Discord.Modal().setCustomId("modal").setTitle("Editing reason").addComponents(
- new MessageActionRow<TextInputComponent>().addComponents(new TextInputComponent()
- .setCustomId("reason")
- .setLabel("Reason")
- .setMaxLength(2000)
- .setRequired(false)
- .setStyle("PARAGRAPH")
- .setPlaceholder("Spammed in #general")
- .setValue(this.reason ? this.reason : "")
- )
- ));
+ await component.showModal(
+ new Discord.Modal()
+ .setCustomId("modal")
+ .setTitle("Editing reason")
+ .addComponents(
+ new MessageActionRow<TextInputComponent>().addComponents(
+ new TextInputComponent()
+ .setCustomId("reason")
+ .setLabel("Reason")
+ .setMaxLength(2000)
+ .setRequired(false)
+ .setStyle("PARAGRAPH")
+ .setPlaceholder("Spammed in #general")
+ .setValue(this.reason ? this.reason : "")
+ )
+ )
+ );
await this.interaction.editReply({
- embeds: [new EmojiEmbed()
- .setTitle(this.title)
- .setDescription("Modal opened. If you can't see it, click back and try again.")
- .setStatus(this.color)
- .setEmoji(this.emoji)
- ], components: [new MessageActionRow().addComponents([new MessageButton()
- .setLabel("Back")
- .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
- .setStyle("PRIMARY")
- .setCustomId("back")
- ])]
+ embeds: [
+ new EmojiEmbed()
+ .setTitle(this.title)
+ .setDescription(
+ "Modal opened. If you can't see it, click back and try again."
+ )
+ .setStatus(this.color)
+ .setEmoji(this.emoji)
+ ],
+ components: [
+ new MessageActionRow().addComponents([
+ new MessageButton()
+ .setLabel("Back")
+ .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
+ .setStyle("PRIMARY")
+ .setCustomId("back")
+ ])
+ ]
});
let out;
try {
- out = await modalInteractionCollector(m, (m) => m.channel.id === this.interaction.channel.id, (m) => m.customId === "reason");
- } catch (e) { return {}; }
- if (out.fields) { return { newReason: out.fields.getTextInputValue("reason") ?? "" }; }
- else { return { newReason: this.reason }; }
+ out = await modalInteractionCollector(
+ m,
+ (m) => m.channel.id === this.interaction.channel.id,
+ (m) => m.customId === "reason"
+ );
+ } catch (e) {
+ return {};
+ }
+ if (out.fields) {
+ return {
+ newReason: out.fields.getTextInputValue("reason") ?? ""
+ };
+ } else {
+ return { newReason: this.reason };
+ }
} else {
component.deferUpdate();
- this.customButtons[component.customId].active = !this.customButtons[component.customId].active;
+ this.customButtons[component.customId].active =
+ !this.customButtons[component.customId].active;
return { components: this.customButtons };
}
}