diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts index 8eb6ca3f..3b15e23c 100644 --- a/src/events/interactionCreate.ts +++ b/src/events/interactionCreate.ts @@ -1,7 +1,6 @@ import { - CacheType, + ButtonInteraction, Interaction, - InteractionDeferUpdateOptions, } from "discord.js"; import { Event } from "../models"; import { UserModel } from "../util/Models/userModel"; @@ -10,7 +9,7 @@ import { captureException } from "@sentry/node"; const event: Event = { event: "interactionCreate", - execute: async (client: WouldYou, interaction: Interaction) => { + execute: async (client: WouldYou, interaction: Interaction) => { const user = await UserModel.findOne({ userID: interaction.user.id }); if (!user) { @@ -45,7 +44,7 @@ const event: Event = { truth: "truth.used.command", dare: "dare.used.command", random: "random.used.command", - } as any; + } as Record; // Get the field path based on the command name const fieldPath = statsMap[interaction.commandName]; if (fieldPath) { @@ -65,7 +64,8 @@ const event: Event = { }); return; }); - } else if (interaction.isButton()) { + } + else if (interaction.isButton()) { const guildDb = await client.database.getGuild( interaction.guild?.id as string, true, @@ -100,10 +100,10 @@ const event: Event = { truth: "truth.used.replay", dare: "dare.used.replay", random: "random.used.replay", - } as any; + } as Record; // Get the field path based on the command name - const fieldPath = replyMap[(interaction as any).customId]; + const fieldPath = replyMap[interaction.customId]; if (fieldPath) { // Increment the specified field using $inc @@ -173,7 +173,7 @@ const event: Event = { interaction.customId.startsWith("higher_") || interaction.customId.startsWith("lower_") ) { - return button.execute(interaction, client, guildDb); + return button.execute(interaction as ButtonInteraction, client, guildDb); } if ( @@ -288,7 +288,7 @@ const event: Event = { } } - button.execute(interaction, client, guildDb); + return button.execute(interaction as ButtonInteraction, client, guildDb); } catch (err) { if (err) console.error(err); interaction.reply({ @@ -297,16 +297,32 @@ const event: Event = { }); return; } - } else { + } + else if ( + interaction.isStringSelectMenu() + || interaction.isUserSelectMenu() + || interaction.isRoleSelectMenu() + || interaction.isMentionableSelectMenu() + || interaction.isChannelSelectMenu() + ){ const guildDb = await client.database.getGuild( interaction.guild?.id as string, true, ); if (!guildDb) return; - const button = client.buttons.get((interaction as any).customId); - if (button) - return await button.execute(interaction as any, client, guildDb); + const selectMenu = client.buttons!.get(interaction.customId); + + if(!selectMenu) { + interaction.reply({ + content: "An error occurred while trying to execute that command.", + ephemeral: true, + }); + + return; + } + + return selectMenu.execute(interaction as any, client, guildDb); } }, }; diff --git a/src/util/Classes/generateHOR.ts b/src/util/Classes/generateHOR.ts index 0c790d96..bc8763a7 100644 --- a/src/util/Classes/generateHOR.ts +++ b/src/util/Classes/generateHOR.ts @@ -187,6 +187,9 @@ export default class HOR { ctx.fillText(`Score: ${score}`, 712, 50); ctx.closePath(); - return canvasObject.encode("png"); + const img = await canvasObject.encode("png"); + Canvas.clearAllCache(); + + return img; } } diff --git a/src/util/Classes/generateLOSE.ts b/src/util/Classes/generateLOSE.ts index 3c06b2f1..8ffc7464 100644 --- a/src/util/Classes/generateLOSE.ts +++ b/src/util/Classes/generateLOSE.ts @@ -76,6 +76,9 @@ export default class LOSE { ctx.fillText(`Score: ${score}`, 712, 280); ctx.closePath(); - return canvasObject.encode("png"); + const img = await canvasObject.encode("png"); + Canvas.clearAllCache(); + + return img; } } diff --git a/src/util/dailyMessage.ts b/src/util/dailyMessage.ts index 6720c5e1..24cd7a98 100644 --- a/src/util/dailyMessage.ts +++ b/src/util/dailyMessage.ts @@ -68,8 +68,8 @@ export default class DailyMessage { return; } // Always directly return before do to many actions - var General = await getWouldYouRather(db.language); - var WhatYouDo = await getWwyd(db.language); + const General = await getWouldYouRather(db.language); + const WhatYouDo = await getWwyd(db.language); let randomDaily: any; let dailyId; diff --git a/src/util/translationHandler.ts b/src/util/translationHandler.ts index 41e8dd47..e604eac7 100644 --- a/src/util/translationHandler.ts +++ b/src/util/translationHandler.ts @@ -53,7 +53,7 @@ export default class TranslationHandler { * @return {void} * @private */ - initLanguage(key: any, language: any) { + initLanguage(key: string, language: object): void { this.translations[key] = language; } @@ -63,7 +63,7 @@ export default class TranslationHandler { * @return {boolean} if the value is a valid translation key * @private */ - checkRegex(value: any) { + checkRegex(value: string): boolean { return /^[a-z]{2}_[A-Z]{2}(?:_rather|_wwyd|_nhie)?$/.test(value); } @@ -73,7 +73,7 @@ export default class TranslationHandler { * @return {object} * @private */ - getLanguage(language: any) { + getLanguage(language: string): object { if (!this.checkRegex(language)) return this.translations["en_EN"]; return this.translations[language]; } @@ -94,7 +94,7 @@ export default class TranslationHandler { * Reload the translation handler * @return {void} */ - reload() { + reload(): void { this.translations = {}; for (const l of this.availableLanguages) { try { @@ -114,14 +114,14 @@ export default class TranslationHandler { * @param {string} language the language key * @param {string} path the path to the translation * @param {object} data the data to replace in the translation - * @return {string|null} the translation + * @return {string} the translation * @example * const translation = getTranslation('en_EN', 'commands.ping.pong', {ping: 100}); */ - get(language: string, path: string, data: any = {}) { + get(language: string, path: string, data: Record = {}): string { if (!language) language = "en_EN"; - const l = this.getLanguage(language); + const l: Record = this.getLanguage(language); const p = path.split("."); let c = null; @@ -149,7 +149,7 @@ export default class TranslationHandler { if (data) { return c.replace( /{(\w+)}/g, - (match: any, key: any) => data[key] ?? match, + (match: string, key: string) => data[key] ?? match, ); }