diff --git a/src/interactions/autocomplete/lyrics.ts b/src/interactions/autocomplete/lyrics.ts index 8094edf..ae2c12b 100644 --- a/src/interactions/autocomplete/lyrics.ts +++ b/src/interactions/autocomplete/lyrics.ts @@ -1,29 +1,25 @@ import { LyricsData, lyricsExtractor } from '@discord-player/extractor'; import { Player, SearchResult, useMainPlayer } from 'discord-player'; import { ApplicationCommandOptionChoiceData } from 'discord.js'; -import { Logger } from 'pino'; -import loggerModule from '../../services/logger'; -import { BaseAutocompleteInteraction } from '../../types/interactionTypes'; - -const loggerTemplate: Logger = loggerModule.child({ - source: 'lyrics.js', - module: 'autocompleteInteraction', - name: '/lyrics' -}); +import { + BaseAutocompleteInteraction, + BaseAutocompleteParams, + BaseAutocompleteReturnType +} from '../../types/interactionTypes'; // TODO: create interface for recent query object const recentQueries = new Map(); -const autocomplete: BaseAutocompleteInteraction = { - execute: async ({ interaction, executionId }) => { - const logger: Logger = loggerTemplate.child({ - executionId: executionId, - shardId: interaction.guild?.shardId, - guildId: interaction.guild?.id - }); +class LyricsAutocomplete extends BaseAutocompleteInteraction { + constructor() { + super('lyrics'); + } + + async execute(params: BaseAutocompleteParams): BaseAutocompleteReturnType { + const { executionId, interaction } = params; + const logger = this.getLogger(this.name, executionId, interaction); const query: string = interaction.options.getString('query', true); - const { lastQuery, result, timestamp } = recentQueries.get(interaction.user.id); if (lastQuery && (query.startsWith(lastQuery) || lastQuery.startsWith(query)) && Date.now() - timestamp < 500) { @@ -76,6 +72,6 @@ const autocomplete: BaseAutocompleteInteraction = { logger.debug(`Responding to autocomplete with results for query: '${query}'.`); return interaction.respond(response); } -}; +} -export default autocomplete; +export default new LyricsAutocomplete(); diff --git a/src/interactions/autocomplete/play.ts b/src/interactions/autocomplete/play.ts index 57f78c5..0b34fee 100644 --- a/src/interactions/autocomplete/play.ts +++ b/src/interactions/autocomplete/play.ts @@ -1,25 +1,22 @@ import { Player, SearchResult, useMainPlayer } from 'discord-player'; import { ApplicationCommandOptionChoiceData } from 'discord.js'; -import { Logger } from 'pino'; -import loggerModule from '../../services/logger'; -import { BaseAutocompleteInteraction } from '../../types/interactionTypes'; - -const loggerTemplate: Logger = loggerModule.child({ - source: 'play.js', - module: 'autocompleteInteraction', - name: '/play' -}); +import { + BaseAutocompleteInteraction, + BaseAutocompleteParams, + BaseAutocompleteReturnType +} from '../../types/interactionTypes'; // TODO: create interface for recent query object const recentQueries = new Map(); -const autocomplete: BaseAutocompleteInteraction = { - execute: async ({ interaction, executionId }) => { - const logger: Logger = loggerTemplate.child({ - executionId: executionId, - shardId: interaction.guild?.shardId, - guildId: interaction.guild?.id - }); +class PlayAutocomplete extends BaseAutocompleteInteraction { + constructor() { + super('play'); + } + + async execute(params: BaseAutocompleteParams): BaseAutocompleteReturnType { + const { executionId, interaction } = params; + const logger = this.getLogger(this.name, executionId, interaction); const player: Player = useMainPlayer()!; const query: string = interaction.options.getString('query', true); @@ -66,6 +63,6 @@ const autocomplete: BaseAutocompleteInteraction = { logger.debug(`Responding to autocomplete with results for query: '${query}'.`); return interaction.respond(response); } -}; +} -export default autocomplete; +export default new PlayAutocomplete(); diff --git a/src/interactions/commands/info/help.ts b/src/interactions/commands/info/help.ts index 2f98c3e..d8801f3 100644 --- a/src/interactions/commands/info/help.ts +++ b/src/interactions/commands/info/help.ts @@ -9,13 +9,13 @@ class HelpCommand extends BaseSlashCommandInteraction { constructor() { const data = new SlashCommandBuilder() .setName('help') - .setDescription('Show a list of commands and their usage.'); + .setDescription('Show the list of bot commands.'); super(data); } async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { const { executionId, client, interaction } = params; - const logger = this.getLogger('help.js', executionId, interaction); + const logger = this.getLogger(this.name, executionId, interaction); const commandList = client! .commands!.filter((command: BaseSlashCommandInteraction) => { diff --git a/src/interactions/commands/info/status.ts b/src/interactions/commands/info/status.ts index 47582ce..d4830a2 100644 --- a/src/interactions/commands/info/status.ts +++ b/src/interactions/commands/info/status.ts @@ -11,13 +11,13 @@ import { getUptimeFormatted } from '../../../utils/system/getUptimeFormatted'; class StatusCommand extends BaseSlashCommandInteraction { constructor() { - const data = new SlashCommandBuilder().setName('status').setDescription('Show the bot and system status.'); + const data = new SlashCommandBuilder().setName('status').setDescription('Show operational status of the bot.'); super(data); } async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { const { executionId, interaction, client } = params; - const logger = this.getLogger('status.js', executionId, interaction); + const logger = this.getLogger(this.name, executionId, interaction); const uptimeString: string = await getUptimeFormatted({ executionId }); const usedMemoryInMB: string = Math.ceil((await osu.mem.info()).usedMemMb).toLocaleString('en-US'); diff --git a/src/interactions/commands/player/filters.ts b/src/interactions/commands/player/filters.ts index 58327f2..5380e53 100644 --- a/src/interactions/commands/player/filters.ts +++ b/src/interactions/commands/player/filters.ts @@ -28,13 +28,13 @@ class FiltersCommand extends BaseSlashCommandInteraction { constructor() { const data = new SlashCommandBuilder() .setName('filters') - .setDescription('Toggle various audio filters during playback.'); + .setDescription('Toggle various audio filters.'); super(data); } async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { const { executionId, interaction } = params; - const logger = this.getLogger(this.commandName, executionId, interaction); + const logger = this.getLogger(this.name, executionId, interaction); const queue: GuildQueue = useQueue(interaction.guild!.id)!; diff --git a/src/interactions/commands/player/leave.ts b/src/interactions/commands/player/leave.ts index b7ce843..62303cb 100644 --- a/src/interactions/commands/player/leave.ts +++ b/src/interactions/commands/player/leave.ts @@ -12,13 +12,13 @@ class LeaveCommand extends BaseSlashCommandInteraction { constructor() { const data = new SlashCommandBuilder() .setName('leave') - .setDescription('Clear the track queue and remove the bot from voice channel.'); + .setDescription('Clear the queue and remove bot from voice channel.'); super(data); } async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { const { executionId, interaction } = params; - const logger = this.getLogger(this.commandName, executionId, interaction); + const logger = this.getLogger(this.name, executionId, interaction); const queue: GuildQueue = useQueue(interaction.guild!.id)!; diff --git a/src/interactions/commands/player/loop.ts b/src/interactions/commands/player/loop.ts index 1f4868c..92f32f7 100644 --- a/src/interactions/commands/player/loop.ts +++ b/src/interactions/commands/player/loop.ts @@ -16,7 +16,7 @@ class LoopCommand extends BaseSlashCommandInteraction { .addStringOption(() => new SlashCommandStringOption() .setName('mode') - .setDescription('Mode to set for looping.') + .setDescription('Loop mode: Track, queue, autoplay or disabled.') .setRequired(false) .addChoices( { name: 'Track', value: '1' }, @@ -30,7 +30,7 @@ class LoopCommand extends BaseSlashCommandInteraction { async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { const { executionId, interaction } = params; - const logger = this.getLogger(this.commandName, executionId, interaction); + const logger = this.getLogger(this.name, executionId, interaction); const queue: GuildQueue = useQueue(interaction.guild!.id)!; diff --git a/src/interactions/commands/player/lyrics.ts b/src/interactions/commands/player/lyrics.ts index 63ea313..0350e03 100644 --- a/src/interactions/commands/player/lyrics.ts +++ b/src/interactions/commands/player/lyrics.ts @@ -13,11 +13,11 @@ class LyricsCommand extends BaseSlashCommandInteraction { constructor() { const data = new SlashCommandBuilder() .setName('lyrics') - .setDescription('Get lyrics from Genius for current or specified track.') + .setDescription('Search Genius lyrics for current or specified track.') .addStringOption((option) => option .setName('query') - .setDescription('Search query or URL.') + .setDescription('Search query by text or URL.') .setRequired(false) .setMinLength(2) .setMaxLength(500) @@ -28,7 +28,7 @@ class LyricsCommand extends BaseSlashCommandInteraction { async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { const { executionId, interaction } = params; - const logger = this.getLogger(this.commandName, executionId, interaction); + const logger = this.getLogger(this.name, executionId, interaction); const query: string = interaction.options.getString('query')!; const queue: GuildQueue = useQueue(interaction.guild!.id)!; diff --git a/src/interactions/commands/player/nowplaying.ts b/src/interactions/commands/player/nowplaying.ts index 5328eb0..cb46422 100644 --- a/src/interactions/commands/player/nowplaying.ts +++ b/src/interactions/commands/player/nowplaying.ts @@ -26,13 +26,13 @@ class NowPlayingCommand extends BaseSlashCommandInteraction { constructor() { const data = new SlashCommandBuilder() .setName('nowplaying') - .setDescription('Show information about the track currently playing.'); + .setDescription('Show information about the current track.'); super(data); } async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { const { executionId, interaction } = params; - const logger = this.getLogger(this.commandName, executionId, interaction); + const logger = this.getLogger(this.name, executionId, interaction); const queue: GuildQueue = useQueue(interaction.guild!.id)!; diff --git a/src/interactions/commands/player/pause.ts b/src/interactions/commands/player/pause.ts index 0e46501..0ff6c73 100644 --- a/src/interactions/commands/player/pause.ts +++ b/src/interactions/commands/player/pause.ts @@ -11,13 +11,13 @@ import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validat class PauseCommand extends BaseSlashCommandInteraction { constructor() { - const data = new SlashCommandBuilder().setName('pause').setDescription('Pause or resume the current track.'); + const data = new SlashCommandBuilder().setName('pause').setDescription('Toggle pause for the current track.'); super(data); } async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { const { executionId, interaction } = params; - const logger = this.getLogger(this.commandName, executionId, interaction); + const logger = this.getLogger(this.name, executionId, interaction); const queue: GuildQueue = useQueue(interaction.guild!.id)!; diff --git a/src/interactions/commands/player/play.ts b/src/interactions/commands/player/play.ts index 716ae2c..26f69df 100644 --- a/src/interactions/commands/player/play.ts +++ b/src/interactions/commands/player/play.ts @@ -18,11 +18,11 @@ class PlayCommand extends BaseSlashCommandInteraction { constructor() { const data = new SlashCommandBuilder() .setName('play') - .setDescription('Add a track or playlist to the queue by searching or url.') + .setDescription('Add a track or playlist to the queue by search query or URL.') .addStringOption((option) => option .setName('query') - .setDescription('Search query or URL.') + .setDescription('Search query by text or URL') .setRequired(true) .setMinLength(2) .setMaxLength(500) @@ -33,7 +33,7 @@ class PlayCommand extends BaseSlashCommandInteraction { async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { const { executionId, interaction } = params; - const logger = this.getLogger(this.commandName, executionId, interaction); + const logger = this.getLogger(this.name, executionId, interaction); let queue: GuildQueue = useQueue(interaction.guild!.id)!; if (queue && (await notInSameVoiceChannel({ interaction, queue, executionId }))) { diff --git a/src/interactions/commands/player/queue.ts b/src/interactions/commands/player/queue.ts index df46158..95b83d7 100644 --- a/src/interactions/commands/player/queue.ts +++ b/src/interactions/commands/player/queue.ts @@ -17,16 +17,16 @@ class QueueCommand extends BaseSlashCommandInteraction { constructor() { const data = new SlashCommandBuilder() .setName('queue') - .setDescription('Show the list of tracks added to the queue.') + .setDescription('Show tracks that have been added to the queue.') .addNumberOption((option) => - option.setName('page').setDescription('Page number of the queue').setMinValue(1) + option.setName('page').setDescription('Page number to display for the queue').setMinValue(1) ); super(data); } async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { const { executionId, interaction } = params; - const logger = this.getLogger(this.commandName, executionId, interaction); + const logger = this.getLogger(this.name, executionId, interaction); const queue: GuildQueue = useQueue(interaction.guild!.id)!; diff --git a/src/interactions/commands/player/remove.ts b/src/interactions/commands/player/remove.ts index 860d34a..b21a31c 100644 --- a/src/interactions/commands/player/remove.ts +++ b/src/interactions/commands/player/remove.ts @@ -12,11 +12,11 @@ class RemoveCommand extends BaseSlashCommandInteraction { constructor() { const data = new SlashCommandBuilder() .setName('remove') - .setDescription('Remove a specific track from the queue') + .setDescription('Remove specified track from the queue') .addNumberOption((option) => option .setName('tracknumber') - .setDescription('Track number to remove from queue.') + .setDescription('The position in queue for track to remove.') .setMinValue(1) .setRequired(true) ); @@ -25,7 +25,7 @@ class RemoveCommand extends BaseSlashCommandInteraction { async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { const { executionId, interaction } = params; - const logger = this.getLogger(this.commandName, executionId, interaction); + const logger = this.getLogger(this.name, executionId, interaction); const queue: GuildQueue = useQueue(interaction.guild!.id)!; diff --git a/src/interactions/commands/player/seek.ts b/src/interactions/commands/player/seek.ts index e7f9c09..c39651b 100644 --- a/src/interactions/commands/player/seek.ts +++ b/src/interactions/commands/player/seek.ts @@ -12,11 +12,11 @@ class SeekCommand extends BaseSlashCommandInteraction { constructor() { const data = new SlashCommandBuilder() .setName('seek') - .setDescription('Seek to a specified duration in the current track.') + .setDescription('Seek to a duration in the current track.') .addStringOption((option) => option .setName('duration') - .setDescription('Duration in format 00:00:00 (HH:mm:ss) to seek to.') + .setDescription('Duration in format 00:00:00 (HH:mm:ss).') .setRequired(true) ); super(data); @@ -24,7 +24,7 @@ class SeekCommand extends BaseSlashCommandInteraction { async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { const { executionId, interaction } = params; - const logger = this.getLogger(this.commandName, executionId, interaction); + const logger = this.getLogger(this.name, executionId, interaction); const queue: GuildQueue = useQueue(interaction.guild!.id)!; diff --git a/src/interactions/commands/player/shuffle.ts b/src/interactions/commands/player/shuffle.ts index 59f584b..d870195 100644 --- a/src/interactions/commands/player/shuffle.ts +++ b/src/interactions/commands/player/shuffle.ts @@ -12,13 +12,13 @@ class ShuffleCommand extends BaseSlashCommandInteraction { constructor() { const data = new SlashCommandBuilder() .setName('shuffle') - .setDescription('Shuffle tracks in the queue randomly.'); + .setDescription('Randomly shuffle all tracks in the queue.'); super(data); } async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { const { executionId, interaction } = params; - const logger = this.getLogger(this.commandName, executionId, interaction); + const logger = this.getLogger(this.name, executionId, interaction); const queue: GuildQueue = useQueue(interaction.guild!.id)!; diff --git a/src/interactions/commands/player/skip.ts b/src/interactions/commands/player/skip.ts index 66dc648..34f1c97 100644 --- a/src/interactions/commands/player/skip.ts +++ b/src/interactions/commands/player/skip.ts @@ -12,16 +12,16 @@ class SkipCommand extends BaseSlashCommandInteraction { constructor() { const data = new SlashCommandBuilder() .setName('test') - .setDescription('Skip current or specified track.') + .setDescription('Skip track to next or specified position in queue.') .addNumberOption((option) => - option.setName('tracknumber').setDescription('Track number to skip to in the queue.').setMinValue(1) + option.setName('tracknumber').setDescription('The position in queue to skip to.').setMinValue(1) ); super(data); } async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { const { executionId, interaction } = params; - const logger = this.getLogger(this.commandName, executionId, interaction); + const logger = this.getLogger(this.name, executionId, interaction); const queue: GuildQueue = useQueue(interaction.guild!.id)!; diff --git a/src/interactions/commands/player/stop.ts b/src/interactions/commands/player/stop.ts index 68554a1..620d3fd 100644 --- a/src/interactions/commands/player/stop.ts +++ b/src/interactions/commands/player/stop.ts @@ -12,13 +12,13 @@ class StopCommand extends BaseSlashCommandInteraction { constructor() { const data = new SlashCommandBuilder() .setName('stop') - .setDescription('Stop playing audio and clear the track queue.'); + .setDescription('Clear the queue and stop playing audio.'); super(data); } async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { const { executionId, interaction } = params; - const logger = this.getLogger(this.commandName, executionId, interaction); + const logger = this.getLogger(this.name, executionId, interaction); const queue: GuildQueue = useQueue(interaction.guild!.id)!; diff --git a/src/interactions/commands/player/volume.ts b/src/interactions/commands/player/volume.ts index e3e255b..18779e6 100644 --- a/src/interactions/commands/player/volume.ts +++ b/src/interactions/commands/player/volume.ts @@ -12,11 +12,11 @@ class VolumeCommand extends BaseSlashCommandInteraction { constructor() { const data = new SlashCommandBuilder() .setName('volume') - .setDescription('Show or set the playback volume for tracks.') + .setDescription('Show or change the playback volume for tracks.') .addNumberOption((option) => option .setName('percentage') - .setDescription('Set volume percentage from 1% to 100%.') + .setDescription('Volume percentage: From 1% to 100%.') .setMinValue(0) .setMaxValue(100) ); @@ -25,7 +25,7 @@ class VolumeCommand extends BaseSlashCommandInteraction { async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { const { executionId, interaction } = params; - const logger = this.getLogger(this.commandName, executionId, interaction); + const logger = this.getLogger(this.name, executionId, interaction); const queue: GuildQueue = useQueue(interaction.guild!.id)!; diff --git a/src/interactions/commands/system/guilds.ts b/src/interactions/commands/system/guilds.ts index d2ed62a..0213822 100644 --- a/src/interactions/commands/system/guilds.ts +++ b/src/interactions/commands/system/guilds.ts @@ -10,13 +10,14 @@ class GuildsCommand extends BaseSlashCommandInteraction { constructor() { const data = new SlashCommandBuilder() .setName('guilds') - .setDescription('Show list of guilds where bot is added.'); - super(data); + .setDescription('Show the top 25 guilds by member count.'); + const isSystemCommand: boolean = true; + super(data, isSystemCommand); } async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { const { executionId, interaction, client } = params; - const logger = this.getLogger(this.commandName, executionId, interaction); + const logger = this.getLogger(this.name, executionId, interaction); if (await notValidGuildId({ interaction, executionId })) { return; diff --git a/src/interactions/commands/system/reload.ts b/src/interactions/commands/system/reload.ts index a134b79..eb4ed5f 100644 --- a/src/interactions/commands/system/reload.ts +++ b/src/interactions/commands/system/reload.ts @@ -9,13 +9,16 @@ import { notValidGuildId } from '../../../utils/validation/systemCommandValidato class ReloadCommand extends BaseSlashCommandInteraction { constructor() { - const data = new SlashCommandBuilder().setName('reload').setDescription('Reload the bot commands.'); - super(data); + const data = new SlashCommandBuilder() + .setName('reload') + .setDescription('Reload all slash commands across shards.'); + const isSystemCommand: boolean = true; + super(data, isSystemCommand); } async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { const { executionId, interaction, client } = params; - const logger = this.getLogger(this.commandName, executionId, interaction); + const logger = this.getLogger(this.name, executionId, interaction); if (await notValidGuildId({ interaction, executionId })) { return; diff --git a/src/interactions/commands/system/shards.ts b/src/interactions/commands/system/shards.ts index c683789..d7ccdaf 100644 --- a/src/interactions/commands/system/shards.ts +++ b/src/interactions/commands/system/shards.ts @@ -12,11 +12,11 @@ class ShardsCommand extends BaseSlashCommandInteraction { constructor() { const data = new SlashCommandBuilder() .setName('shards') - .setDescription('Show information about the running shards.') + .setDescription('Show information about all connected shards.') .addStringOption((option) => option .setName('sort') - .setDescription('If specified, what to sort the shards by.') + .setDescription('What to sort the shards by.') .setRequired(false) .addChoices( { name: 'None (Shard ID)', value: 'none' }, @@ -28,13 +28,16 @@ class ShardsCommand extends BaseSlashCommandInteraction { { name: 'Members', value: 'members' } ) ) - .addNumberOption((option) => option.setName('page').setDescription('Page number to show').setMinValue(1)); - super(data); + .addNumberOption((option) => + option.setName('page').setDescription('Page number to display for the shards').setMinValue(1) + ); + const isSystemCommand: boolean = true; + super(data, isSystemCommand); } async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { const { executionId, interaction, client } = params; - const logger = this.getLogger(this.commandName, executionId, interaction); + const logger = this.getLogger(this.name, executionId, interaction); if (await notValidGuildId({ interaction, executionId })) { return; diff --git a/src/interactions/commands/system/systemstatus.ts b/src/interactions/commands/system/systemstatus.ts index d2ef93f..93d238c 100644 --- a/src/interactions/commands/system/systemstatus.ts +++ b/src/interactions/commands/system/systemstatus.ts @@ -14,13 +14,14 @@ class SystemStatusCommand extends BaseSlashCommandInteraction { constructor() { const data = new SlashCommandBuilder() .setName('systemstatus') - .setDescription('Show the bot and system status.'); - super(data); + .setDescription('Show operational status of the bot with additional technical information.'); + const isSystemCommand: boolean = true; + super(data, isSystemCommand); } async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { const { executionId, interaction, client } = params; - const logger = this.getLogger(this.commandName, executionId, interaction); + const logger = this.getLogger(this.name, executionId, interaction); if (await notValidGuildId({ interaction, executionId })) { return; diff --git a/src/interactions/components/filters-disable-button.ts b/src/interactions/components/filters-disable-button.ts index 019b266..ca814eb 100644 --- a/src/interactions/components/filters-disable-button.ts +++ b/src/interactions/components/filters-disable-button.ts @@ -1,26 +1,17 @@ -import config from 'config'; import { GuildQueue, useQueue } from 'discord-player'; import { EmbedBuilder, GuildMember } from 'discord.js'; -import { Logger } from 'pino'; -import loggerModule from '../../services/logger'; -import { EmbedOptions } from '../../types/configTypes'; -import { BaseComponentInteraction } from '../../types/interactionTypes'; +import { BaseComponentInteraction, BaseComponentParams, BaseComponentReturnType } from '../../types/interactionTypes'; import { queueDoesNotExist } from '../../utils/validation/queueValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../utils/validation/voiceChannelValidator'; -const embedOptions: EmbedOptions = config.get('embedOptions'); -const component: BaseComponentInteraction = { - execute: async ({ interaction, executionId }) => { - const logger: Logger = loggerModule.child({ - source: 'filters-disable-button.js', - module: 'componentInteraction', - name: 'filters-disable-button', - executionId: executionId, - shardId: interaction.guild?.shardId, - guildId: interaction.guild?.id - }); +class FiltersDisableButtonComponent extends BaseComponentInteraction { + constructor() { + super('filters-disable-button'); + } - logger.debug('Received disable confirmation.'); + async execute(params: BaseComponentParams): BaseComponentReturnType { + const { executionId, interaction } = params; + const logger = this.getLogger(this.name, executionId, interaction); const queue: GuildQueue = useQueue(interaction.guild!.id)!; @@ -56,16 +47,16 @@ const component: BaseComponentInteraction = { new EmbedBuilder() .setAuthor({ name: authorName, - iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl + iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl }) .setDescription( - `**${embedOptions.icons.success} Disabled filters**\nAll audio filters have been disabled.` + `**${this.embedOptions.icons.success} Disabled filters**\nAll audio filters have been disabled.` ) - .setColor(embedOptions.colors.success) + .setColor(this.embedOptions.colors.success) ], components: [] }); } -}; +} -export default component; +export default new FiltersDisableButtonComponent(); diff --git a/src/interactions/components/filters-select-menu.ts b/src/interactions/components/filters-select-menu.ts index cdac0f6..e35cae7 100644 --- a/src/interactions/components/filters-select-menu.ts +++ b/src/interactions/components/filters-select-menu.ts @@ -1,25 +1,20 @@ import config from 'config'; import { GuildQueue, QueueFilters, useQueue } from 'discord-player'; import { EmbedBuilder, GuildMember, StringSelectMenuInteraction } from 'discord.js'; -import { Logger } from 'pino'; -import loggerModule from '../../services/logger'; -import { EmbedOptions, FFmpegFilterOption, FFmpegFilterOptions } from '../../types/configTypes'; -import { BaseComponentInteraction } from '../../types/interactionTypes'; +import { FFmpegFilterOption, FFmpegFilterOptions } from '../../types/configTypes'; +import { BaseComponentInteraction, BaseComponentParams, BaseComponentReturnType } 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: BaseComponentInteraction = { - execute: async ({ interaction, executionId }) => { - const logger: Logger = loggerModule.child({ - source: 'filters-select-menu.js', - module: 'componentInteraction', - name: 'filters-select-menu', - executionId: executionId, - shardId: interaction.guild?.shardId, - guildId: interaction.guild?.id - }); +class FiltersSelectMenuComponent extends BaseComponentInteraction { + constructor() { + super('filters-select-menu'); + } + + async execute(params: BaseComponentParams): BaseComponentReturnType { + const { executionId, interaction } = params; + const logger = this.getLogger(this.name, executionId, interaction); logger.debug('Received select menu confirmation.'); @@ -87,7 +82,7 @@ const component: BaseComponentInteraction = { }) .setDescription( `**${ - embedOptions.icons.success + this.embedOptions.icons.success } Filters toggled**\nNow using these filters:\n${selectMenuInteraction.values .map((enabledFilter: string) => { const filter: FFmpegFilterOption | undefined = @@ -103,11 +98,11 @@ const component: BaseComponentInteraction = { }) .join('\n')}` ) - .setColor(embedOptions.colors.success) + .setColor(this.embedOptions.colors.success) ], components: [] }); } -}; +} -export default component; +export default new FiltersSelectMenuComponent(); diff --git a/src/interactions/components/nowplaying-skip-button.ts b/src/interactions/components/nowplaying-skip-button.ts index 8015325..e3cfec4 100644 --- a/src/interactions/components/nowplaying-skip-button.ts +++ b/src/interactions/components/nowplaying-skip-button.ts @@ -1,27 +1,17 @@ -import config from 'config'; import { GuildQueue, Track, useQueue } from 'discord-player'; import { EmbedBuilder, GuildMember } from 'discord.js'; - -import loggerModule from '../../services/logger'; -import { EmbedOptions } from '../../types/configTypes'; -import { BaseComponentInteraction } from '../../types/interactionTypes'; -import { notInSameVoiceChannel, notInVoiceChannel } from '../../utils/validation/voiceChannelValidator'; +import { BaseComponentInteraction, BaseComponentParams, BaseComponentReturnType } from '../../types/interactionTypes'; import { queueDoesNotExist, queueNoCurrentTrack } from '../../utils/validation/queueValidator'; -import { Logger } from 'pino'; -const embedOptions: EmbedOptions = config.get('embedOptions'); +import { notInSameVoiceChannel, notInVoiceChannel } from '../../utils/validation/voiceChannelValidator'; -const component: BaseComponentInteraction = { - execute: async ({ interaction, referenceId, executionId }) => { - const logger: Logger = loggerModule.child({ - source: 'nowplaying-skip.js', - module: 'componentInteraction', - name: 'nowplaying-skip', - executionId: executionId, - shardId: interaction.guild?.shardId, - guildId: interaction.guild?.id - }); +class NowplayingSkipButton extends BaseComponentInteraction { + constructor() { + super('nowplaying-skip-button'); + } - logger.debug(`Received skip confirmation for track id ${referenceId}.`); + async execute(params: BaseComponentParams): BaseComponentReturnType { + const { executionId, interaction, referenceId } = params; + const logger = this.getLogger(this.name, executionId, interaction); const queue: GuildQueue = useQueue(interaction.guild!.id)!; @@ -46,9 +36,9 @@ const component: BaseComponentInteraction = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedOptions.icons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with **\`/play\`**!` + `**${this.embedOptions.icons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with **\`/play\`**!` ) - .setColor(embedOptions.colors.warning) + .setColor(this.embedOptions.colors.warning) ], components: [] }); @@ -62,9 +52,9 @@ const component: BaseComponentInteraction = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedOptions.icons.warning} Oops!**\nThis track has already been skipped or is no longer playing.` + `**${this.embedOptions.icons.warning} Oops!**\nThis track has already been skipped or is no longer playing.` ) - .setColor(embedOptions.colors.warning) + .setColor(this.embedOptions.colors.warning) ], components: [] }); @@ -77,7 +67,7 @@ const component: BaseComponentInteraction = { : `\`${skippedTrack.duration}\``; if (skippedTrack.raw.live) { - durationFormat = `${embedOptions.icons.liveTrack} \`LIVE\``; + durationFormat = `${this.embedOptions.icons.liveTrack} \`LIVE\``; } queue.node.skip(); logger.debug('Skipped the track.'); @@ -105,28 +95,28 @@ const component: BaseComponentInteraction = { new EmbedBuilder() .setAuthor({ name: authorName, - iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl + iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl }) .setDescription( - `**${embedOptions.icons.skipped} Skipped track**\n**${durationFormat} [${skippedTrack.title}](${ - skippedTrack.raw.url ?? skippedTrack.url - })**` + + `**${this.embedOptions.icons.skipped} Skipped track**\n**${durationFormat} [${ + skippedTrack.title + }](${skippedTrack.raw.url ?? skippedTrack.url})**` + `${ queue.repeatMode === 0 ? '' : `\n\n**${ queue.repeatMode === 3 - ? embedOptions.icons.autoplaying - : embedOptions.icons.looping + ? this.embedOptions.icons.autoplaying + : this.embedOptions.icons.looping } Looping**\nLoop mode is set to ${repeatModeUserString}. You can change it with **\`/loop\`**.` }` ) .setThumbnail(skippedTrack.thumbnail) - .setColor(embedOptions.colors.success) + .setColor(this.embedOptions.colors.success) ], components: [] }); } -}; +} -export default component; +export default new NowplayingSkipButton(); diff --git a/src/types/interactionTypes.ts b/src/types/interactionTypes.ts index 8c8723f..9bc3f4f 100644 --- a/src/types/interactionTypes.ts +++ b/src/types/interactionTypes.ts @@ -13,36 +13,6 @@ import loggerModule from '../services/logger'; import { ExtendedClient } from './clientTypes'; import { BotOptions, EmbedOptions } from './configTypes'; -interface BaseInteractionParams { - executionId: string; -} - -export interface BaseSlashCommandParams extends BaseInteractionParams { - interaction: ChatInputCommandInteraction; - client?: ExtendedClient; -} - -export type BaseSlashCommandReturnType = Promise | void>; - -interface BaseAutocompleteParams extends BaseInteractionParams { - interaction: AutocompleteInteraction; -} - -interface BaseComponentParams extends BaseInteractionParams { - interaction: MessageComponentInteraction; - referenceId?: string; -} - -// Interaction types - -export interface BaseAutocompleteInteraction { - execute(params: BaseAutocompleteParams): Promise; -} - -export interface BaseComponentInteraction { - execute(params: BaseComponentParams): Promise | void>; -} - export interface ShardInfo { shardId: number; memUsage: number; @@ -66,8 +36,37 @@ export class CustomError extends Error { code?: string; } +interface BaseInteractionParams { + executionId: string; +} + +export interface BaseSlashCommandParams extends BaseInteractionParams { + interaction: ChatInputCommandInteraction; + client?: ExtendedClient; +} + +export interface BaseAutocompleteParams extends BaseInteractionParams { + interaction: AutocompleteInteraction; +} + +export interface BaseComponentParams extends BaseInteractionParams { + interaction: MessageComponentInteraction; + referenceId?: string; +} + +export type BaseSlashCommandReturnType = Promise | void>; + +export type BaseAutocompleteReturnType = Promise; + +export type BaseComponentReturnType = Promise | void>; + abstract class BaseInteraction { - protected getLoggerBase(module: string, name: string, executionId: string, interaction: Interaction): Logger { + protected getLoggerBase( + module: string, + name: string, + executionId: string, + interaction: Interaction | MessageComponentInteraction + ): Logger { return loggerModule.child({ module: module, name: name, @@ -89,7 +88,7 @@ export abstract class BaseSlashCommandInteraction extends BaseInteraction { isBeta: boolean; embedOptions: EmbedOptions; botOptions: BotOptions; - commandName: string; + name: string; constructor( data: Omit, @@ -104,12 +103,46 @@ export abstract class BaseSlashCommandInteraction extends BaseInteraction { this.isBeta = isBeta; this.embedOptions = config.get('embedOptions'); this.botOptions = config.get('botOptions'); - this.commandName = data.name; + this.name = data.name; } - protected getLogger(name: string, executionId: string, interaction: Interaction): Logger { - return super.getLoggerBase('slashCommand', name, executionId, interaction); + protected getLogger(name: string, executionId: string, interaction: ChatInputCommandInteraction): Logger { + return super.getLoggerBase('slashCommandInteraction', name, executionId, interaction); } abstract execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType; } + +export abstract class BaseAutocompleteInteraction extends BaseInteraction { + name: string; + + constructor(name: string) { + super(); + this.name = name; + } + + protected getLogger(name: string, executionId: string, interaction: AutocompleteInteraction): Logger { + return super.getLoggerBase('autocompleteInteraction', name, executionId, interaction); + } + + abstract execute(params: BaseAutocompleteParams): BaseAutocompleteReturnType; +} + +export abstract class BaseComponentInteraction extends BaseInteraction { + embedOptions: EmbedOptions; + botOptions: BotOptions; + name: string; + + constructor(name: string) { + super(); + this.embedOptions = config.get('embedOptions'); + this.botOptions = config.get('botOptions'); + this.name = name; + } + + protected getLogger(name: string, executionId: string, interaction: MessageComponentInteraction): Logger { + return super.getLoggerBase('componentInteraction', name, executionId, interaction); + } + + abstract execute(params: BaseComponentParams): BaseComponentReturnType; +}