diff --git a/src/interactions/autocomplete/lyrics.ts b/src/interactions/autocomplete/lyrics.ts index 208090a..8094edf 100644 --- a/src/interactions/autocomplete/lyrics.ts +++ b/src/interactions/autocomplete/lyrics.ts @@ -3,7 +3,7 @@ import { Player, SearchResult, useMainPlayer } from 'discord-player'; import { ApplicationCommandOptionChoiceData } from 'discord.js'; import { Logger } from 'pino'; import loggerModule from '../../services/logger'; -import { CustomAutocompleteInteraction } from '../../types/interactionTypes'; +import { BaseAutocompleteInteraction } from '../../types/interactionTypes'; const loggerTemplate: Logger = loggerModule.child({ source: 'lyrics.js', @@ -14,7 +14,7 @@ const loggerTemplate: Logger = loggerModule.child({ // TODO: create interface for recent query object const recentQueries = new Map(); -const autocomplete: CustomAutocompleteInteraction = { +const autocomplete: BaseAutocompleteInteraction = { execute: async ({ interaction, executionId }) => { const logger: Logger = loggerTemplate.child({ executionId: executionId, diff --git a/src/interactions/autocomplete/play.ts b/src/interactions/autocomplete/play.ts index c0f7a4b..57f78c5 100644 --- a/src/interactions/autocomplete/play.ts +++ b/src/interactions/autocomplete/play.ts @@ -2,7 +2,7 @@ import { Player, SearchResult, useMainPlayer } from 'discord-player'; import { ApplicationCommandOptionChoiceData } from 'discord.js'; import { Logger } from 'pino'; import loggerModule from '../../services/logger'; -import { CustomAutocompleteInteraction } from '../../types/interactionTypes'; +import { BaseAutocompleteInteraction } from '../../types/interactionTypes'; const loggerTemplate: Logger = loggerModule.child({ source: 'play.js', @@ -13,7 +13,7 @@ const loggerTemplate: Logger = loggerModule.child({ // TODO: create interface for recent query object const recentQueries = new Map(); -const autocomplete: CustomAutocompleteInteraction = { +const autocomplete: BaseAutocompleteInteraction = { execute: async ({ interaction, executionId }) => { const logger: Logger = loggerTemplate.child({ executionId: executionId, diff --git a/src/interactions/commands/info/help.ts b/src/interactions/commands/info/help.ts index 7751a0f..2bddf4b 100644 --- a/src/interactions/commands/info/help.ts +++ b/src/interactions/commands/info/help.ts @@ -3,12 +3,12 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; import { Logger } from 'pino'; import loggerModule from '../../../services/logger'; import { BotOptions, EmbedOptions } from '../../../types/configTypes'; -import { CustomSlashCommandInteraction } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../types/interactionTypes'; const embedOptions: EmbedOptions = config.get('embedOptions'); const botOptions: BotOptions = config.get('botOptions'); -const command: CustomSlashCommandInteraction = { +const command: BaseSlashCommandInteraction = { isNew: false, isBeta: false, data: new SlashCommandBuilder() diff --git a/src/interactions/commands/info/status.ts b/src/interactions/commands/info/status.ts index a0362ac..74b2c5c 100644 --- a/src/interactions/commands/info/status.ts +++ b/src/interactions/commands/info/status.ts @@ -6,12 +6,12 @@ import { Logger } from 'pino'; import { version } from '../../../../package.json'; import loggerModule from '../../../services/logger'; import { EmbedOptions } from '../../../types/configTypes'; -import { CustomSlashCommandInteraction } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../types/interactionTypes'; import { getUptimeFormatted } from '../../../utils/system/getUptimeFormatted'; const embedOptions: EmbedOptions = config.get('embedOptions'); -const command: CustomSlashCommandInteraction = { +const command: BaseSlashCommandInteraction = { isNew: false, isBeta: false, data: new SlashCommandBuilder() diff --git a/src/interactions/commands/player/filters.ts b/src/interactions/commands/player/filters.ts index a44af2e..b1d2473 100644 --- a/src/interactions/commands/player/filters.ts +++ b/src/interactions/commands/player/filters.ts @@ -16,14 +16,14 @@ import { import { Logger } from 'pino'; import loggerModule from '../../../services/logger'; import { EmbedOptions, FFmpegFilterOption, FFmpegFilterOptions } from '../../../types/configTypes'; -import { CustomSlashCommandInteraction } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../types/interactionTypes'; import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; const embedOptions: EmbedOptions = config.get('embedOptions'); const ffmpegFilterOptions: FFmpegFilterOptions = config.get('ffmpegFilterOptions'); -const command: CustomSlashCommandInteraction = { +const command: BaseSlashCommandInteraction = { isNew: false, isBeta: false, data: new SlashCommandBuilder() diff --git a/src/interactions/commands/player/leave.ts b/src/interactions/commands/player/leave.ts index a6f6203..fa7b545 100644 --- a/src/interactions/commands/player/leave.ts +++ b/src/interactions/commands/player/leave.ts @@ -4,13 +4,13 @@ import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js'; import { Logger } from 'pino'; import loggerModule from '../../../services/logger'; import { EmbedOptions } from '../../../types/configTypes'; -import { CustomSlashCommandInteraction } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../types/interactionTypes'; import { queueDoesNotExist } from '../../../utils/validation/queueValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; const embedOptions: EmbedOptions = config.get('embedOptions'); -const command: CustomSlashCommandInteraction = { +const command: BaseSlashCommandInteraction = { isNew: false, isBeta: false, data: new SlashCommandBuilder() diff --git a/src/interactions/commands/player/loop.ts b/src/interactions/commands/player/loop.ts index 22c3265..e7c7868 100644 --- a/src/interactions/commands/player/loop.ts +++ b/src/interactions/commands/player/loop.ts @@ -4,14 +4,14 @@ import { EmbedBuilder, GuildMember, SlashCommandBuilder, SlashCommandStringOptio import { Logger } from 'pino'; import loggerModule from '../../../services/logger'; import { BotOptions, EmbedOptions } from '../../../types/configTypes'; -import { CustomSlashCommandInteraction } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../types/interactionTypes'; import { queueDoesNotExist } from '../../../utils/validation/queueValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; const embedOptions: EmbedOptions = config.get('embedOptions'); const botOptions: BotOptions = config.get('botOptions'); -const command: CustomSlashCommandInteraction = { +const command: BaseSlashCommandInteraction = { isNew: false, isBeta: false, data: new SlashCommandBuilder() diff --git a/src/interactions/commands/player/lyrics.ts b/src/interactions/commands/player/lyrics.ts index 9ddb013..2dd18c6 100644 --- a/src/interactions/commands/player/lyrics.ts +++ b/src/interactions/commands/player/lyrics.ts @@ -5,7 +5,7 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; import { LyricsData, lyricsExtractor } from '@discord-player/extractor'; import loggerModule from '../../../services/logger'; -import { CustomSlashCommandInteraction } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../types/interactionTypes'; import { EmbedOptions } from '../../../types/configTypes'; import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; @@ -19,7 +19,7 @@ const loggerTemplate: Logger = loggerModule.child({ name: '/lyrics' }); -const command: CustomSlashCommandInteraction = { +const command: BaseSlashCommandInteraction = { isNew: false, isBeta: false, data: new SlashCommandBuilder() diff --git a/src/interactions/commands/player/nowplaying.ts b/src/interactions/commands/player/nowplaying.ts index 1527d71..78e2c91 100644 --- a/src/interactions/commands/player/nowplaying.ts +++ b/src/interactions/commands/player/nowplaying.ts @@ -12,7 +12,7 @@ import { } from 'discord.js'; import loggerModule from '../../../services/logger'; -import { CustomSlashCommandInteraction, TrackMetadata } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction, TrackMetadata } from '../../../types/interactionTypes'; import { EmbedOptions, PlayerOptions } from '../../../types/configTypes'; import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; @@ -21,7 +21,7 @@ import { Logger } from 'pino'; const embedOptions: EmbedOptions = config.get('embedOptions'); const playerOptions: PlayerOptions = config.get('playerOptions'); -const command: CustomSlashCommandInteraction = { +const command: BaseSlashCommandInteraction = { isNew: false, isBeta: false, data: new SlashCommandBuilder() diff --git a/src/interactions/commands/player/pause.ts b/src/interactions/commands/player/pause.ts index cb440f6..72d01c1 100644 --- a/src/interactions/commands/player/pause.ts +++ b/src/interactions/commands/player/pause.ts @@ -4,13 +4,13 @@ import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js'; import { Logger } from 'pino'; import loggerModule from '../../../services/logger'; import { EmbedOptions } from '../../../types/configTypes'; -import { CustomSlashCommandInteraction } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../types/interactionTypes'; import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; const embedOptions: EmbedOptions = config.get('embedOptions'); -const command: CustomSlashCommandInteraction = { +const command: BaseSlashCommandInteraction = { isNew: false, isBeta: false, data: new SlashCommandBuilder() diff --git a/src/interactions/commands/player/play.ts b/src/interactions/commands/player/play.ts index 59637a1..7bfbd9f 100644 --- a/src/interactions/commands/player/play.ts +++ b/src/interactions/commands/player/play.ts @@ -3,7 +3,7 @@ import { GuildQueue, useMainPlayer, useQueue } from 'discord-player'; import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js'; import loggerModule from '../../../services/logger'; -import { CustomError, CustomSlashCommandInteraction } from '../../../types/interactionTypes'; +import { CustomError, BaseSlashCommandInteraction } from '../../../types/interactionTypes'; import { BotOptions, EmbedOptions, PlayerOptions } from '../../../types/configTypes'; import { cannotJoinVoiceOrTalk } from '../../../utils/validation/permissionValidator'; import { transformQuery } from '../../../utils/validation/searchQueryValidator'; @@ -20,7 +20,7 @@ const loggerTemplate: Logger = loggerModule.child({ name: '/play' }); -const command: CustomSlashCommandInteraction = { +const command: BaseSlashCommandInteraction = { isNew: false, isBeta: false, data: new SlashCommandBuilder() diff --git a/src/interactions/commands/player/queue.ts b/src/interactions/commands/player/queue.ts index 846c154..2fb542a 100644 --- a/src/interactions/commands/player/queue.ts +++ b/src/interactions/commands/player/queue.ts @@ -4,14 +4,14 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; import { Logger } from 'pino'; import loggerModule from '../../../services/logger'; import { EmbedOptions, PlayerOptions } from '../../../types/configTypes'; -import { CustomSlashCommandInteraction } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../types/interactionTypes'; import { queueDoesNotExist } from '../../../utils/validation/queueValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; const embedOptions: EmbedOptions = config.get('embedOptions'); const playerOptions: PlayerOptions = config.get('playerOptions'); -const command: CustomSlashCommandInteraction = { +const command: BaseSlashCommandInteraction = { isNew: false, isBeta: false, data: new SlashCommandBuilder() diff --git a/src/interactions/commands/player/remove.ts b/src/interactions/commands/player/remove.ts index e219376..2cb40d4 100644 --- a/src/interactions/commands/player/remove.ts +++ b/src/interactions/commands/player/remove.ts @@ -4,13 +4,13 @@ import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js'; import { Logger } from 'pino'; import loggerModule from '../../../services/logger'; import { EmbedOptions } from '../../../types/configTypes'; -import { CustomSlashCommandInteraction } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../types/interactionTypes'; import { queueDoesNotExist } from '../../../utils/validation/queueValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; const embedOptions: EmbedOptions = config.get('embedOptions'); -const command: CustomSlashCommandInteraction = { +const command: BaseSlashCommandInteraction = { isNew: false, isBeta: false, data: new SlashCommandBuilder() diff --git a/src/interactions/commands/player/seek.ts b/src/interactions/commands/player/seek.ts index 690d404..8e10096 100644 --- a/src/interactions/commands/player/seek.ts +++ b/src/interactions/commands/player/seek.ts @@ -4,13 +4,13 @@ import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js'; import { Logger } from 'pino'; import loggerModule from '../../../services/logger'; import { EmbedOptions } from '../../../types/configTypes'; -import { CustomSlashCommandInteraction } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../types/interactionTypes'; import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; const embedOptions: EmbedOptions = config.get('embedOptions'); -const command: CustomSlashCommandInteraction = { +const command: BaseSlashCommandInteraction = { isNew: false, isBeta: false, data: new SlashCommandBuilder() diff --git a/src/interactions/commands/player/shuffle.ts b/src/interactions/commands/player/shuffle.ts index 722ede2..28b6821 100644 --- a/src/interactions/commands/player/shuffle.ts +++ b/src/interactions/commands/player/shuffle.ts @@ -4,13 +4,13 @@ import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js'; import { Logger } from 'pino'; import loggerModule from '../../../services/logger'; import { EmbedOptions } from '../../../types/configTypes'; -import { CustomSlashCommandInteraction } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../types/interactionTypes'; import { queueDoesNotExist, queueIsEmpty } from '../../../utils/validation/queueValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; const embedOptions: EmbedOptions = config.get('embedOptions'); -const command: CustomSlashCommandInteraction = { +const command: BaseSlashCommandInteraction = { isNew: false, isBeta: false, data: new SlashCommandBuilder() diff --git a/src/interactions/commands/player/skip.ts b/src/interactions/commands/player/skip.ts index 9e9386d..da803da 100644 --- a/src/interactions/commands/player/skip.ts +++ b/src/interactions/commands/player/skip.ts @@ -4,13 +4,13 @@ import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js'; import { Logger } from 'pino'; import loggerModule from '../../../services/logger'; import { EmbedOptions } from '../../../types/configTypes'; -import { CustomSlashCommandInteraction } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../types/interactionTypes'; import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; const embedOptions: EmbedOptions = config.get('embedOptions'); -const command: CustomSlashCommandInteraction = { +const command: BaseSlashCommandInteraction = { isNew: false, isBeta: false, data: new SlashCommandBuilder() diff --git a/src/interactions/commands/player/stop.ts b/src/interactions/commands/player/stop.ts index 5097f44..078a027 100644 --- a/src/interactions/commands/player/stop.ts +++ b/src/interactions/commands/player/stop.ts @@ -4,13 +4,13 @@ import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js'; import { Logger } from 'pino'; import loggerModule from '../../../services/logger'; import { EmbedOptions } from '../../../types/configTypes'; -import { CustomSlashCommandInteraction } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../types/interactionTypes'; import { queueDoesNotExist } from '../../../utils/validation/queueValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; const embedOptions: EmbedOptions = config.get('embedOptions'); -const command: CustomSlashCommandInteraction = { +const command: BaseSlashCommandInteraction = { isNew: false, isBeta: false, data: new SlashCommandBuilder() diff --git a/src/interactions/commands/player/test.ts b/src/interactions/commands/player/test.ts new file mode 100644 index 0000000..2c13c88 --- /dev/null +++ b/src/interactions/commands/player/test.ts @@ -0,0 +1,23 @@ +import { SlashCommandBuilder } from 'discord.js'; +import { BaseCommandInteraction, BaseSlashCommandParams } from '../../../types/interactionTypes'; + +export class TestCommandInteraction extends BaseCommandInteraction { + constructor() { + const data = new SlashCommandBuilder().setName('test').setDescription('Test command'); + super(data); + } + + async execute(params: BaseSlashCommandParams): Promise { + const { executionId, interaction } = params; + const logger = this.getLogger('test.ts', 'test', executionId, interaction); + + logger.info('test command executed'); + logger.info(`${interaction.user.tag} executed test command`); + logger.info(`Execution ID: ${executionId}`); + + logger.info(this.embedOptions.icons.success + ' Icon success from config.'); + return; + } +} + +export default new TestCommandInteraction(); diff --git a/src/interactions/commands/player/volume.ts b/src/interactions/commands/player/volume.ts index fe853a2..2f0f9a8 100644 --- a/src/interactions/commands/player/volume.ts +++ b/src/interactions/commands/player/volume.ts @@ -4,13 +4,13 @@ import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js'; import { Logger } from 'pino'; import loggerModule from '../../../services/logger'; import { EmbedOptions } from '../../../types/configTypes'; -import { CustomSlashCommandInteraction } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../types/interactionTypes'; import { queueDoesNotExist } from '../../../utils/validation/queueValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; const embedOptions: EmbedOptions = config.get('embedOptions'); -const command: CustomSlashCommandInteraction = { +const command: BaseSlashCommandInteraction = { isNew: false, isBeta: false, data: new SlashCommandBuilder() diff --git a/src/interactions/commands/system/guilds.ts b/src/interactions/commands/system/guilds.ts index 5e37f99..4641038 100644 --- a/src/interactions/commands/system/guilds.ts +++ b/src/interactions/commands/system/guilds.ts @@ -3,12 +3,12 @@ import { EmbedBuilder, Guild, SlashCommandBuilder } from 'discord.js'; import { Logger } from 'pino'; import loggerModule from '../../../services/logger'; import { EmbedOptions } from '../../../types/configTypes'; -import { CustomSlashCommandInteraction } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../types/interactionTypes'; import { notValidGuildId } from '../../../utils/validation/systemCommandValidator'; const embedOptions: EmbedOptions = config.get('embedOptions'); -const command: CustomSlashCommandInteraction = { +const command: BaseSlashCommandInteraction = { isSystemCommand: true, isNew: false, isBeta: false, diff --git a/src/interactions/commands/system/reload.ts b/src/interactions/commands/system/reload.ts index e39ad07..860db44 100644 --- a/src/interactions/commands/system/reload.ts +++ b/src/interactions/commands/system/reload.ts @@ -4,12 +4,12 @@ import { Logger } from 'pino'; import loggerModule from '../../../services/logger'; import { ExtendedClient } from '../../../types/clientTypes'; import { EmbedOptions } from '../../../types/configTypes'; -import { CustomSlashCommandInteraction } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../types/interactionTypes'; import { notValidGuildId } from '../../../utils/validation/systemCommandValidator'; const embedOptions: EmbedOptions = config.get('embedOptions'); -const command: CustomSlashCommandInteraction = { +const command: BaseSlashCommandInteraction = { isSystemCommand: true, isNew: false, isBeta: false, diff --git a/src/interactions/commands/system/shards.ts b/src/interactions/commands/system/shards.ts index 5123dda..12c2062 100644 --- a/src/interactions/commands/system/shards.ts +++ b/src/interactions/commands/system/shards.ts @@ -4,12 +4,12 @@ import { Logger } from 'pino'; import loggerModule from '../../../services/logger'; import { ExtendedClient } from '../../../types/clientTypes'; import { EmbedOptions } from '../../../types/configTypes'; -import { CustomSlashCommandInteraction, ShardInfo } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction, ShardInfo } from '../../../types/interactionTypes'; import { notValidGuildId } from '../../../utils/validation/systemCommandValidator'; const embedOptions: EmbedOptions = config.get('embedOptions'); -const command: CustomSlashCommandInteraction = { +const command: BaseSlashCommandInteraction = { isSystemCommand: true, isNew: false, isBeta: false, diff --git a/src/interactions/commands/system/systemstatus.ts b/src/interactions/commands/system/systemstatus.ts index 2ccfc24..a9abe42 100644 --- a/src/interactions/commands/system/systemstatus.ts +++ b/src/interactions/commands/system/systemstatus.ts @@ -4,7 +4,7 @@ import osu from 'node-os-utils'; // @ts-ignore import { dependencies, version } from '../../../../package.json'; import loggerModule from '../../../services/logger'; -import { CustomSlashCommandInteraction } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../types/interactionTypes'; import { EmbedOptions } from '../../../types/configTypes'; import { getUptimeFormatted } from '../../../utils/system/getUptimeFormatted'; import { notValidGuildId } from '../../../utils/validation/systemCommandValidator'; @@ -12,7 +12,7 @@ import { Logger } from 'pino'; const embedOptions: EmbedOptions = config.get('embedOptions'); -const command: CustomSlashCommandInteraction = { +const command: BaseSlashCommandInteraction = { isSystemCommand: true, isNew: false, isBeta: false, diff --git a/src/interactions/components/filters-disable-button.ts b/src/interactions/components/filters-disable-button.ts index 06957c3..019b266 100644 --- a/src/interactions/components/filters-disable-button.ts +++ b/src/interactions/components/filters-disable-button.ts @@ -4,12 +4,12 @@ import { EmbedBuilder, GuildMember } from 'discord.js'; import { Logger } from 'pino'; import loggerModule from '../../services/logger'; import { EmbedOptions } from '../../types/configTypes'; -import { CustomComponentInteraction } from '../../types/interactionTypes'; +import { BaseComponentInteraction } from '../../types/interactionTypes'; import { queueDoesNotExist } from '../../utils/validation/queueValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../utils/validation/voiceChannelValidator'; const embedOptions: EmbedOptions = config.get('embedOptions'); -const component: CustomComponentInteraction = { +const component: BaseComponentInteraction = { execute: async ({ interaction, executionId }) => { const logger: Logger = loggerModule.child({ source: 'filters-disable-button.js', diff --git a/src/interactions/components/filters-select-menu.ts b/src/interactions/components/filters-select-menu.ts index b15650a..cdac0f6 100644 --- a/src/interactions/components/filters-select-menu.ts +++ b/src/interactions/components/filters-select-menu.ts @@ -4,13 +4,13 @@ import { EmbedBuilder, GuildMember, StringSelectMenuInteraction } from 'discord. import { Logger } from 'pino'; import loggerModule from '../../services/logger'; import { EmbedOptions, FFmpegFilterOption, FFmpegFilterOptions } from '../../types/configTypes'; -import { CustomComponentInteraction } from '../../types/interactionTypes'; +import { BaseComponentInteraction } from '../../types/interactionTypes'; import { queueDoesNotExist } from '../../utils/validation/queueValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../utils/validation/voiceChannelValidator'; const embedOptions: EmbedOptions = config.get('embedOptions'); const ffmpegFilterOptions: FFmpegFilterOptions = config.get('ffmpegFilterOptions'); -const component: CustomComponentInteraction = { +const component: BaseComponentInteraction = { execute: async ({ interaction, executionId }) => { const logger: Logger = loggerModule.child({ source: 'filters-select-menu.js', diff --git a/src/interactions/components/nowplaying-skip-button.ts b/src/interactions/components/nowplaying-skip-button.ts index 41ea8cc..8015325 100644 --- a/src/interactions/components/nowplaying-skip-button.ts +++ b/src/interactions/components/nowplaying-skip-button.ts @@ -4,13 +4,13 @@ import { EmbedBuilder, GuildMember } from 'discord.js'; import loggerModule from '../../services/logger'; import { EmbedOptions } from '../../types/configTypes'; -import { CustomComponentInteraction } from '../../types/interactionTypes'; +import { BaseComponentInteraction } from '../../types/interactionTypes'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../utils/validation/voiceChannelValidator'; import { queueDoesNotExist, queueNoCurrentTrack } from '../../utils/validation/queueValidator'; import { Logger } from 'pino'; const embedOptions: EmbedOptions = config.get('embedOptions'); -const component: CustomComponentInteraction = { +const component: BaseComponentInteraction = { execute: async ({ interaction, referenceId, executionId }) => { const logger: Logger = loggerModule.child({ source: 'nowplaying-skip.js', diff --git a/src/types/clientTypes.ts b/src/types/clientTypes.ts index 921106b..dd99cd7 100644 --- a/src/types/clientTypes.ts +++ b/src/types/clientTypes.ts @@ -1,7 +1,9 @@ -import { Client, Collection, SharedNameAndDescription } from 'discord.js'; +import { Client, Collection } from 'discord.js'; +import { BaseCommandInteraction } from './interactionTypes'; type RegisterClientCommandsFunction = (params: { client: Client; executionId: string }) => void; +/* export interface Command { isNew?: boolean; isBeta?: boolean; @@ -14,8 +16,9 @@ export interface Command { execute: (params: { interaction: object; client: ExtendedClient | undefined; executionId: string }) => void; autocomplete?: (params: { interaction: object; executionId: string }) => void; } +*/ export interface ExtendedClient extends Client { registerClientCommands?: RegisterClientCommandsFunction; - commands?: Collection; + commands?: Collection; } diff --git a/src/types/interactionTypes.ts b/src/types/interactionTypes.ts index c7113da..89f392f 100644 --- a/src/types/interactionTypes.ts +++ b/src/types/interactionTypes.ts @@ -1,49 +1,53 @@ +import config from 'config'; import { ApplicationCommandOptionChoiceData, AutocompleteInteraction, ChatInputCommandInteraction, + Interaction, Message, MessageComponentInteraction, SlashCommandBuilder } from 'discord.js'; +import { Logger } from 'pino'; +import loggerModule from '../services/logger'; import { ExtendedClient } from './clientTypes'; +import { EmbedOptions } from './configTypes'; -// Local types -interface CommandParams { - client?: ExtendedClient; +interface BaseInteractionParams { executionId: string; - interaction: ChatInputCommandInteraction; } -interface AutocompleteParams { - executionId: string; +export interface BaseSlashCommandParams extends BaseInteractionParams { + interaction: ChatInputCommandInteraction; + client?: ExtendedClient; +} + +interface BaseAutocompleteParams { interaction: AutocompleteInteraction; } -interface ComponentParams { +interface BaseComponentParams { interaction: MessageComponentInteraction; referenceId?: string; - executionId: string; } // Interaction types -export interface CustomSlashCommandInteraction { +export interface BaseSlashCommandInteraction { isNew: boolean; isBeta: boolean; isSystemCommand?: boolean; data: Omit; - execute(params: CommandParams): Promise | void>; + execute(params: BaseSlashCommandParams): Promise | void>; } -export interface CustomAutocompleteInteraction { - execute(params: AutocompleteParams): Promise; +export interface BaseAutocompleteInteraction { + execute(params: BaseAutocompleteParams): Promise; } -export interface CustomComponentInteraction { - execute(params: ComponentParams): Promise | void>; +export interface BaseComponentInteraction { + execute(params: BaseComponentParams): Promise | void>; } -// Command specific types export interface ShardInfo { shardId: number; memUsage: number; @@ -66,3 +70,54 @@ export class CustomError extends Error { type?: string; code?: string; } + +abstract class BaseInteraction { + protected getLoggerBase( + module: string, + source: string, + name: string, + executionId: string, + interaction: Interaction + ): Logger { + return loggerModule.child({ + source: source, + module: module, + name: name, + executionId: executionId, + shardId: interaction.guild?.shardId, + guildId: interaction.guild?.id + }); + } + + abstract execute( + params: BaseInteractionParams + ): Promise | ApplicationCommandOptionChoiceData | void>; +} + +export abstract class BaseCommandInteraction extends BaseInteraction { + data: Omit; + isSystemCommand: boolean; + isNew: boolean; + isBeta: boolean; + embedOptions: EmbedOptions; + + constructor( + data: Omit, + isSystemCommand?: boolean, + isNew?: boolean, + isBeta?: boolean + ) { + super(); + this.data = data; + this.isSystemCommand = isSystemCommand || false; + this.isNew = isNew || false; + this.isBeta = isBeta || false; + this.embedOptions = config.get('embedOptions'); + } + + protected getLogger(source: string, name: string, executionId: string, interaction: Interaction): Logger { + return super.getLoggerBase('slashCommand', source, name, executionId, interaction); + } + + abstract execute(params: BaseSlashCommandParams): Promise | void>; +} diff --git a/src/utils/deploySlashCommands.ts b/src/utils/deploySlashCommands.ts index cd142dd..1db4a73 100644 --- a/src/utils/deploySlashCommands.ts +++ b/src/utils/deploySlashCommands.ts @@ -1,7 +1,13 @@ import 'dotenv/config'; import config from 'config'; -import { REST, RouteLike, Routes, SlashCommandBuilder } from 'discord.js'; +import { + REST, + RESTPostAPIChatInputApplicationCommandsJSONBody, + RouteLike, + Routes, + SlashCommandBuilder +} from 'discord.js'; import fs from 'node:fs'; import path from 'node:path'; import { v4 as uuidv4 } from 'uuid'; @@ -23,8 +29,8 @@ const logger: Logger = loggerModule.child({ //TODO: Fix deploying not working with require() -const slashCommands: SlashCommandBuilder[] = []; -const systemCommands: SlashCommandBuilder[] = []; +const slashCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[] = []; +const systemCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[] = []; const commandFolders: string[] = fs.readdirSync(path.resolve('./dist/interactions/commands')); if (!process.env.DISCORD_BOT_TOKEN) { @@ -45,6 +51,7 @@ const rest: REST = new REST({ version: '10' }).setToken(process.env.DISCORD_BOT_ process.exit(1); } + /* for (const folder of commandFolders) { const commandFiles: string[] = fs .readdirSync(path.resolve(`./dist/interactions/commands/${folder}`)) @@ -59,6 +66,11 @@ const rest: REST = new REST({ version: '10' }).setToken(process.env.DISCORD_BOT_ : slashCommands.push(command.data.toJSON()); } } + */ + + const commandModule = await import('../interactions/commands/player/test.js'); + const command = commandModule.default; + slashCommands.push(command.data.toJSON()); try { logger.debug(`Bot user slash commands found: ${slashCommands.map((command) => `/${command.name}`).join(', ')}`); diff --git a/src/utils/registerClientCommands.ts b/src/utils/registerClientCommands.ts index 7f4ca46..f251f1f 100644 --- a/src/utils/registerClientCommands.ts +++ b/src/utils/registerClientCommands.ts @@ -18,13 +18,15 @@ export const registerClientCommands = async ({ client, executionId }: RegisterCl logger.debug('Registering client commands...'); client.commands = new Collection(); + /* const commandFolders: string[] = fs.readdirSync(path.resolve('./dist/interactions/commands')); for (const folder of commandFolders) { logger.trace(`Registering client commands for folder '${folder}'...`); + const commandFiles: string[] = fs .readdirSync(path.resolve(`./dist/interactions/commands/${folder}`)) .filter((file) => file.endsWith('.js')); - + for (const file of commandFiles) { try { // delete command from require cache @@ -44,7 +46,15 @@ export const registerClientCommands = async ({ client, executionId }: RegisterCl } } } + } + */ + + const commandModule = await import('../interactions/commands/player/test.js'); + const command = commandModule.default; + + logger.info(command.data); + client.commands.set('test', command); logger.trace('Registering client commands complete.'); };