diff --git a/src/classes/interactions.ts b/src/classes/interactions.ts index 14905222..6c91908d 100644 --- a/src/classes/interactions.ts +++ b/src/classes/interactions.ts @@ -1,4 +1,5 @@ import config from 'config'; +import { GuildQueue } from 'discord-player'; import { ApplicationCommandOptionChoiceData, AutocompleteInteraction, @@ -64,7 +65,7 @@ abstract class BaseInteractionWithEmbedResponse extends BaseInteraction { this.botOptions = config.get('botOptions'); } - protected async getEmbedAuthor( + protected async getEmbedUserAuthor( interaction: MessageComponentInteraction | ChatInputCommandInteraction ): Promise { let authorName: string = ''; @@ -79,6 +80,16 @@ abstract class BaseInteractionWithEmbedResponse extends BaseInteraction { iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl }; } + + protected async getEmbedQueueAuthor( + interaction: MessageComponentInteraction | ChatInputCommandInteraction, + queue: GuildQueue + ): Promise { + return { + name: `Channel: ${queue.channel!.name} (${queue.channel!.bitrate / 1000}kbps)`, + iconURL: interaction.guild!.iconURL() || this.embedOptions.info.fallbackIconUrl + }; + } } export abstract class BaseSlashCommandInteraction extends BaseInteractionWithEmbedResponse { diff --git a/src/events/client/debug.ts b/src/events/client/debug.ts index b6c9730a..b4b3d017 100644 --- a/src/events/client/debug.ts +++ b/src/events/client/debug.ts @@ -1,8 +1,7 @@ import { Events } from 'discord.js'; import { randomUUID as uuidv4 } from 'node:crypto'; - -import loggerModule from '../../services/logger'; import { Logger } from 'pino'; +import loggerModule from '../../services/logger'; module.exports = { name: Events.Debug, diff --git a/src/events/client/disconnect.ts b/src/events/client/disconnect.ts index 02cc7cff..ca365578 100644 --- a/src/events/client/disconnect.ts +++ b/src/events/client/disconnect.ts @@ -1,11 +1,10 @@ import config from 'config'; import { BaseGuildTextChannel, EmbedBuilder } from 'discord.js'; import { randomUUID as uuidv4 } from 'node:crypto'; - +import { Logger } from 'pino'; import loggerModule from '../../services/logger'; import { ExtendedClient } from '../../types/clientTypes'; import { EmbedOptions, SystemOptions } from '../../types/configTypes'; -import { Logger } from 'pino'; const embedOptions: EmbedOptions = config.get('embedOptions'); const systemOptions: SystemOptions = config.get('systemOptions'); diff --git a/src/events/client/error.ts b/src/events/client/error.ts index 725395eb..7e545531 100644 --- a/src/events/client/error.ts +++ b/src/events/client/error.ts @@ -1,8 +1,7 @@ import { Events } from 'discord.js'; import { randomUUID as uuidv4 } from 'node:crypto'; - -import loggerModule from '../../services/logger'; import { Logger } from 'pino'; +import loggerModule from '../../services/logger'; module.exports = { name: Events.Error, diff --git a/src/events/client/guildCreate.ts b/src/events/client/guildCreate.ts index 18eb2b85..7639d93c 100644 --- a/src/events/client/guildCreate.ts +++ b/src/events/client/guildCreate.ts @@ -1,8 +1,7 @@ import { Events, Guild } from 'discord.js'; import { randomUUID as uuidv4 } from 'node:crypto'; - -import loggerModule from '../../services/logger'; import { Logger } from 'pino'; +import loggerModule from '../../services/logger'; module.exports = { name: Events.GuildCreate, diff --git a/src/events/client/guildDelete.ts b/src/events/client/guildDelete.ts index 49568e81..8c4b0297 100644 --- a/src/events/client/guildDelete.ts +++ b/src/events/client/guildDelete.ts @@ -1,8 +1,7 @@ import { Events, Guild } from 'discord.js'; import { randomUUID as uuidv4 } from 'node:crypto'; - -import loggerModule from '../../services/logger'; import { Logger } from 'pino'; +import loggerModule from '../../services/logger'; module.exports = { name: Events.GuildDelete, diff --git a/src/events/client/ready.ts b/src/events/client/ready.ts index b9c4a537..546f9172 100644 --- a/src/events/client/ready.ts +++ b/src/events/client/ready.ts @@ -1,7 +1,6 @@ import config from 'config'; import { BaseGuildTextChannel, EmbedBuilder, Events, PresenceData } from 'discord.js'; import { randomUUID as uuidv4 } from 'node:crypto'; - import { Logger } from 'pino'; import loggerModule from '../../services/logger'; import { ExtendedClient } from '../../types/clientTypes'; diff --git a/src/events/client/reconnecting.ts b/src/events/client/reconnecting.ts index 0ca66a09..c3e26589 100644 --- a/src/events/client/reconnecting.ts +++ b/src/events/client/reconnecting.ts @@ -1,7 +1,6 @@ import config from 'config'; import { BaseGuildTextChannel, EmbedBuilder } from 'discord.js'; import { randomUUID as uuidv4 } from 'node:crypto'; - import { Logger } from 'pino'; import loggerModule from '../../services/logger'; import { ExtendedClient } from '../../types/clientTypes'; diff --git a/src/events/client/warn.ts b/src/events/client/warn.ts index d6c0e514..30c5bfcf 100644 --- a/src/events/client/warn.ts +++ b/src/events/client/warn.ts @@ -1,6 +1,6 @@ import { Events } from 'discord.js'; -import { Logger } from 'pino'; import { randomUUID as uuidv4 } from 'node:crypto'; +import { Logger } from 'pino'; import loggerModule from '../../services/logger'; module.exports = { diff --git a/src/events/interactions/interactionCreate.ts b/src/events/interactions/interactionCreate.ts index 3a4530ec..3b538955 100644 --- a/src/events/interactions/interactionCreate.ts +++ b/src/events/interactions/interactionCreate.ts @@ -6,15 +6,15 @@ import { InteractionType, MessageComponentInteraction } from 'discord.js'; -import { Logger } from 'pino'; import { randomUUID as uuidv4 } from 'node:crypto'; +import { Logger } from 'pino'; +import { CustomError } from '../../classes/interactions'; import { handleAutocomplete } from '../../handlers/interactionAutocompleteHandler'; import { handleCommand } from '../../handlers/interactionCommandHandler'; import { handleComponent } from '../../handlers/interactionComponentHandler'; import { handleError } from '../../handlers/interactionErrorHandler'; import loggerModule from '../../services/logger'; import { ExtendedClient } from '../../types/clientTypes'; -import { CustomError } from '../../classes/interactions'; module.exports = { name: Events.InteractionCreate, diff --git a/src/events/player/generalDebug.ts b/src/events/player/generalDebug.ts index e06698ce..7afb6e14 100644 --- a/src/events/player/generalDebug.ts +++ b/src/events/player/generalDebug.ts @@ -1,5 +1,5 @@ -import { Logger } from 'pino'; import { randomUUID as uuidv4 } from 'node:crypto'; +import { Logger } from 'pino'; import loggerModule from '../../services/logger'; module.exports = { diff --git a/src/events/player/generalError.ts b/src/events/player/generalError.ts index 8cf969b5..851ed0b8 100644 --- a/src/events/player/generalError.ts +++ b/src/events/player/generalError.ts @@ -1,7 +1,7 @@ import config from 'config'; import { BaseGuildTextChannel, EmbedBuilder } from 'discord.js'; -import { Logger } from 'pino'; import { randomUUID as uuidv4 } from 'node:crypto'; +import { Logger } from 'pino'; import loggerModule from '../../services/logger'; import { BotOptions, EmbedOptions, SystemOptions } from '../../types/configTypes'; import { ExtendedGuildQueuePlayerNode } from '../../types/eventTypes'; diff --git a/src/events/player/playerDebug.ts b/src/events/player/playerDebug.ts index 47d0d491..0764870c 100644 --- a/src/events/player/playerDebug.ts +++ b/src/events/player/playerDebug.ts @@ -1,5 +1,5 @@ -import { Logger } from 'pino'; import { randomUUID as uuidv4 } from 'node:crypto'; +import { Logger } from 'pino'; import loggerModule from '../../services/logger'; module.exports = { diff --git a/src/events/player/playerError.ts b/src/events/player/playerError.ts index 66dd9fe4..08c4077c 100644 --- a/src/events/player/playerError.ts +++ b/src/events/player/playerError.ts @@ -1,7 +1,7 @@ import config from 'config'; import { BaseGuildTextChannel, EmbedBuilder } from 'discord.js'; -import { Logger } from 'pino'; import { randomUUID as uuidv4 } from 'node:crypto'; +import { Logger } from 'pino'; import loggerModule from '../../services/logger'; import { BotOptions, EmbedOptions, SystemOptions } from '../../types/configTypes'; import { ExtendedGuildQueuePlayerNode } from '../../types/eventTypes'; diff --git a/src/events/player/playerSkip.ts b/src/events/player/playerSkip.ts index 642ac223..0ada031d 100644 --- a/src/events/player/playerSkip.ts +++ b/src/events/player/playerSkip.ts @@ -1,8 +1,8 @@ import config from 'config'; import { Track } from 'discord-player'; import { BaseGuildTextChannel, EmbedBuilder } from 'discord.js'; -import { Logger } from 'pino'; import { randomUUID as uuidv4 } from 'node:crypto'; +import { Logger } from 'pino'; import loggerModule from '../../services/logger'; import { BotOptions, EmbedOptions, SystemOptions } from '../../types/configTypes'; import { ExtendedGuildQueuePlayerNode } from '../../types/eventTypes'; diff --git a/src/events/player/playerStart.ts b/src/events/player/playerStart.ts index 0fe59276..3a0384c9 100644 --- a/src/events/player/playerStart.ts +++ b/src/events/player/playerStart.ts @@ -1,6 +1,6 @@ import { Track } from 'discord-player'; -import { Logger } from 'pino'; import { randomUUID as uuidv4 } from 'node:crypto'; +import { Logger } from 'pino'; import loggerModule from '../../services/logger'; import { ExtendedGuildQueuePlayerNode } from '../../types/eventTypes'; diff --git a/src/events/process/uncaughtException.ts b/src/events/process/uncaughtException.ts index e6c1ab09..0a01d55b 100644 --- a/src/events/process/uncaughtException.ts +++ b/src/events/process/uncaughtException.ts @@ -1,5 +1,5 @@ -import { Logger } from 'pino'; import { randomUUID as uuidv4 } from 'node:crypto'; +import { Logger } from 'pino'; import loggerModule from '../../services/logger'; module.exports = { diff --git a/src/events/process/unhandledRejection.ts b/src/events/process/unhandledRejection.ts index c8d5128d..d982b941 100644 --- a/src/events/process/unhandledRejection.ts +++ b/src/events/process/unhandledRejection.ts @@ -1,5 +1,5 @@ -import { Logger } from 'pino'; import { randomUUID as uuidv4 } from 'node:crypto'; +import { Logger } from 'pino'; import loggerModule from '../../services/logger'; module.exports = { diff --git a/src/handlers/interactionAutocompleteHandler.ts b/src/handlers/interactionAutocompleteHandler.ts index 963dfc8e..2030b106 100644 --- a/src/handlers/interactionAutocompleteHandler.ts +++ b/src/handlers/interactionAutocompleteHandler.ts @@ -1,8 +1,8 @@ import { AutocompleteInteraction } from 'discord.js'; import { Logger } from 'pino'; +import { BaseAutocompleteInteraction } from '../classes/interactions'; import loggerModule from '../services/logger'; import { ExtendedClient } from '../types/clientTypes'; -import { BaseAutocompleteInteraction } from '../classes/interactions'; export const handleAutocomplete = async ( interaction: AutocompleteInteraction, diff --git a/src/handlers/interactionCommandHandler.ts b/src/handlers/interactionCommandHandler.ts index 06f88a00..ae8f2054 100644 --- a/src/handlers/interactionCommandHandler.ts +++ b/src/handlers/interactionCommandHandler.ts @@ -1,8 +1,8 @@ import { ChatInputCommandInteraction } from 'discord.js'; import { Logger } from 'pino'; +import { BaseSlashCommandInteraction } from '../classes/interactions'; import loggerModule from '../services/logger'; import { ExtendedClient } from '../types/clientTypes'; -import { BaseSlashCommandInteraction } from '../classes/interactions'; import { checkChannelPermissionViewable } from '../utils/validation/permissionValidator'; export const handleCommand = async ( diff --git a/src/handlers/interactionComponentHandler.ts b/src/handlers/interactionComponentHandler.ts index f95d1dc4..8418e5f4 100644 --- a/src/handlers/interactionComponentHandler.ts +++ b/src/handlers/interactionComponentHandler.ts @@ -1,8 +1,8 @@ import { MessageComponentInteraction } from 'discord.js'; import { Logger } from 'pino'; +import { BaseComponentInteraction } from '../classes/interactions'; import loggerModule from '../services/logger'; import { ExtendedClient } from '../types/clientTypes'; -import { BaseComponentInteraction } from '../classes/interactions'; import { checkChannelPermissionViewable } from '../utils/validation/permissionValidator'; export const handleComponent = async ( diff --git a/src/handlers/interactionErrorHandler.ts b/src/handlers/interactionErrorHandler.ts index e718981b..84160518 100644 --- a/src/handlers/interactionErrorHandler.ts +++ b/src/handlers/interactionErrorHandler.ts @@ -8,9 +8,9 @@ import { MessageComponentInteraction } from 'discord.js'; import { Logger } from 'pino'; +import { CustomError, InteractionValidationError } from '../classes/interactions'; import loggerModule from '../services/logger'; import { BotOptions, EmbedOptions } from '../types/configTypes'; -import { CustomError, InteractionValidationError } from '../classes/interactions'; const embedOptions: EmbedOptions = config.get('embedOptions'); const botOptions: BotOptions = config.get('botOptions'); diff --git a/src/index.ts b/src/index.ts index 029b2977..b0671564 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,9 +1,7 @@ -import 'dotenv/config'; - import config from 'config'; import { Client, Shard, ShardEvents, ShardingManager, ShardingManagerOptions } from 'discord.js'; +import 'dotenv/config'; import { randomUUID as uuidv4 } from 'node:crypto'; - import { Logger } from 'pino'; import loggerModule from './services/logger'; diff --git a/src/interactions/autocomplete/lyrics.ts b/src/interactions/autocomplete/lyrics.ts index 731fa7d9..f9b974d0 100644 --- a/src/interactions/autocomplete/lyrics.ts +++ b/src/interactions/autocomplete/lyrics.ts @@ -1,8 +1,8 @@ import { LyricsData, lyricsExtractor } from '@discord-player/extractor'; import { Player, SearchResult, useMainPlayer } from 'discord-player'; import { ApplicationCommandOptionChoiceData } from 'discord.js'; -import { BaseAutocompleteParams, BaseAutocompleteReturnType } from '../../types/interactionTypes'; import { BaseAutocompleteInteraction } from '../../classes/interactions'; +import { BaseAutocompleteParams, BaseAutocompleteReturnType } from '../../types/interactionTypes'; // TODO: create type for recent query object const recentQueries = new Map(); diff --git a/src/interactions/autocomplete/play.ts b/src/interactions/autocomplete/play.ts index 93881b08..f5711894 100644 --- a/src/interactions/autocomplete/play.ts +++ b/src/interactions/autocomplete/play.ts @@ -1,7 +1,7 @@ import { Player, SearchResult, useMainPlayer } from 'discord-player'; import { ApplicationCommandOptionChoiceData } from 'discord.js'; -import { BaseAutocompleteParams, BaseAutocompleteReturnType } from '../../types/interactionTypes'; import { BaseAutocompleteInteraction } from '../../classes/interactions'; +import { BaseAutocompleteParams, BaseAutocompleteReturnType } from '../../types/interactionTypes'; // TODO: create type for recent query object const recentQueries = new Map(); diff --git a/src/interactions/commands/info/help.ts b/src/interactions/commands/info/help.ts index af722ebe..62729b88 100644 --- a/src/interactions/commands/info/help.ts +++ b/src/interactions/commands/info/help.ts @@ -1,6 +1,6 @@ import { EmbedBuilder, SlashCommandBuilder, SlashCommandNumberOption, SlashCommandStringOption } from 'discord.js'; -import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; import { BaseSlashCommandInteraction } from '../../../classes/interactions'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; class HelpCommand extends BaseSlashCommandInteraction { constructor() { diff --git a/src/interactions/commands/info/status.ts b/src/interactions/commands/info/status.ts index 97c58d55..04a54bf4 100644 --- a/src/interactions/commands/info/status.ts +++ b/src/interactions/commands/info/status.ts @@ -2,8 +2,8 @@ import { EmbedBuilder, Guild, SlashCommandBuilder } from 'discord.js'; import osu from 'node-os-utils'; // @ts-ignore import { version } from '../../../../package.json'; -import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; import { BaseSlashCommandInteraction } from '../../../classes/interactions'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; import { getUptimeFormatted } from '../../../utils/system/getUptimeFormatted'; class StatusCommand extends BaseSlashCommandInteraction { diff --git a/src/interactions/commands/player/filters.ts b/src/interactions/commands/player/filters.ts index 8f7d81e8..e3515e55 100644 --- a/src/interactions/commands/player/filters.ts +++ b/src/interactions/commands/player/filters.ts @@ -18,8 +18,8 @@ import { Logger } from 'pino'; import { BaseSlashCommandInteraction } from '../../../classes/interactions'; import { FFmpegFilterOption, FFmpegFilterOptions } from '../../../types/configTypes'; import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; -import { checkQueueExists, checkQueueCurrentTrack } from '../../../utils/validation/queueValidator'; -import { checkSameVoiceChannel, checkInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; +import { checkQueueCurrentTrack, checkQueueExists } from '../../../utils/validation/queueValidator'; +import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; const ffmpegFilterOptions: FFmpegFilterOptions = config.get('ffmpegFilterOptions'); diff --git a/src/interactions/commands/player/leave.ts b/src/interactions/commands/player/leave.ts index 1c6e07e3..1aa1e4dc 100644 --- a/src/interactions/commands/player/leave.ts +++ b/src/interactions/commands/player/leave.ts @@ -3,7 +3,7 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; import { BaseSlashCommandInteraction } from '../../../classes/interactions'; import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; import { checkQueueExists } from '../../../utils/validation/queueValidator'; -import { checkSameVoiceChannel, checkInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; +import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; class LeaveCommand extends BaseSlashCommandInteraction { constructor() { @@ -36,7 +36,7 @@ class LeaveCommand extends BaseSlashCommandInteraction { return await interaction.editReply({ embeds: [ new EmbedBuilder() - .setAuthor(await this.getEmbedAuthor(interaction)) + .setAuthor(await this.getEmbedUserAuthor(interaction)) .setDescription( `**${this.embedOptions.icons.success} Leaving channel**\nCleared the track queue and left voice channel.\n\nTo play more music, use the **\`/play\`** command!` ) diff --git a/src/interactions/commands/player/loop.ts b/src/interactions/commands/player/loop.ts index ed736953..dc33a8b4 100644 --- a/src/interactions/commands/player/loop.ts +++ b/src/interactions/commands/player/loop.ts @@ -1,9 +1,9 @@ import { GuildQueue, QueueRepeatMode, useQueue } from 'discord-player'; -import { EmbedBuilder, GuildMember, SlashCommandBuilder, SlashCommandStringOption } from 'discord.js'; -import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; +import { EmbedBuilder, SlashCommandBuilder, SlashCommandStringOption } from 'discord.js'; import { BaseSlashCommandInteraction } from '../../../classes/interactions'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; import { checkQueueExists } from '../../../utils/validation/queueValidator'; -import { checkSameVoiceChannel, checkInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; +import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; class LoopCommand extends BaseSlashCommandInteraction { constructor() { @@ -106,14 +106,6 @@ class LoopCommand extends BaseSlashCommandInteraction { }); } - let authorName: string; - - if (interaction.member instanceof GuildMember) { - authorName = interaction.member.nickname || interaction.user.username; - } else { - authorName = interaction.user.username; - } - if (queue.repeatMode === 0) { logger.debug('Disabled loop mode.'); @@ -122,10 +114,7 @@ class LoopCommand extends BaseSlashCommandInteraction { return await interaction.editReply({ embeds: [ new EmbedBuilder() - .setAuthor({ - name: authorName, - iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl - }) + .setAuthor(await this.getEmbedUserAuthor(interaction)) .setDescription( `**${this.embedOptions.icons.success} Loop mode disabled**\nChanging loop mode from **\`${currentModeUserString}\`** to **\`${modeUserString}\`**.\n\nThe ${currentModeUserString} will no longer play on repeat!` ) @@ -141,10 +130,7 @@ class LoopCommand extends BaseSlashCommandInteraction { return await interaction.editReply({ embeds: [ new EmbedBuilder() - .setAuthor({ - name: authorName, - iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl - }) + .setAuthor(await this.getEmbedUserAuthor(interaction)) .setDescription( `**${this.embedOptions.icons.autoplaying} Loop mode changed**\nChanging loop mode from **\`${currentModeUserString}\`** to **\`${modeUserString}\`**.\n\nWhen the queue is empty, similar tracks will start playing!` ) @@ -159,10 +145,7 @@ class LoopCommand extends BaseSlashCommandInteraction { return await interaction.editReply({ embeds: [ new EmbedBuilder() - .setAuthor({ - name: authorName, - iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl - }) + .setAuthor(await this.getEmbedUserAuthor(interaction)) .setDescription( `**${this.embedOptions.icons.looping} Loop mode changed**\nChanging loop mode from **\`${currentModeUserString}\`** to **\`${modeUserString}\`**.\n\nThe ${modeUserString} will now play on repeat!` ) diff --git a/src/interactions/commands/player/lyrics.ts b/src/interactions/commands/player/lyrics.ts index 61d3aa3b..11578c56 100644 --- a/src/interactions/commands/player/lyrics.ts +++ b/src/interactions/commands/player/lyrics.ts @@ -1,10 +1,10 @@ import { LyricsData, lyricsExtractor } from '@discord-player/extractor'; import { GuildQueue, Player, QueryType, useMainPlayer, useQueue } from 'discord-player'; import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; -import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; import { BaseSlashCommandInteraction } from '../../../classes/interactions'; -import { checkQueueExists, checkQueueCurrentTrack } from '../../../utils/validation/queueValidator'; -import { checkSameVoiceChannel, checkInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; +import { checkQueueCurrentTrack, checkQueueExists } from '../../../utils/validation/queueValidator'; +import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; class LyricsCommand extends BaseSlashCommandInteraction { constructor() { diff --git a/src/interactions/commands/player/nowplaying.ts b/src/interactions/commands/player/nowplaying.ts index 9e806fcd..08ea5846 100644 --- a/src/interactions/commands/player/nowplaying.ts +++ b/src/interactions/commands/player/nowplaying.ts @@ -10,11 +10,11 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; +import { BaseSlashCommandInteraction } from '../../../classes/interactions'; import { PlayerOptions } from '../../../types/configTypes'; import { BaseSlashCommandParams, BaseSlashCommandReturnType, TrackMetadata } from '../../../types/interactionTypes'; -import { BaseSlashCommandInteraction } from '../../../classes/interactions'; -import { checkQueueExists, checkQueueCurrentTrack } from '../../../utils/validation/queueValidator'; -import { checkSameVoiceChannel, checkInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; +import { checkQueueCurrentTrack, checkQueueExists } from '../../../utils/validation/queueValidator'; +import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; const playerOptions: PlayerOptions = config.get('playerOptions'); @@ -132,10 +132,7 @@ class NowPlayingCommand extends BaseSlashCommandInteraction { return await interaction.editReply({ embeds: [ new EmbedBuilder() - .setAuthor({ - name: `Channel: ${queue.channel!.name} (${queue.channel!.bitrate / 1000}kbps)`, - iconURL: interaction.guild!.iconURL() || this.embedOptions.info.fallbackIconUrl - }) + .setAuthor(await this.getEmbedQueueAuthor(interaction, queue)) .setDescription( (queue.node.isPaused() ? '**Currently Paused**\n' diff --git a/src/interactions/commands/player/pause.ts b/src/interactions/commands/player/pause.ts index f0bef152..37c6e8c0 100644 --- a/src/interactions/commands/player/pause.ts +++ b/src/interactions/commands/player/pause.ts @@ -1,10 +1,9 @@ import { GuildQueue, Track, useQueue } from 'discord-player'; -import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js'; - -import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; +import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; import { BaseSlashCommandInteraction } from '../../../classes/interactions'; -import { checkQueueExists, checkQueueCurrentTrack } from '../../../utils/validation/queueValidator'; -import { checkSameVoiceChannel, checkInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; +import { checkQueueCurrentTrack, checkQueueExists } from '../../../utils/validation/queueValidator'; +import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; class PauseCommand extends BaseSlashCommandInteraction { constructor() { @@ -42,22 +41,11 @@ class PauseCommand extends BaseSlashCommandInteraction { queue.node.setPaused(!queue.node.isPaused()); logger.debug(`Set paused state to ${queue.node.isPaused()}.`); - let authorName: string; - - if (interaction.member instanceof GuildMember) { - authorName = interaction.member.nickname || interaction.user.username; - } else { - authorName = interaction.user.username; - } - logger.debug('Responding with success embed.'); return await interaction.editReply({ embeds: [ new EmbedBuilder() - .setAuthor({ - name: authorName, - iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl - }) + .setAuthor(await this.getEmbedUserAuthor(interaction)) .setDescription( `**${this.embedOptions.icons.pauseResumed} ${ queue.node.isPaused() ? 'Paused Track' : 'Resumed track' diff --git a/src/interactions/commands/player/play.ts b/src/interactions/commands/player/play.ts index 9c347fa1..dc0e6df5 100644 --- a/src/interactions/commands/player/play.ts +++ b/src/interactions/commands/player/play.ts @@ -238,22 +238,11 @@ class PlayCommand extends BaseSlashCommandInteraction { if (searchResult.playlist && searchResult.tracks.length > 1) { logger.debug(`Playlist found and added with player.play(). Query: '${query}'`); - let authorName: string; - - if (interaction.member instanceof GuildMember) { - authorName = interaction.member.nickname || interaction.user.username; - } else { - authorName = interaction.user.username; - } - logger.debug('Responding with success embed.'); return await interaction.editReply({ embeds: [ new EmbedBuilder() - .setAuthor({ - name: authorName, - iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl - }) + .setAuthor(await this.getEmbedUserAuthor(interaction)) .setDescription( `**${this.embedOptions.icons.success} Added playlist to queue**\n**${durationFormat} [${ track.title @@ -270,22 +259,11 @@ class PlayCommand extends BaseSlashCommandInteraction { if (queue && queue.currentTrack === track && queue.tracks.data.length === 0) { logger.debug(`Track found and added with player.play(), started playing. Query: '${query}'.`); - let authorName: string; - - if (interaction.member instanceof GuildMember) { - authorName = interaction.member.nickname || interaction.user.username; - } else { - authorName = interaction.user.username; - } - logger.debug('Responding with success embed.'); return await interaction.editReply({ embeds: [ new EmbedBuilder() - .setAuthor({ - name: authorName, - iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl - }) + .setAuthor(await this.getEmbedUserAuthor(interaction)) .setDescription( `**${this.embedOptions.icons.audioStartedPlaying} Started playing**\n**${durationFormat} [${ track.title @@ -299,22 +277,11 @@ class PlayCommand extends BaseSlashCommandInteraction { logger.debug(`Track found and added with player.play(), added to queue. Query: '${query}'.`); - let authorName: string; - - if (interaction.member instanceof GuildMember) { - authorName = interaction.member.nickname || interaction.user.username; - } else { - authorName = interaction.user.username; - } - logger.debug('Responding with success embed.'); return await interaction.editReply({ embeds: [ new EmbedBuilder() - .setAuthor({ - name: authorName, - iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl - }) + .setAuthor(await this.getEmbedUserAuthor(interaction)) .setDescription( `${this.embedOptions.icons.success} **Added to queue**\n**${durationFormat} [${track.title}](${ track.raw.url ?? track.url diff --git a/src/interactions/commands/player/queue.ts b/src/interactions/commands/player/queue.ts index 33eeee7b..d3b54b22 100644 --- a/src/interactions/commands/player/queue.ts +++ b/src/interactions/commands/player/queue.ts @@ -1,11 +1,11 @@ import config from 'config'; import { GuildQueue, PlayerTimestamp, Track, useQueue } from 'discord-player'; import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; +import { BaseSlashCommandInteraction } from '../../../classes/interactions'; import { PlayerOptions } from '../../../types/configTypes'; import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; -import { BaseSlashCommandInteraction } from '../../../classes/interactions'; import { checkQueueExists } from '../../../utils/validation/queueValidator'; -import { checkSameVoiceChannel, checkInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; +import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; const playerOptions: PlayerOptions = config.get('playerOptions'); @@ -103,10 +103,7 @@ class QueueCommand extends BaseSlashCommandInteraction { return await interaction.editReply({ embeds: [ new EmbedBuilder() - .setAuthor({ - name: `Channel: ${queue.channel!.name} (${queue.channel!.bitrate / 1000}kbps)`, - iconURL: interaction.guild!.iconURL() || this.embedOptions.info.fallbackIconUrl - }) + .setAuthor(await this.getEmbedQueueAuthor(interaction, queue)) .setDescription( `${repeatModeString}` + `**${this.embedOptions.icons.queue} Tracks in queue**\n${queueString}` @@ -141,10 +138,7 @@ class QueueCommand extends BaseSlashCommandInteraction { return await interaction.editReply({ embeds: [ new EmbedBuilder() - .setAuthor({ - name: `Channel: ${queue.channel!.name} (${queue.channel!.bitrate / 1000}kbps)`, - iconURL: interaction.guild!.iconURL() || this.embedOptions.info.fallbackIconUrl - }) + .setAuthor(await this.getEmbedQueueAuthor(interaction, queue)) .setDescription( `**${this.embedOptions.icons.audioPlaying} Now playing**\n` + (currentTrack diff --git a/src/interactions/commands/player/remove.ts b/src/interactions/commands/player/remove.ts index d3b361ff..2611e513 100644 --- a/src/interactions/commands/player/remove.ts +++ b/src/interactions/commands/player/remove.ts @@ -1,9 +1,9 @@ import { GuildQueue, Track, useQueue } from 'discord-player'; -import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js'; -import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; +import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; import { BaseSlashCommandInteraction } from '../../../classes/interactions'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; import { checkQueueExists } from '../../../utils/validation/queueValidator'; -import { checkSameVoiceChannel, checkInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; +import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; class RemoveCommand extends BaseSlashCommandInteraction { constructor() { @@ -63,22 +63,11 @@ class RemoveCommand extends BaseSlashCommandInteraction { durationFormat = `${this.embedOptions.icons.liveTrack} \`LIVE\``; } - let authorName: string; - - if (interaction.member instanceof GuildMember) { - authorName = interaction.member.nickname || interaction.user.username; - } else { - authorName = interaction.user.username; - } - logger.debug('Responding with success embed.'); return await interaction.editReply({ embeds: [ new EmbedBuilder() - .setAuthor({ - name: authorName, - iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl - }) + .setAuthor(await this.getEmbedUserAuthor(interaction)) .setDescription( `**${this.embedOptions.icons.success} Removed track**\n**${durationFormat} [${ removedTrack.title diff --git a/src/interactions/commands/player/seek.ts b/src/interactions/commands/player/seek.ts index 8d8853ed..47e40004 100644 --- a/src/interactions/commands/player/seek.ts +++ b/src/interactions/commands/player/seek.ts @@ -1,9 +1,9 @@ import { GuildQueue, useQueue } from 'discord-player'; -import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js'; -import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; +import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; import { BaseSlashCommandInteraction } from '../../../classes/interactions'; -import { checkQueueExists, checkQueueCurrentTrack } from '../../../utils/validation/queueValidator'; -import { checkSameVoiceChannel, checkInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; +import { checkQueueCurrentTrack, checkQueueExists } from '../../../utils/validation/queueValidator'; +import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; class SeekCommand extends BaseSlashCommandInteraction { constructor() { @@ -141,22 +141,11 @@ class SeekCommand extends BaseSlashCommandInteraction { queue.node.seek(durationInMilliseconds); logger.debug(`Seeked to '${durationString}' in current track.`); - let authorName: string; - - if (interaction.member instanceof GuildMember) { - authorName = interaction.member.nickname || interaction.user.username; - } else { - authorName = interaction.user.username; - } - logger.debug('Responding with success embed.'); return await interaction.editReply({ embeds: [ new EmbedBuilder() - .setAuthor({ - name: authorName, - iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl - }) + .setAuthor(await this.getEmbedUserAuthor(interaction)) .setDescription( `**${this.embedOptions.icons.success} Seeking to duration**\nSeeking to **\`${durationString}\`** in current track.` ) diff --git a/src/interactions/commands/player/shuffle.ts b/src/interactions/commands/player/shuffle.ts index 46537da8..5a630dd3 100644 --- a/src/interactions/commands/player/shuffle.ts +++ b/src/interactions/commands/player/shuffle.ts @@ -1,9 +1,9 @@ import { GuildQueue, useQueue } from 'discord-player'; -import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js'; -import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; +import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; import { BaseSlashCommandInteraction } from '../../../classes/interactions'; -import { checkQueueExists, checkQueueEmpty } from '../../../utils/validation/queueValidator'; -import { checkSameVoiceChannel, checkInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; +import { checkQueueEmpty, checkQueueExists } from '../../../utils/validation/queueValidator'; +import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; class ShuffleCommand extends BaseSlashCommandInteraction { constructor() { @@ -31,22 +31,11 @@ class ShuffleCommand extends BaseSlashCommandInteraction { queue.tracks.shuffle(); logger.debug('Shuffled queue tracks.'); - let authorName: string; - - if (interaction.member instanceof GuildMember) { - authorName = interaction.member.nickname || interaction.user.username; - } else { - authorName = interaction.user.username; - } - logger.debug('Responding with success embed.'); return await interaction.editReply({ embeds: [ new EmbedBuilder() - .setAuthor({ - name: authorName, - iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl - }) + .setAuthor(await this.getEmbedUserAuthor(interaction)) .setDescription( `**${this.embedOptions.icons.shuffled} Shuffled queue tracks**\nThe **${queue.tracks.data.length}** tracks in the queue has been shuffled.\n\nView the new queue order with **\`/queue\`**.` ) diff --git a/src/interactions/commands/player/skip.ts b/src/interactions/commands/player/skip.ts index 3328682c..b12d33d9 100644 --- a/src/interactions/commands/player/skip.ts +++ b/src/interactions/commands/player/skip.ts @@ -1,9 +1,9 @@ import { GuildQueue, Track, useQueue } from 'discord-player'; -import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js'; -import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; +import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; import { BaseSlashCommandInteraction } from '../../../classes/interactions'; -import { checkQueueExists, checkQueueCurrentTrack } from '../../../utils/validation/queueValidator'; -import { checkSameVoiceChannel, checkInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; +import { checkQueueCurrentTrack, checkQueueExists } from '../../../utils/validation/queueValidator'; +import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; class SkipCommand extends BaseSlashCommandInteraction { constructor() { @@ -63,22 +63,11 @@ class SkipCommand extends BaseSlashCommandInteraction { queue.node.skipTo(skipToTrack - 1); logger.debug('Skipped to specified track number.'); - let authorName: string; - - if (interaction.member instanceof GuildMember) { - authorName = interaction.member.nickname || interaction.user.username; - } else { - authorName = interaction.user.username; - } - logger.debug('Responding with success embed.'); return await interaction.editReply({ embeds: [ new EmbedBuilder() - .setAuthor({ - name: authorName, - iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl - }) + .setAuthor(await this.getEmbedUserAuthor(interaction)) .setDescription( `**${this.embedOptions.icons.skipped} Skipped track**\n**${durationFormat} [${ skippedTrack.title @@ -134,22 +123,11 @@ class SkipCommand extends BaseSlashCommandInteraction { const repeatModeString: string = queue.repeatMode === 0 ? '' : getRepeatModeMessage(queue.repeatMode); - let authorName: string; - - if (interaction.member instanceof GuildMember) { - authorName = interaction.member.nickname || interaction.user.username; - } else { - authorName = interaction.user.username; - } - logger.debug('Responding with success embed.'); return await interaction.editReply({ embeds: [ new EmbedBuilder() - .setAuthor({ - name: authorName, - iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl - }) + .setAuthor(await this.getEmbedUserAuthor(interaction)) .setDescription( `**${this.embedOptions.icons.skipped} Skipped track**\n**${durationFormat} [${ skippedTrack.title diff --git a/src/interactions/commands/player/stop.ts b/src/interactions/commands/player/stop.ts index bba3690f..50cf5a97 100644 --- a/src/interactions/commands/player/stop.ts +++ b/src/interactions/commands/player/stop.ts @@ -1,9 +1,9 @@ import { GuildQueue, useQueue } from 'discord-player'; -import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js'; -import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; +import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; import { BaseSlashCommandInteraction } from '../../../classes/interactions'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; import { checkQueueExists } from '../../../utils/validation/queueValidator'; -import { checkSameVoiceChannel, checkInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; +import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; class StopCommand extends BaseSlashCommandInteraction { constructor() { @@ -34,22 +34,11 @@ class StopCommand extends BaseSlashCommandInteraction { logger.debug('Cleared and stopped the queue.'); } - let authorName: string; - - if (interaction.member instanceof GuildMember) { - authorName = interaction.member.nickname || interaction.user.username; - } else { - authorName = interaction.user.username; - } - logger.debug('Responding with success embed.'); return await interaction.editReply({ embeds: [ new EmbedBuilder() - .setAuthor({ - name: authorName, - iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl - }) + .setAuthor(await this.getEmbedUserAuthor(interaction)) .setDescription( `**${this.embedOptions.icons.success} Stopped playing**\nStopped playing audio and cleared the track queue.\n\nTo play more music, use the **\`/play\`** command!` ) diff --git a/src/interactions/commands/player/volume.ts b/src/interactions/commands/player/volume.ts index 763a425c..d6955bfe 100644 --- a/src/interactions/commands/player/volume.ts +++ b/src/interactions/commands/player/volume.ts @@ -1,9 +1,9 @@ import { GuildQueue, useQueue } from 'discord-player'; -import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js'; -import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; +import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; import { BaseSlashCommandInteraction } from '../../../classes/interactions'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; import { checkQueueExists } from '../../../utils/validation/queueValidator'; -import { checkSameVoiceChannel, checkInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; +import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; class VolumeCommand extends BaseSlashCommandInteraction { constructor() { @@ -72,23 +72,12 @@ class VolumeCommand extends BaseSlashCommandInteraction { queue.node.setVolume(volume); logger.debug(`Set volume to ${volume}%.`); - let authorName: string; - - if (interaction.member instanceof GuildMember) { - authorName = interaction.member.nickname || interaction.user.username; - } else { - authorName = interaction.user.username; - } - if (volume === 0) { logger.debug('Responding with success embed.'); return await interaction.editReply({ embeds: [ new EmbedBuilder() - .setAuthor({ - name: authorName, - iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl - }) + .setAuthor(await this.getEmbedUserAuthor(interaction)) .setDescription( `**${this.embedOptions.icons.volumeMuted} Audio muted**\nPlayback audio has been muted, because volume was set to **\`${volume}%\`**.` ) @@ -101,10 +90,7 @@ class VolumeCommand extends BaseSlashCommandInteraction { return await interaction.editReply({ embeds: [ new EmbedBuilder() - .setAuthor({ - name: authorName, - iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl - }) + .setAuthor(await this.getEmbedUserAuthor(interaction)) .setDescription( `**${this.embedOptions.icons.volumeChanged} Volume changed**\nPlayback volume has been changed to **\`${volume}%\`**.` ) diff --git a/src/interactions/commands/system/guilds.ts b/src/interactions/commands/system/guilds.ts index d38f5ee0..ad76379e 100644 --- a/src/interactions/commands/system/guilds.ts +++ b/src/interactions/commands/system/guilds.ts @@ -1,6 +1,6 @@ import { EmbedBuilder, Guild, SlashCommandBuilder } from 'discord.js'; -import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; import { BaseSlashCommandInteraction } from '../../../classes/interactions'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; import { checkValidGuildId } from '../../../utils/validation/systemCommandValidator'; class GuildsCommand extends BaseSlashCommandInteraction { diff --git a/src/interactions/commands/system/reload.ts b/src/interactions/commands/system/reload.ts index f863ea7c..43f3cdef 100644 --- a/src/interactions/commands/system/reload.ts +++ b/src/interactions/commands/system/reload.ts @@ -1,7 +1,7 @@ import { ApplicationCommandOption, ApplicationCommandOptionData, EmbedBuilder, SlashCommandBuilder } from 'discord.js'; +import { BaseSlashCommandInteraction } from '../../../classes/interactions'; import { ExtendedClient } from '../../../types/clientTypes'; import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; -import { BaseSlashCommandInteraction } from '../../../classes/interactions'; import { checkValidGuildId } from '../../../utils/validation/systemCommandValidator'; class ReloadCommand extends BaseSlashCommandInteraction { diff --git a/src/interactions/commands/system/shards.ts b/src/interactions/commands/system/shards.ts index 8f34cab4..3d774e28 100644 --- a/src/interactions/commands/system/shards.ts +++ b/src/interactions/commands/system/shards.ts @@ -1,7 +1,7 @@ import { EmbedBuilder, EmbedField, SlashCommandBuilder } from 'discord.js'; +import { BaseSlashCommandInteraction } from '../../../classes/interactions'; import { ExtendedClient } from '../../../types/clientTypes'; import { BaseSlashCommandParams, BaseSlashCommandReturnType, ShardInfo } from '../../../types/interactionTypes'; -import { BaseSlashCommandInteraction } from '../../../classes/interactions'; import { checkValidGuildId } from '../../../utils/validation/systemCommandValidator'; class ShardsCommand extends BaseSlashCommandInteraction { diff --git a/src/interactions/commands/system/systemstatus.ts b/src/interactions/commands/system/systemstatus.ts index 11270a18..2061ddda 100644 --- a/src/interactions/commands/system/systemstatus.ts +++ b/src/interactions/commands/system/systemstatus.ts @@ -2,8 +2,8 @@ import { EmbedBuilder, Guild, SlashCommandBuilder } from 'discord.js'; import osu from 'node-os-utils'; // @ts-ignore import { dependencies, version } from '../../../../package.json'; -import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; import { BaseSlashCommandInteraction } from '../../../classes/interactions'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; import { getUptimeFormatted } from '../../../utils/system/getUptimeFormatted'; import { checkValidGuildId } from '../../../utils/validation/systemCommandValidator'; diff --git a/src/interactions/components/filters-disable-button.ts b/src/interactions/components/filters-disable-button.ts index 57bf766f..4772a38b 100644 --- a/src/interactions/components/filters-disable-button.ts +++ b/src/interactions/components/filters-disable-button.ts @@ -1,9 +1,9 @@ import { GuildQueue, useQueue } from 'discord-player'; -import { EmbedBuilder, GuildMember } from 'discord.js'; -import { BaseComponentParams, BaseComponentReturnType } from '../../types/interactionTypes'; +import { EmbedBuilder } from 'discord.js'; import { BaseComponentInteraction } from '../../classes/interactions'; +import { BaseComponentParams, BaseComponentReturnType } from '../../types/interactionTypes'; import { checkQueueExists } from '../../utils/validation/queueValidator'; -import { checkSameVoiceChannel, checkInVoiceChannel } from '../../utils/validation/voiceChannelValidator'; +import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator'; class FiltersDisableButtonComponent extends BaseComponentInteraction { constructor() { @@ -30,22 +30,11 @@ class FiltersDisableButtonComponent extends BaseComponentInteraction { logger.debug('Reset queue filters.'); } - let authorName: string; - - if (interaction.member instanceof GuildMember) { - authorName = interaction.member.nickname || interaction.user.username; - } else { - authorName = interaction.user.username; - } - logger.debug('Responding with success embed.'); return await interaction.editReply({ embeds: [ new EmbedBuilder() - .setAuthor({ - name: authorName, - iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl - }) + .setAuthor(await this.getEmbedUserAuthor(interaction)) .setDescription( `**${this.embedOptions.icons.success} Disabled filters**\nAll audio filters have been disabled.` ) diff --git a/src/interactions/components/filters-select-menu.ts b/src/interactions/components/filters-select-menu.ts index 9108f0bf..d256d3ab 100644 --- a/src/interactions/components/filters-select-menu.ts +++ b/src/interactions/components/filters-select-menu.ts @@ -1,11 +1,12 @@ import config from 'config'; import { GuildQueue, QueueFilters, useQueue } from 'discord-player'; -import { EmbedBuilder, GuildMember, StringSelectMenuInteraction } from 'discord.js'; +import { EmbedBuilder, StringSelectMenuInteraction } from 'discord.js'; +import { BaseComponentInteraction } from '../../classes/interactions'; import { FFmpegFilterOption, FFmpegFilterOptions } from '../../types/configTypes'; import { BaseComponentParams, BaseComponentReturnType } from '../../types/interactionTypes'; -import { BaseComponentInteraction } from '../../classes/interactions'; import { checkQueueExists } from '../../utils/validation/queueValidator'; -import { checkSameVoiceChannel, checkInVoiceChannel } from '../../utils/validation/voiceChannelValidator'; +import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator'; + const ffmpegFilterOptions: FFmpegFilterOptions = config.get('ffmpegFilterOptions'); class FiltersSelectMenuComponent extends BaseComponentInteraction { @@ -61,22 +62,11 @@ class FiltersSelectMenuComponent extends BaseComponentInteraction { queue.filters.ffmpeg.toggle(selectMenuInteraction.values as (keyof QueueFilters)[]); logger.debug(`Enabled filters ${selectMenuInteraction.values.join(', ')}.`); - let authorName: string; - - if (selectMenuInteraction.member instanceof GuildMember) { - authorName = selectMenuInteraction.member.nickname || selectMenuInteraction.user.username; - } else { - authorName = selectMenuInteraction.user.username; - } - logger.debug('Responding with success embed.'); return await selectMenuInteraction.editReply({ embeds: [ new EmbedBuilder() - .setAuthor({ - name: authorName, - iconURL: selectMenuInteraction.user.avatarURL() || '' - }) + .setAuthor(await this.getEmbedUserAuthor(interaction)) .setDescription( `**${ this.embedOptions.icons.success diff --git a/src/interactions/components/nowplaying-skip-button.ts b/src/interactions/components/nowplaying-skip-button.ts index 1c6d5366..a5a3a648 100644 --- a/src/interactions/components/nowplaying-skip-button.ts +++ b/src/interactions/components/nowplaying-skip-button.ts @@ -1,9 +1,9 @@ import { GuildQueue, Track, useQueue } from 'discord-player'; -import { EmbedBuilder, GuildMember } from 'discord.js'; -import { BaseComponentParams, BaseComponentReturnType } from '../../types/interactionTypes'; +import { EmbedBuilder } from 'discord.js'; import { BaseComponentInteraction } from '../../classes/interactions'; -import { checkQueueExists, checkQueueCurrentTrack } from '../../utils/validation/queueValidator'; -import { checkSameVoiceChannel, checkInVoiceChannel } from '../../utils/validation/voiceChannelValidator'; +import { BaseComponentParams, BaseComponentReturnType } from '../../types/interactionTypes'; +import { checkQueueCurrentTrack, checkQueueExists } from '../../utils/validation/queueValidator'; +import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator'; class NowplayingSkipButton extends BaseComponentInteraction { constructor() { @@ -85,22 +85,11 @@ class NowplayingSkipButton extends BaseComponentInteraction { const repeatModeString: string = queue.repeatMode === 0 ? '' : getRepeatModeMessage(queue.repeatMode); - let authorName: string; - - if (interaction.member instanceof GuildMember) { - authorName = interaction.member.nickname || interaction.user.username; - } else { - authorName = interaction.user.username; - } - logger.debug('Responding with success embed.'); return await interaction.editReply({ embeds: [ new EmbedBuilder() - .setAuthor({ - name: authorName, - iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl - }) + .setAuthor(await this.getEmbedUserAuthor(interaction)) .setDescription( `**${this.embedOptions.icons.skipped} Skipped track**\n**${durationFormat} [${ skippedTrack.title diff --git a/src/services/logger.ts b/src/services/logger.ts index c498f588..0840ad14 100644 --- a/src/services/logger.ts +++ b/src/services/logger.ts @@ -1,6 +1,5 @@ import config from 'config'; import pino, { DestinationStream, Logger, LoggerOptions } from 'pino'; - import { CustomLoggerOptions } from '../types/configTypes'; import { TargetOptions } from '../types/serviceTypes'; diff --git a/src/types/eventTypes.d.ts b/src/types/eventTypes.d.ts index 98762d95..4dd85e30 100644 --- a/src/types/eventTypes.d.ts +++ b/src/types/eventTypes.d.ts @@ -1,6 +1,5 @@ import { GuildQueuePlayerNode } from 'discord-player'; import { BaseGuildTextChannel } from 'discord.js'; - import { ExtendedClient } from './clientTypes'; export type ClientEventArguments = unknown[]; diff --git a/src/types/utilTypes.d.ts b/src/types/utilTypes.d.ts index 7428eff0..2ebe8384 100644 --- a/src/types/utilTypes.d.ts +++ b/src/types/utilTypes.d.ts @@ -1,6 +1,5 @@ import { GuildQueue, Player } from 'discord-player'; import { ChatInputCommandInteraction, MessageComponentInteraction } from 'discord.js'; - import { ExtendedClient } from './clientTypes'; export type RegisterEventListenersParams = { diff --git a/src/utils/deploySlashCommands.ts b/src/utils/deploySlashCommands.ts index 5abbb1ff..77f1d69c 100644 --- a/src/utils/deploySlashCommands.ts +++ b/src/utils/deploySlashCommands.ts @@ -1,19 +1,16 @@ -import 'dotenv/config'; - import config from 'config'; import { REST, RESTPostAPIChatInputApplicationCommandsJSONBody, RouteLike, Routes } from 'discord.js'; +import 'dotenv/config'; +import { randomUUID as uuidv4 } from 'node:crypto'; import fs from 'node:fs'; import path from 'node:path'; -import { randomUUID as uuidv4 } from 'node:crypto'; - +import { Logger } from 'pino'; import loggerModule from '../services/logger'; import { SystemOptions } from '../types/configTypes'; -import { Logger } from 'pino'; const systemOptions: SystemOptions = config.get('systemOptions'); const executionId: string = uuidv4(); - const logger: Logger = loggerModule.child({ module: 'deploy', name: 'deploySlashCommands', diff --git a/src/utils/factory/createClient.ts b/src/utils/factory/createClient.ts index 9c1f0ec5..ec12f276 100644 --- a/src/utils/factory/createClient.ts +++ b/src/utils/factory/createClient.ts @@ -1,7 +1,6 @@ import Discord, { Client } from 'discord.js'; - -import loggerModule from '../../services/logger'; import { Logger } from 'pino'; +import loggerModule from '../../services/logger'; export const createClient = async ({ executionId }: { executionId: string }) => { const logger: Logger = loggerModule.child({ diff --git a/src/utils/other/startLoadTest.ts b/src/utils/other/startLoadTest.ts index c632fc42..23952bdf 100644 --- a/src/utils/other/startLoadTest.ts +++ b/src/utils/other/startLoadTest.ts @@ -1,6 +1,5 @@ import config from 'config'; import { Channel, Client } from 'discord.js'; - import { Logger } from 'pino'; import loggerModule from '../../services/logger'; import { LoadTestOptions } from '../../types/configTypes'; diff --git a/src/utils/registerClientInteractions.ts b/src/utils/registerClientInteractions.ts index 2c3d8ed1..4c9fac3b 100644 --- a/src/utils/registerClientInteractions.ts +++ b/src/utils/registerClientInteractions.ts @@ -1,11 +1,10 @@ import { Collection } from 'discord.js'; import fs from 'node:fs'; import path from 'node:path'; - -import loggerModule from '../services/logger'; -import { RegisterClientInteractionsParams } from '../types/utilTypes'; import { Logger } from 'pino'; +import loggerModule from '../services/logger'; import { ExtendedClient } from '../types/clientTypes'; +import { RegisterClientInteractionsParams } from '../types/utilTypes'; export const registerClientInteractions = async ({ client, executionId }: RegisterClientInteractionsParams) => { const logger: Logger = loggerModule.child({ diff --git a/src/utils/registerEventListeners.ts b/src/utils/registerEventListeners.ts index 960be997..aac0226d 100644 --- a/src/utils/registerEventListeners.ts +++ b/src/utils/registerEventListeners.ts @@ -1,14 +1,13 @@ import config from 'config'; -import fs from 'node:fs'; -import path from 'node:path'; - import { GuildQueueEvents, Player, PlayerEvents } from 'discord-player'; import { Client } from 'discord.js'; +import fs from 'node:fs'; +import path from 'node:path'; +import { Logger } from 'pino'; import loggerModule from '../services/logger'; import { CustomLoggerOptions } from '../types/configTypes'; import { ClientEventArguments, PlayerEventArguments, ProcessEventArguments } from '../types/eventTypes'; import { CustomEvent, RegisterEventListenersParams } from '../types/utilTypes'; -import { Logger } from 'pino'; const loggerOptions: CustomLoggerOptions = config.get('loggerOptions'); diff --git a/src/utils/validation/permissionValidator.ts b/src/utils/validation/permissionValidator.ts index 6e7a6d49..d88f297f 100644 --- a/src/utils/validation/permissionValidator.ts +++ b/src/utils/validation/permissionValidator.ts @@ -9,10 +9,10 @@ import { VoiceChannel } from 'discord.js'; import { Logger } from 'pino'; +import { InteractionValidationError } from '../../classes/interactions'; import loggerModule from '../../services/logger'; import { EmbedOptions } from '../../types/configTypes'; import { ValidatorParams } from '../../types/utilTypes'; -import { InteractionValidationError } from '../../classes/interactions'; const embedOptions: EmbedOptions = config.get('embedOptions'); export const checkVoicePermissionJoinAndTalk = async ({ interaction, executionId }: ValidatorParams) => { diff --git a/src/utils/validation/queueValidator.ts b/src/utils/validation/queueValidator.ts index fd9a680b..9668eb74 100644 --- a/src/utils/validation/queueValidator.ts +++ b/src/utils/validation/queueValidator.ts @@ -1,10 +1,10 @@ import config from 'config'; import { EmbedBuilder, InteractionType } from 'discord.js'; import { Logger } from 'pino'; +import { InteractionValidationError } from '../../classes/interactions'; import loggerModule from '../../services/logger'; import { EmbedOptions } from '../../types/configTypes'; import { ValidatorParams } from '../../types/utilTypes'; -import { InteractionValidationError } from '../../classes/interactions'; const embedOptions: EmbedOptions = config.get('embedOptions'); export const checkQueueExists = async ({ interaction, queue, executionId }: ValidatorParams) => { diff --git a/src/utils/validation/systemCommandValidator.ts b/src/utils/validation/systemCommandValidator.ts index a8a1dd63..a208c12f 100644 --- a/src/utils/validation/systemCommandValidator.ts +++ b/src/utils/validation/systemCommandValidator.ts @@ -1,10 +1,10 @@ import config from 'config'; import { EmbedBuilder, InteractionType } from 'discord.js'; import { Logger } from 'pino'; +import { InteractionValidationError } from '../../classes/interactions'; import loggerModule from '../../services/logger'; import { EmbedOptions, SystemOptions } from '../../types/configTypes'; import { ValidatorParams } from '../../types/utilTypes'; -import { InteractionValidationError } from '../../classes/interactions'; const embedOptions: EmbedOptions = config.get('embedOptions'); const systemOptions: SystemOptions = config.get('systemOptions'); diff --git a/src/utils/validation/voiceChannelValidator.ts b/src/utils/validation/voiceChannelValidator.ts index 7759341d..0ad31947 100644 --- a/src/utils/validation/voiceChannelValidator.ts +++ b/src/utils/validation/voiceChannelValidator.ts @@ -1,10 +1,10 @@ import config from 'config'; import { EmbedBuilder, GuildMember, InteractionType } from 'discord.js'; import { Logger } from 'pino'; +import { InteractionValidationError } from '../../classes/interactions'; import loggerModule from '../../services/logger'; import { EmbedOptions } from '../../types/configTypes'; import { ValidatorParams } from '../../types/utilTypes'; -import { InteractionValidationError } from '../../classes/interactions'; const embedOptions: EmbedOptions = config.get('embedOptions'); export const checkInVoiceChannel = async ({ interaction, executionId }: ValidatorParams) => {