From 09d42ace4b7eb07cade78500216529fc56e9c217 Mon Sep 17 00:00:00 2001 From: Yuzu Date: Mon, 18 Jul 2022 13:22:49 +0700 Subject: [PATCH] Changed embeds to HybridInteractionMessage --- src/discord/Developer/ServiceAnnouncement.ts | 48 +++++++-------- src/discord/InteractionManager.ts | 64 ++++++++++---------- src/discord/osu.ts | 42 ++++++------- 3 files changed, 77 insertions(+), 77 deletions(-) diff --git a/src/discord/Developer/ServiceAnnouncement.ts b/src/discord/Developer/ServiceAnnouncement.ts index 5a72754..faddf89 100644 --- a/src/discord/Developer/ServiceAnnouncement.ts +++ b/src/discord/Developer/ServiceAnnouncement.ts @@ -24,7 +24,7 @@ import Users from '../../services/Users'; const hexToDecimal = (hex: string) => parseInt(hex.replace('#', ''), 16); const EMBEDS = { - ANNOUNCEMENT_INFO: (data: Message | BaseInteraction) => { + ANNOUNCEMENT_INFO: (data: HybridInteractionMessage) => { return makeInfoEmbed({ title: 'Service Announcement', description: `This module contains management tool for announcement feed\n The announcement message is located in \`\`configs/ServiceAnnouncement.json\`\``, @@ -34,14 +34,14 @@ const EMBEDS = { value: '``reload`` ``previewNews`` ``sendNews`` ``previewMaintenance`` ``sendMaintenance`` ``previewMessage`` ``sendMessage`` ``previewAlert`` ``sendAlert``' } ], - user: data instanceof BaseInteraction ? data.user : data.author + user: data.getUser() }); }, - NOT_DEVELOPER: (data: Message | BaseInteraction) => { + NOT_DEVELOPER: (data: HybridInteractionMessage) => { return makeErrorEmbed({ title: 'Developer only', description: `This command is restricted to the developers only`, - user: data instanceof BaseInteraction ? data.user : data.author + user: data.getUser() }); }, MAKE_PAYLOAD: (payload: EmbedData) => { @@ -67,38 +67,38 @@ const EMBEDS = { return new EmbedBuilder(payload); }, - RELOADED: (data: Message | BaseInteraction) => { + RELOADED: (data: HybridInteractionMessage) => { return makeSuccessEmbed({ title: 'Service Announcement Configuration Reloaded', - user: data instanceof BaseInteraction ? data.user : data.author + user: data.getUser() }); }, - RELOAD_ERROR: (data: Message | BaseInteraction, error: string) => { + RELOAD_ERROR: (data: HybridInteractionMessage, error: string) => { return makeErrorEmbed({ title: 'Unable to reload Service Announcement Configuration', description: `\`\`\`${error}\`\`\``, - user: data instanceof BaseInteraction ? data.user : data.author + user: data.getUser() }); }, - SENDING_SERVICE_ANNOUNCEMENT: (data: Message | BaseInteraction) => { + SENDING_SERVICE_ANNOUNCEMENT: (data: HybridInteractionMessage) => { return makeProcessingEmbed({ title: 'Service Announcement', description: `Broadcasting Service Announcement`, - user: data instanceof BaseInteraction ? data.user : data.author + user: data.getUser() }); }, - SERVICE_ANNOUNCEMENT_SENT: (data: Message | BaseInteraction) => { + SERVICE_ANNOUNCEMENT_SENT: (data: HybridInteractionMessage) => { return makeSuccessEmbed({ title: 'Service Announcement', description: `Broadcasted Service Announcement`, - user: data instanceof BaseInteraction ? data.user : data.author + user: data.getUser() }); }, - SERVICE_ANNOUNCEMENT_SENT_WITH_ERRORS: (data: Message | BaseInteraction) => { + SERVICE_ANNOUNCEMENT_SENT_WITH_ERRORS: (data: HybridInteractionMessage) => { return makeWarningEmbed({ title: 'Service Announcement', description: `Broadcasted Service Announcement with errors, check console for more info`, - user: data instanceof BaseInteraction ? data.user : data.author + user: data.getUser() }); } }; @@ -167,7 +167,7 @@ export default class ServiceAnnouncement extends DiscordModule { async run(data: HybridInteractionMessage, args: any) { if (!Users.isDeveloper(data.getUser()!.id)) return await sendHybridInteractionMessageResponse(data, { - embeds: [EMBEDS.NOT_DEVELOPER(data.getRaw())] + embeds: [EMBEDS.NOT_DEVELOPER(data)] }); const channel = data.getChannel(); @@ -185,7 +185,7 @@ export default class ServiceAnnouncement extends DiscordModule { } catch (err: any) { Logger.error('Unable to load custom ServiceAnnouncement config: ' + err); return await sendMessage(channel, undefined, { - embeds: [EMBEDS.RELOAD_ERROR(data.getRaw(), err)] + embeds: [EMBEDS.RELOAD_ERROR(data, err)] }); } } else { @@ -197,7 +197,7 @@ export default class ServiceAnnouncement extends DiscordModule { } return await sendMessage(channel, undefined, { - embeds: [EMBEDS.RELOADED(data.getRaw())] + embeds: [EMBEDS.RELOADED(data)] }); }, previewNews: async (data: HybridInteractionMessage) => { @@ -252,7 +252,7 @@ export default class ServiceAnnouncement extends DiscordModule { let _placeholder = await sendHybridInteractionMessageResponse( data, - { embeds: [EMBEDS.SENDING_SERVICE_ANNOUNCEMENT(data.getRaw())] }, + { embeds: [EMBEDS.SENDING_SERVICE_ANNOUNCEMENT(data)] }, true ); if (_placeholder) placeholder = new HybridInteractionMessage(_placeholder); @@ -300,7 +300,7 @@ export default class ServiceAnnouncement extends DiscordModule { .getMessage() .edit({ embeds: [ - EMBEDS.SERVICE_ANNOUNCEMENT_SENT_WITH_ERRORS(data.getRaw()) + EMBEDS.SERVICE_ANNOUNCEMENT_SENT_WITH_ERRORS(data) ] }); else if (data.isApplicationCommand()) @@ -308,7 +308,7 @@ export default class ServiceAnnouncement extends DiscordModule { data, { embeds: [ - EMBEDS.SERVICE_ANNOUNCEMENT_SENT_WITH_ERRORS(data.getRaw()) + EMBEDS.SERVICE_ANNOUNCEMENT_SENT_WITH_ERRORS(data) ] }, true @@ -317,11 +317,11 @@ export default class ServiceAnnouncement extends DiscordModule { if (data && data.isMessage() && placeholder && placeholder.isMessage()) return placeholder .getMessage() - .edit({ embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_SENT(data.getRaw())] }); + .edit({ embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_SENT(data)] }); else if (data.isApplicationCommand()) return await sendHybridInteractionMessageResponse( data, - { embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_SENT(data.getRaw())] }, + { embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_SENT(data)] }, true ); } @@ -333,7 +333,7 @@ export default class ServiceAnnouncement extends DiscordModule { if (data.isMessage()) { if (args.length === 0) return await sendHybridInteractionMessageResponse(data, { - embeds: [EMBEDS.ANNOUNCEMENT_INFO(data.getRaw())] + embeds: [EMBEDS.ANNOUNCEMENT_INFO(data)] }); query = args[0].toLowerCase(); } else if (data.isApplicationCommand()) { @@ -343,7 +343,7 @@ export default class ServiceAnnouncement extends DiscordModule { switch (query) { case 'info': return await sendHybridInteractionMessageResponse(data, { - embeds: [EMBEDS.ANNOUNCEMENT_INFO(data.getRaw())] + embeds: [EMBEDS.ANNOUNCEMENT_INFO(data)] }); case 'reload': return await funct.reload(data); diff --git a/src/discord/InteractionManager.ts b/src/discord/InteractionManager.ts index 95be3ce..7f02d80 100644 --- a/src/discord/InteractionManager.ts +++ b/src/discord/InteractionManager.ts @@ -18,7 +18,7 @@ import { } from '../utils/DiscordInteraction'; const EMBEDS = { - INTERACTION_INFO: (data: Message | BaseInteraction) => { + INTERACTION_INFO: (data: HybridInteractionMessage) => { return makeInfoEmbed({ title: 'Interaction', description: `This module contains management tool for interaction based contents`, @@ -28,47 +28,47 @@ const EMBEDS = { value: '``reloadAll`` ``unloadAll`` ``reloadglobal``' } ], - user: data instanceof BaseInteraction ? data.user : data.author + user: data.getUser() }); }, - PROCESSING: (data: Message | BaseInteraction) => { + PROCESSING: (data: HybridInteractionMessage) => { return makeProcessingEmbed({ icon: data instanceof Message ? undefined : '⌛', title: `Performing actions`, - user: data instanceof BaseInteraction ? data.user : data.author + user: data.getUser() }); }, - NOT_DEVELOPER: (data: Message | BaseInteraction) => { + NOT_DEVELOPER: (data: HybridInteractionMessage) => { return makeErrorEmbed({ title: 'Developer only', description: `This command is restricted to the developers only`, - user: data instanceof BaseInteraction ? data.user : data.author + user: data.getUser() }); }, - UNLOADALL_SUCCESS: (data: Message | BaseInteraction) => { + UNLOADALL_SUCCESS: (data: HybridInteractionMessage) => { return makeSuccessEmbed({ title: 'Unloaded all Interaction', - user: data instanceof BaseInteraction ? data.user : data.author + user: data.getUser() }); }, - UNLOADALL_ERROR: (data: Message | BaseInteraction, err: any) => { + UNLOADALL_ERROR: (data: HybridInteractionMessage, err: any) => { return makeErrorEmbed({ title: 'An error occurred while trying to unload interaction', description: '```' + err + '```', - user: data instanceof BaseInteraction ? data.user : data.author + user: data.getUser() }); }, - RELOADALL_SUCCESS: (data: Message | BaseInteraction) => { + RELOADALL_SUCCESS: (data: HybridInteractionMessage) => { return makeSuccessEmbed({ title: 'Reloaded all Interaction', - user: data instanceof BaseInteraction ? data.user : data.author + user: data.getUser() }); }, - RELOADALL_ERROR: (data: Message | BaseInteraction, err: any) => { + RELOADALL_ERROR: (data: HybridInteractionMessage, err: any) => { return makeErrorEmbed({ title: 'An error occurred while trying to reload interaction', description: '```' + err + '```', - user: data instanceof BaseInteraction ? data.user : data.author + user: data.getUser() }); } }; @@ -92,7 +92,7 @@ export default class InteractionManager extends DiscordModule { if (!Users.isDeveloper(user.id)) return await sendHybridInteractionMessageResponse(data, { - embeds: [EMBEDS.NOT_DEVELOPER(data.getRaw())] + embeds: [EMBEDS.NOT_DEVELOPER(data)] }); const funct = { @@ -100,7 +100,7 @@ export default class InteractionManager extends DiscordModule { let placeholder: HybridInteractionMessage | undefined; let _placeholder = await sendHybridInteractionMessageResponse(data, { - embeds: [EMBEDS.PROCESSING(data.getRaw())] + embeds: [EMBEDS.PROCESSING(data)] }); if (_placeholder) placeholder = new HybridInteractionMessage(_placeholder); @@ -110,22 +110,22 @@ export default class InteractionManager extends DiscordModule { if (data && data.isMessage() && placeholder && placeholder.isMessage()) return placeholder .getMessage() - .edit({ embeds: [EMBEDS.UNLOADALL_SUCCESS(data.getRaw())] }); + .edit({ embeds: [EMBEDS.UNLOADALL_SUCCESS(data)] }); else if (data.isApplicationCommand()) return await sendHybridInteractionMessageResponse( data, - { embeds: [EMBEDS.UNLOADALL_SUCCESS(data.getRaw())] }, + { embeds: [EMBEDS.UNLOADALL_SUCCESS(data)] }, true ); } catch (err) { if (data && data.isMessage() && placeholder && placeholder.isMessage()) return placeholder .getMessage() - .edit({ embeds: [EMBEDS.UNLOADALL_ERROR(data.getRaw(), err)] }); + .edit({ embeds: [EMBEDS.UNLOADALL_ERROR(data, err)] }); else if (data.isApplicationCommand()) return await sendHybridInteractionMessageResponse( data, - { embeds: [EMBEDS.UNLOADALL_ERROR(data.getRaw(), err)] }, + { embeds: [EMBEDS.UNLOADALL_ERROR(data, err)] }, true ); } @@ -134,7 +134,7 @@ export default class InteractionManager extends DiscordModule { let placeholder: HybridInteractionMessage | undefined; let _placeholder = await sendHybridInteractionMessageResponse(data, { - embeds: [EMBEDS.PROCESSING(data.getRaw())] + embeds: [EMBEDS.PROCESSING(data)] }); if (_placeholder) placeholder = new HybridInteractionMessage(_placeholder); @@ -145,22 +145,22 @@ export default class InteractionManager extends DiscordModule { if (data && data.isMessage() && placeholder && placeholder.isMessage()) return placeholder .getMessage() - .edit({ embeds: [EMBEDS.RELOADALL_SUCCESS(data.getRaw())] }); + .edit({ embeds: [EMBEDS.RELOADALL_SUCCESS(data)] }); else if (data.isApplicationCommand()) return await sendHybridInteractionMessageResponse( data, - { embeds: [EMBEDS.RELOADALL_SUCCESS(data.getRaw())] }, + { embeds: [EMBEDS.RELOADALL_SUCCESS(data)] }, true ); } catch (err) { if (data && data.isMessage() && placeholder && placeholder.isMessage()) return placeholder .getMessage() - .edit({ embeds: [EMBEDS.RELOADALL_ERROR(data.getRaw(), err)] }); + .edit({ embeds: [EMBEDS.RELOADALL_ERROR(data, err)] }); else if (data.isApplicationCommand()) return await sendHybridInteractionMessageResponse( data, - { embeds: [EMBEDS.RELOADALL_ERROR(data.getRaw(), err)] }, + { embeds: [EMBEDS.RELOADALL_ERROR(data, err)] }, true ); } @@ -169,7 +169,7 @@ export default class InteractionManager extends DiscordModule { let placeholder: HybridInteractionMessage | undefined; let _placeholder = await sendHybridInteractionMessageResponse(data, { - embeds: [EMBEDS.PROCESSING(data.getRaw())] + embeds: [EMBEDS.PROCESSING(data)] }); if (_placeholder) placeholder = new HybridInteractionMessage(_placeholder); @@ -180,22 +180,22 @@ export default class InteractionManager extends DiscordModule { if (data && data.isMessage() && placeholder && placeholder.isMessage()) return placeholder .getMessage() - .edit({ embeds: [EMBEDS.RELOADALL_SUCCESS(data.getRaw())] }); + .edit({ embeds: [EMBEDS.RELOADALL_SUCCESS(data)] }); else if (data.isApplicationCommand()) return await sendHybridInteractionMessageResponse( data, - { embeds: [EMBEDS.RELOADALL_SUCCESS(data.getRaw())] }, + { embeds: [EMBEDS.RELOADALL_SUCCESS(data)] }, true ); } catch (err) { if (data && data.isMessage() && placeholder && placeholder.isMessage()) return placeholder .getMessage() - .edit({ embeds: [EMBEDS.RELOADALL_ERROR(data.getRaw(), err)] }); + .edit({ embeds: [EMBEDS.RELOADALL_ERROR(data, err)] }); else if (data.isApplicationCommand()) return await sendHybridInteractionMessageResponse( data, - { embeds: [EMBEDS.RELOADALL_ERROR(data.getRaw(), err)] }, + { embeds: [EMBEDS.RELOADALL_ERROR(data, err)] }, true ); } @@ -207,7 +207,7 @@ export default class InteractionManager extends DiscordModule { if (data.isMessage()) { if (args.length === 0) return await sendHybridInteractionMessageResponse(data, { - embeds: [EMBEDS.INTERACTION_INFO(data.getRaw())] + embeds: [EMBEDS.INTERACTION_INFO(data)] }); query = args[0].toLowerCase(); @@ -218,7 +218,7 @@ export default class InteractionManager extends DiscordModule { switch (query) { case 'info': return await sendHybridInteractionMessageResponse(data, { - embeds: [EMBEDS.INTERACTION_INFO(data.getRaw())] + embeds: [EMBEDS.INTERACTION_INFO(data)] }); case 'reloadall': return await funct.reloadAll(data); diff --git a/src/discord/osu.ts b/src/discord/osu.ts index e2e0d0a..bf0623a 100644 --- a/src/discord/osu.ts +++ b/src/discord/osu.ts @@ -21,7 +21,7 @@ import { } from '../utils/DiscordMessage'; const EMBEDS = { - osu_INFO: (data: Message | BaseInteraction) => { + osu_INFO: (data: HybridInteractionMessage) => { return makeInfoEmbed({ title: 'osu!', description: `[osu!](https://osu.ppy.sh/home) is a free-to-play rhythm game primarily developed, published, and created by Dean "peppy" Herbert`, @@ -35,43 +35,43 @@ const EMBEDS = { value: '``user``' } ], - user: data instanceof BaseInteraction ? data.user : data.author + user: data.getUser() }); }, - NO_USER_FOUND: (data: Message | BaseInteraction) => { + NO_USER_FOUND: (data: HybridInteractionMessage) => { return makeErrorEmbed({ title: `That user doesn't exists on osu!`, - user: data instanceof BaseInteraction ? data.user : data.author + user: data.getUser() }); }, - NO_USER_MENTIONED: (data: Message | BaseInteraction) => { + NO_USER_MENTIONED: (data: HybridInteractionMessage) => { return makeErrorEmbed({ title: `No osu! username or user id provided`, - user: data instanceof BaseInteraction ? data.user : data.author + user: data.getUser() }); }, - INVALID_USER_MENTIONED: (data: Message | BaseInteraction) => { + INVALID_USER_MENTIONED: (data: HybridInteractionMessage) => { return makeErrorEmbed({ title: `Not a valid osu username or id`, - user: data instanceof BaseInteraction ? data.user : data.author + user: data.getUser() }); }, - INVALID_BEATMAP_ID_MENTIONED: (data: Message | BaseInteraction) => { + INVALID_BEATMAP_ID_MENTIONED: (data: HybridInteractionMessage) => { return makeErrorEmbed({ title: `Not a valid osu beatmap id`, - user: data instanceof BaseInteraction ? data.user : data.author + user: data.getUser() }); }, - NO_BEATMAP_FOUND: (data: Message | BaseInteraction) => { + NO_BEATMAP_FOUND: (data: HybridInteractionMessage) => { return makeErrorEmbed({ title: `That beatmap doesn't exists on osu!`, - user: data instanceof BaseInteraction ? data.user : data.author + user: data.getUser() }); }, - NO_BEATMAP_MENTIONED: (data: Message | BaseInteraction) => { + NO_BEATMAP_MENTIONED: (data: HybridInteractionMessage) => { return makeErrorEmbed({ title: `No osu! beatmap id provided`, - user: data instanceof BaseInteraction ? data.user : data.author + user: data.getUser() }); } }; @@ -99,7 +99,7 @@ export default class osu extends DiscordModule { if (data.isMessage()) { if (typeof args[1] === 'undefined') return await sendHybridInteractionMessageResponse(data, { - embeds: [EMBEDS.NO_USER_MENTIONED(data.getRaw())] + embeds: [EMBEDS.NO_USER_MENTIONED(data)] }); const [removed, ...newArgs] = args; user = newArgs.join(' '); @@ -108,14 +108,14 @@ export default class osu extends DiscordModule { if (!validator.isNumeric(user) && !this.validate_osu_username(user)) return await sendHybridInteractionMessageResponse(data, { - embeds: [EMBEDS.INVALID_USER_MENTIONED(data.getRaw())] + embeds: [EMBEDS.INVALID_USER_MENTIONED(data)] }); let result = await osuAPI.client.getUser({ u: user }); if (result instanceof Array && result.length === 0) return await sendHybridInteractionMessageResponse(data, { - embeds: [EMBEDS.NO_USER_FOUND(data.getRaw())] + embeds: [EMBEDS.NO_USER_FOUND(data)] }); if (data.isApplicationCommand()) { @@ -277,7 +277,7 @@ export default class osu extends DiscordModule { if (data.isMessage()) { if (typeof args[1] === 'undefined') return await sendHybridInteractionMessageResponse(data, { - embeds: [EMBEDS.NO_BEATMAP_MENTIONED(data.getRaw())] + embeds: [EMBEDS.NO_BEATMAP_MENTIONED(data)] }); const [removed, ...newArgs] = args; beatmap = newArgs.join(' '); @@ -286,14 +286,14 @@ export default class osu extends DiscordModule { if (!validator.isNumeric(beatmap)) return await sendHybridInteractionMessageResponse(data, { - embeds: [EMBEDS.INVALID_BEATMAP_ID_MENTIONED(data.getRaw())] + embeds: [EMBEDS.INVALID_BEATMAP_ID_MENTIONED(data)] }); let result = await osuAPI.client.getBeatmaps({ b: beatmap }); if (result instanceof Array && result.length === 0) return await sendHybridInteractionMessageResponse(data, { - embeds: [EMBEDS.NO_BEATMAP_FOUND(data.getRaw())] + embeds: [EMBEDS.NO_BEATMAP_FOUND(data)] }); if (data.isApplicationCommand()) await data.getSlashCommand().deferReply(); @@ -473,7 +473,7 @@ export default class osu extends DiscordModule { if (data.isMessage()) { if (args.length === 0) { return await sendHybridInteractionMessageResponse(data, { - embeds: [EMBEDS.osu_INFO(data.getRaw())] + embeds: [EMBEDS.osu_INFO(data)] }); } query = args[0].toLowerCase();