converted commands to classes

This commit is contained in:
Marius Begby committed 2023-08-31 13:22:28 +02:00
1 parent 335f4bb84e
commit d81fc1d2e7
35 files changed
+618 -768

No files matched your search

+21 -26
View File
@@ -13,33 +13,28 @@ import {
StringSelectMenuBuilder,
StringSelectMenuOptionBuilder
} from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { EmbedOptions, FFmpegFilterOption, FFmpegFilterOptions } from '../../../types/configTypes';
import { BaseSlashCommandInteraction } from '../../../types/interactionTypes';
import { FFmpegFilterOption, FFmpegFilterOptions } from '../../../types/configTypes';
import {
BaseSlashCommandInteraction,
BaseSlashCommandParams,
BaseSlashCommandReturnType
} from '../../../types/interactionTypes';
import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
const embedOptions: EmbedOptions = config.get('embedOptions');
const ffmpegFilterOptions: FFmpegFilterOptions = config.get('ffmpegFilterOptions');
const command: BaseSlashCommandInteraction = {
isNew: false,
isBeta: false,
data: new SlashCommandBuilder()
.setName('filters')
.setDescription('Toggle various audio filters during playback.')
.setDMPermission(false)
.setNSFW(false),
execute: async ({ interaction, executionId }) => {
const logger: Logger = loggerModule.child({
source: 'filters.js',
module: 'slashCommand',
name: '/filters',
executionId: executionId,
shardId: interaction.guild?.shardId,
guildId: interaction.guild?.id
});
class FiltersCommand extends BaseSlashCommandInteraction {
constructor() {
const data = new SlashCommandBuilder()
.setName('filters')
.setDescription('Toggle various audio filters during playback.');
super(data);
}
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction } = params;
const logger = this.getLogger(this.commandName, executionId, interaction);
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
@@ -92,7 +87,7 @@ const command: BaseSlashCommandInteraction = {
.setCustomId('filters-disable-button')
.setLabel('Disable all filters')
.setStyle(ButtonStyle.Secondary)
.setEmoji(embedOptions.icons.disable)
.setEmoji(this.embedOptions.icons.disable)
.toJSON();
const disableFiltersActionRow: APIActionRowComponent<APIMessageActionRowComponent> = {
@@ -105,11 +100,11 @@ const command: BaseSlashCommandInteraction = {
embeds: [
new EmbedBuilder()
.setDescription('**Toggle filters**\nEnable or disable audio filters for playback from the menu.')
.setColor(embedOptions.colors.info)
.setColor(this.embedOptions.colors.info)
],
components: [filterActionRow, disableFiltersActionRow]
});
}
};
}
export default command;
export default new FiltersCommand();
+20 -28
View File
@@ -1,32 +1,24 @@
import config from 'config';
import { GuildQueue, useQueue } from 'discord-player';
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { EmbedOptions } from '../../../types/configTypes';
import { BaseSlashCommandInteraction } from '../../../types/interactionTypes';
import {
BaseSlashCommandInteraction,
BaseSlashCommandParams,
BaseSlashCommandReturnType
} from '../../../types/interactionTypes';
import { queueDoesNotExist } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
const embedOptions: EmbedOptions = config.get('embedOptions');
class LeaveCommand extends BaseSlashCommandInteraction {
constructor() {
const data = new SlashCommandBuilder()
.setName('leave')
.setDescription('Clear the track queue and remove the bot from voice channel.');
super(data);
}
const command: BaseSlashCommandInteraction = {
isNew: false,
isBeta: false,
data: new SlashCommandBuilder()
.setName('leave')
.setDescription('Clear the track queue and remove the bot from voice channel.')
.setDMPermission(false)
.setNSFW(false),
execute: async ({ interaction, executionId }) => {
const logger: Logger = loggerModule.child({
source: 'leave.js',
module: 'slashCommand',
name: '/leave',
executionId: executionId,
shardId: interaction.guild?.shardId,
guildId: interaction.guild?.id
});
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction } = params;
const logger = this.getLogger(this.commandName, executionId, interaction);
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
@@ -61,15 +53,15 @@ const command: BaseSlashCommandInteraction = {
new EmbedBuilder()
.setAuthor({
name: authorName,
iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl
iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl
})
.setDescription(
`**${embedOptions.icons.success} Leaving channel**\nCleared the track queue and left voice channel.\n\nTo play more music, use the **\`/play\`** command!`
`**${this.embedOptions.icons.success} Leaving channel**\nCleared the track queue and left voice channel.\n\nTo play more music, use the **\`/play\`** command!`
)
.setColor(embedOptions.colors.success)
.setColor(this.embedOptions.colors.success)
]
});
}
};
}
export default command;
export default new LeaveCommand();
+44 -53
View File
@@ -1,45 +1,36 @@
import config from 'config';
import { GuildQueue, QueueRepeatMode, useQueue } from 'discord-player';
import { EmbedBuilder, GuildMember, SlashCommandBuilder, SlashCommandStringOption } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { BotOptions, EmbedOptions } from '../../../types/configTypes';
import { BaseSlashCommandInteraction } from '../../../types/interactionTypes';
import {
BaseSlashCommandInteraction,
BaseSlashCommandParams,
BaseSlashCommandReturnType
} from '../../../types/interactionTypes';
import { queueDoesNotExist } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
const embedOptions: EmbedOptions = config.get('embedOptions');
const botOptions: BotOptions = config.get('botOptions');
class LoopCommand extends BaseSlashCommandInteraction {
constructor() {
const data = new SlashCommandBuilder()
.setName('loop')
.setDescription('Toggle looping a track, the whole queue or autoplay.')
.addStringOption(() =>
new SlashCommandStringOption()
.setName('mode')
.setDescription('Mode to set for looping.')
.setRequired(false)
.addChoices(
{ name: 'Track', value: '1' },
{ name: 'Queue', value: '2' },
{ name: 'Autoplay', value: '3' },
{ name: 'Disabled', value: '0' }
)
);
super(data);
}
const command: BaseSlashCommandInteraction = {
isNew: false,
isBeta: false,
data: new SlashCommandBuilder()
.setName('loop')
.setDescription('Toggle looping a track, the whole queue or autoplay.')
.setDMPermission(false)
.setNSFW(false)
.addStringOption(() =>
new SlashCommandStringOption()
.setName('mode')
.setDescription('Mode to set for looping.')
.setRequired(false)
.addChoices(
{ name: 'Track', value: '1' },
{ name: 'Queue', value: '2' },
{ name: 'Autoplay', value: '3' },
{ name: 'Disabled', value: '0' }
)
),
execute: async ({ interaction, executionId }) => {
const logger: Logger = loggerModule.child({
source: 'loop.js',
module: 'slashCommand',
name: '/loop',
executionId: executionId,
shardId: interaction.guild?.shardId,
guildId: interaction.guild?.id
});
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction } = params;
const logger = this.getLogger(this.commandName, executionId, interaction);
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
@@ -77,10 +68,10 @@ const command: BaseSlashCommandInteraction = {
new EmbedBuilder()
.setDescription(
`**${
currentMode === 3 ? embedOptions.icons.autoplay : embedOptions.icons.loop
currentMode === 3 ? this.embedOptions.icons.autoplay : this.embedOptions.icons.loop
} Current loop mode**\nThe looping mode is currently set to **\`${currentModeUserString}\`**.`
)
.setColor(embedOptions.colors.info)
.setColor(this.embedOptions.colors.info)
]
});
}
@@ -93,9 +84,9 @@ const command: BaseSlashCommandInteraction = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedOptions.icons.warning} Oops!**\nLoop mode is already **\`${modeUserString}\`**.`
`**${this.embedOptions.icons.warning} Oops!**\nLoop mode is already **\`${modeUserString}\`**.`
)
.setColor(embedOptions.colors.warning)
.setColor(this.embedOptions.colors.warning)
]
});
}
@@ -114,9 +105,9 @@ const command: BaseSlashCommandInteraction = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedOptions.icons.error} Uh-oh... Failed to change loop mode!**\nI tried to change the loop mode to **\`${modeUserString}\`**, but something went wrong.\n\nYou can try to perform the command again.\n\n_If you think this message is incorrect or the issue persists, please submit a bug report in the **[support server](${botOptions.serverInviteUrl})**._`
`**${this.embedOptions.icons.error} Uh-oh... Failed to change loop mode!**\nI tried to change the loop mode to **\`${modeUserString}\`**, but something went wrong.\n\nYou can try to perform the command again.\n\n_If you think this message is incorrect or the issue persists, please submit a bug report in the **[support server](${this.botOptions.serverInviteUrl})**._`
)
.setColor(embedOptions.colors.error)
.setColor(this.embedOptions.colors.error)
.setFooter({ text: `Execution ID: ${executionId}` })
]
});
@@ -140,12 +131,12 @@ const command: BaseSlashCommandInteraction = {
new EmbedBuilder()
.setAuthor({
name: authorName,
iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl
iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl
})
.setDescription(
`**${embedOptions.icons.success} Loop mode disabled**\nChanging loop mode from **\`${currentModeUserString}\`** to **\`${modeUserString}\`**.\n\nThe ${currentModeUserString} will no longer play on repeat!`
`**${this.embedOptions.icons.success} Loop mode disabled**\nChanging loop mode from **\`${currentModeUserString}\`** to **\`${modeUserString}\`**.\n\nThe ${currentModeUserString} will no longer play on repeat!`
)
.setColor(embedOptions.colors.success)
.setColor(this.embedOptions.colors.success)
]
});
}
@@ -159,12 +150,12 @@ const command: BaseSlashCommandInteraction = {
new EmbedBuilder()
.setAuthor({
name: authorName,
iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl
iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl
})
.setDescription(
`**${embedOptions.icons.autoplaying} Loop mode changed**\nChanging loop mode from **\`${currentModeUserString}\`** to **\`${modeUserString}\`**.\n\nWhen the queue is empty, similar tracks will start playing!`
`**${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!`
)
.setColor(embedOptions.colors.success)
.setColor(this.embedOptions.colors.success)
]
});
}
@@ -177,15 +168,15 @@ const command: BaseSlashCommandInteraction = {
new EmbedBuilder()
.setAuthor({
name: authorName,
iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl
iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl
})
.setDescription(
`**${embedOptions.icons.looping} Loop mode changed**\nChanging loop mode from **\`${currentModeUserString}\`** to **\`${modeUserString}\`**.\n\nThe ${modeUserString} will now play on repeat!`
`**${this.embedOptions.icons.looping} Loop mode changed**\nChanging loop mode from **\`${currentModeUserString}\`** to **\`${modeUserString}\`**.\n\nThe ${modeUserString} will now play on repeat!`
)
.setColor(embedOptions.colors.success)
.setColor(this.embedOptions.colors.success)
]
});
}
};
}
export default command;
export default new LoopCommand();
+36 -49
View File
@@ -1,47 +1,34 @@
import config from 'config';
import { LyricsData, lyricsExtractor } from '@discord-player/extractor';
import { GuildQueue, Player, QueryType, useMainPlayer, useQueue } from 'discord-player';
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import { LyricsData, lyricsExtractor } from '@discord-player/extractor';
import loggerModule from '../../../services/logger';
import { BaseSlashCommandInteraction } from '../../../types/interactionTypes';
import { EmbedOptions } from '../../../types/configTypes';
import {
BaseSlashCommandInteraction,
BaseSlashCommandParams,
BaseSlashCommandReturnType
} from '../../../types/interactionTypes';
import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { Logger } from 'pino';
const embedOptions: EmbedOptions = config.get('embedOptions');
class LyricsCommand extends BaseSlashCommandInteraction {
constructor() {
const data = new SlashCommandBuilder()
.setName('lyrics')
.setDescription('Get lyrics from Genius for current or specified track.')
.addStringOption((option) =>
option
.setName('query')
.setDescription('Search query or URL.')
.setRequired(false)
.setMinLength(2)
.setMaxLength(500)
.setAutocomplete(true)
);
super(data);
}
const loggerTemplate: Logger = loggerModule.child({
source: 'lyrics.js',
module: 'slashCommand',
name: '/lyrics'
});
const command: BaseSlashCommandInteraction = {
isNew: false,
isBeta: false,
data: new SlashCommandBuilder()
.setName('lyrics')
.setDescription('Get lyrics from Genius for current or specified track.')
.setDMPermission(false)
.setNSFW(false)
.addStringOption((option) =>
option
.setName('query')
.setDescription('Search query or URL.')
.setRequired(false)
.setMinLength(2)
.setMaxLength(500)
.setAutocomplete(true)
),
execute: async ({ interaction, executionId }) => {
const logger: Logger = loggerTemplate.child({
executionId: executionId,
shardId: interaction.guild?.shardId,
guildId: interaction.guild?.id
});
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction } = params;
const logger = this.getLogger(this.commandName, executionId, interaction);
const query: string = interaction.options.getString('query')!;
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
@@ -84,9 +71,9 @@ const command: BaseSlashCommandInteraction = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedOptions.icons.warning} No search results found**\nThere was no search results found for query **${query}**.`
`**${this.embedOptions.icons.warning} No search results found**\nThere was no search results found for query **${query}**.`
)
.setColor(embedOptions.colors.warning)
.setColor(this.embedOptions.colors.warning)
]
});
}
@@ -144,9 +131,9 @@ const command: BaseSlashCommandInteraction = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedOptions.icons.warning} No lyrics found**\nThere was no Genius lyrics found for track **${geniusSearchQuery}**.`
`**${this.embedOptions.icons.warning} No lyrics found**\nThere was no Genius lyrics found for track **${geniusSearchQuery}**.`
)
.setColor(embedOptions.colors.warning)
.setColor(this.embedOptions.colors.warning)
]
});
}
@@ -166,12 +153,12 @@ const command: BaseSlashCommandInteraction = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedOptions.icons.queue} Showing lyrics**\n` +
`**${this.embedOptions.icons.queue} Showing lyrics**\n` +
`**Track: [${lyricsResult.title}](${lyricsResult.url})**\n` +
`**Artist: [${lyricsResult.artist.name}](${lyricsResult.artist.url})**` +
`\n\n\`\`\`fix\n${message}\`\`\``
)
.setColor(embedOptions.colors.info)
.setColor(this.embedOptions.colors.info)
]
});
continue;
@@ -181,7 +168,7 @@ const command: BaseSlashCommandInteraction = {
embeds: [
new EmbedBuilder()
.setDescription(`\`\`\`fix\n${message}\`\`\``)
.setColor(embedOptions.colors.info)
.setColor(this.embedOptions.colors.info)
]
});
}
@@ -195,15 +182,15 @@ const command: BaseSlashCommandInteraction = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedOptions.icons.queue} Showing lyrics**\n` +
`**${this.embedOptions.icons.queue} Showing lyrics**\n` +
`**Track: [${lyricsResult.title}](${lyricsResult.url})**\n` +
`**Artist: [${lyricsResult.artist.name}](${lyricsResult.artist.url})**` +
`\n\n\`\`\`fix\n${lyricsResult.lyrics}\`\`\``
)
.setColor(embedOptions.colors.info)
.setColor(this.embedOptions.colors.info)
]
});
}
};
}
export default command;
export default new LyricsCommand();
+33 -36
View File
@@ -10,34 +10,29 @@ import {
EmbedBuilder,
SlashCommandBuilder
} from 'discord.js';
import loggerModule from '../../../services/logger';
import { BaseSlashCommandInteraction, TrackMetadata } from '../../../types/interactionTypes';
import { EmbedOptions, PlayerOptions } from '../../../types/configTypes';
import { PlayerOptions } from '../../../types/configTypes';
import {
BaseSlashCommandInteraction,
BaseSlashCommandParams,
BaseSlashCommandReturnType,
TrackMetadata
} from '../../../types/interactionTypes';
import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { Logger } from 'pino';
const embedOptions: EmbedOptions = config.get('embedOptions');
const playerOptions: PlayerOptions = config.get('playerOptions');
const command: BaseSlashCommandInteraction = {
isNew: false,
isBeta: false,
data: new SlashCommandBuilder()
.setName('nowplaying')
.setDescription('Show information about the track currently playing.')
.setDMPermission(false)
.setNSFW(false),
execute: async ({ interaction, executionId }) => {
const logger: Logger = loggerModule.child({
source: 'nowplaying.js',
module: 'slashCommand',
name: '/nowplaying',
executionId: executionId,
shardId: interaction.guild?.shardId,
guildId: interaction.guild?.id
});
class NowPlayingCommand extends BaseSlashCommandInteraction {
constructor() {
const data = new SlashCommandBuilder()
.setName('nowplaying')
.setDescription('Show information about the track currently playing.');
super(data);
}
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction } = params;
const logger = this.getLogger(this.commandName, executionId, interaction);
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
@@ -64,11 +59,11 @@ const command: BaseSlashCommandInteraction = {
]);
const sourceIcons: Map<string, string> = new Map([
['youtube', embedOptions.icons.sourceYouTube],
['soundcloud', embedOptions.icons.sourceSoundCloud],
['spotify', embedOptions.icons.sourceSpotify],
['apple_music', embedOptions.icons.sourceAppleMusic],
['arbitrary', embedOptions.icons.sourceArbitrary]
['youtube', this.embedOptions.icons.sourceYouTube],
['soundcloud', this.embedOptions.icons.sourceSoundCloud],
['spotify', this.embedOptions.icons.sourceSpotify],
['apple_music', this.embedOptions.icons.sourceAppleMusic],
['arbitrary', this.embedOptions.icons.sourceArbitrary]
]);
const currentTrack: Track = queue.currentTrack!;
@@ -106,7 +101,7 @@ const command: BaseSlashCommandInteraction = {
}
if (currentTrack.raw.live) {
bar = `${embedOptions.icons.liveTrack} **\`LIVE\`** - Playing continuously from live source.`;
bar = `${this.embedOptions.icons.liveTrack} **\`LIVE\`** - Playing continuously from live source.`;
}
const customId: string = `nowplaying-skip-button_${currentTrack.id}`;
@@ -116,7 +111,7 @@ const command: BaseSlashCommandInteraction = {
.setCustomId(customId)
.setLabel('Skip track')
.setStyle(ButtonStyle.Secondary)
.setEmoji(embedOptions.icons.nextTrack)
.setEmoji(this.embedOptions.icons.nextTrack)
.toJSON();
const nowPlayingActionRow: APIActionRowComponent<APIMessageActionRowComponent> = {
@@ -141,12 +136,12 @@ const command: BaseSlashCommandInteraction = {
new EmbedBuilder()
.setAuthor({
name: `Channel: ${queue.channel!.name} (${queue.channel!.bitrate / 1000}kbps)`,
iconURL: interaction.guild!.iconURL() || embedOptions.info.fallbackIconUrl
iconURL: interaction.guild!.iconURL() || this.embedOptions.info.fallbackIconUrl
})
.setDescription(
(queue.node.isPaused()
? '**Currently Paused**\n'
: `**${embedOptions.icons.audioPlaying} Now Playing**\n`) +
: `**${this.embedOptions.icons.audioPlaying} Now Playing**\n`) +
`**[${currentTrack.title}](${currentTrack.raw.url ?? currentTrack.url})**` +
`\nRequested by: <@${currentTrack.requestedBy?.id}>` +
`\n ${bar}\n\n` +
@@ -154,7 +149,9 @@ const command: BaseSlashCommandInteraction = {
queue.repeatMode === 0
? ''
: `**${
queue.repeatMode === 3 ? embedOptions.icons.autoplay : embedOptions.icons.loop
queue.repeatMode === 3
? this.embedOptions.icons.autoplay
: this.embedOptions.icons.loop
} Looping**\nLoop mode is set to **\`${loopModeUserString}\`**. You can change it with **\`/loop\`**.`
}`
)
@@ -181,11 +178,11 @@ const command: BaseSlashCommandInteraction = {
text: queueLength ? `${queueLength} other tracks in the queue...` : ' '
})
.setThumbnail(queue.currentTrack!.thumbnail)
.setColor(embedOptions.colors.info)
.setColor(this.embedOptions.colors.info)
],
components: [nowPlayingActionRow as APIActionRowComponent<APIMessageActionRowComponent>]
});
}
};
}
export default command;
export default new NowPlayingCommand();
+20 -29
View File
@@ -1,32 +1,23 @@
import config from 'config';
import { GuildQueue, Track, useQueue } from 'discord-player';
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { EmbedOptions } from '../../../types/configTypes';
import { BaseSlashCommandInteraction } from '../../../types/interactionTypes';
import {
BaseSlashCommandInteraction,
BaseSlashCommandParams,
BaseSlashCommandReturnType
} from '../../../types/interactionTypes';
import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
const embedOptions: EmbedOptions = config.get('embedOptions');
class PauseCommand extends BaseSlashCommandInteraction {
constructor() {
const data = new SlashCommandBuilder().setName('pause').setDescription('Pause or resume the current track.');
super(data);
}
const command: BaseSlashCommandInteraction = {
isNew: false,
isBeta: false,
data: new SlashCommandBuilder()
.setName('pause')
.setDescription('Pause or resume the current track.')
.setDMPermission(false)
.setNSFW(false),
execute: async ({ interaction, executionId }) => {
const logger: Logger = loggerModule.child({
source: 'pause.js',
module: 'slashCommand',
name: '/pause',
executionId: executionId,
shardId: interaction.guild?.shardId,
guildId: interaction.guild?.id
});
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction } = params;
const logger = this.getLogger(this.commandName, executionId, interaction);
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
@@ -51,7 +42,7 @@ const command: BaseSlashCommandInteraction = {
: `\`${currentTrack.duration}\``;
if (currentTrack.raw.live) {
durationFormat = `${embedOptions.icons.liveTrack} \`LIVE\``;
durationFormat = `${this.embedOptions.icons.liveTrack} \`LIVE\``;
}
// change paused state to opposite of current state
@@ -72,18 +63,18 @@ const command: BaseSlashCommandInteraction = {
new EmbedBuilder()
.setAuthor({
name: authorName,
iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl
iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl
})
.setDescription(
`**${embedOptions.icons.pauseResumed} ${
`**${this.embedOptions.icons.pauseResumed} ${
queue.node.isPaused() ? 'Paused Track' : 'Resumed track'
}**\n**${durationFormat} [${currentTrack.title}](${currentTrack.raw.url ?? currentTrack.url})**`
)
.setThumbnail(currentTrack.thumbnail)
.setColor(embedOptions.colors.success)
.setColor(this.embedOptions.colors.success)
]
});
}
};
}
export default command;
export default new PauseCommand();
+53 -62
View File
@@ -1,48 +1,39 @@
import config from 'config';
import { GuildQueue, useMainPlayer, useQueue } from 'discord-player';
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
import loggerModule from '../../../services/logger';
import { CustomError, BaseSlashCommandInteraction } from '../../../types/interactionTypes';
import { BotOptions, EmbedOptions, PlayerOptions } from '../../../types/configTypes';
import { PlayerOptions } from '../../../types/configTypes';
import {
BaseSlashCommandInteraction,
BaseSlashCommandParams,
BaseSlashCommandReturnType,
CustomError
} from '../../../types/interactionTypes';
import { cannotJoinVoiceOrTalk } from '../../../utils/validation/permissionValidator';
import { transformQuery } from '../../../utils/validation/searchQueryValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { Logger } from 'pino';
const embedOptions: EmbedOptions = config.get('embedOptions');
const botOptions: BotOptions = config.get('botOptions');
const playerOptions: PlayerOptions = config.get('playerOptions');
const loggerTemplate: Logger = loggerModule.child({
source: 'play.js',
module: 'slashCommand',
name: '/play'
});
class PlayCommand extends BaseSlashCommandInteraction {
constructor() {
const data = new SlashCommandBuilder()
.setName('play')
.setDescription('Add a track or playlist to the queue by searching or url.')
.addStringOption((option) =>
option
.setName('query')
.setDescription('Search query or URL.')
.setRequired(true)
.setMinLength(2)
.setMaxLength(500)
.setAutocomplete(true)
);
super(data);
}
const command: BaseSlashCommandInteraction = {
isNew: false,
isBeta: false,
data: new SlashCommandBuilder()
.setName('play')
.setDescription('Add a track or playlist to the queue by searching or url.')
.setDMPermission(false)
.setNSFW(false)
.addStringOption((option) =>
option
.setName('query')
.setDescription('Search query or URL.')
.setRequired(true)
.setMinLength(2)
.setMaxLength(500)
.setAutocomplete(true)
),
execute: async ({ interaction, executionId }) => {
const logger = loggerTemplate.child({
executionId: executionId,
shardId: interaction.guild?.shardId,
guildId: interaction.guild?.id
});
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction } = params;
const logger = this.getLogger(this.commandName, executionId, interaction);
let queue: GuildQueue = useQueue(interaction.guild!.id)!;
if (queue && (await notInSameVoiceChannel({ interaction, queue, executionId }))) {
@@ -83,9 +74,9 @@ const command: BaseSlashCommandInteraction = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedOptions.icons.warning} No track found**\nNo results found for **\`${transformedQuery}\`**.\n\nIf you specified a URL, please make sure it is valid and public.`
`**${this.embedOptions.icons.warning} No track found**\nNo results found for **\`${transformedQuery}\`**.\n\nIf you specified a URL, please make sure it is valid and public.`
)
.setColor(embedOptions.colors.warning)
.setColor(this.embedOptions.colors.warning)
]
});
}
@@ -101,9 +92,9 @@ const command: BaseSlashCommandInteraction = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedOptions.icons.warning} Playlist too large**\nThis playlist is too large to be added to the queue.\n\nThe maximum amount of tracks that can be added to the queue is **${playerOptions.maxQueueSize}**.`
`**${this.embedOptions.icons.warning} Playlist too large**\nThis playlist is too large to be added to the queue.\n\nThe maximum amount of tracks that can be added to the queue is **${playerOptions.maxQueueSize}**.`
)
.setColor(embedOptions.colors.warning)
.setColor(this.embedOptions.colors.warning)
]
});
}
@@ -145,9 +136,9 @@ const command: BaseSlashCommandInteraction = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedOptions.icons.warning} Cannot retrieve audio for track**\nThis audio source is age restricted and requires login to access. Because of this I cannot retrieve the audio for the track.\n\n_If you think this message is incorrect, please submit a bug report in the **[support server](${botOptions.serverInviteUrl})**._`
`**${this.embedOptions.icons.warning} Cannot retrieve audio for track**\nThis audio source is age restricted and requires login to access. Because of this I cannot retrieve the audio for the track.\n\n_If you think this message is incorrect, please submit a bug report in the **[support server](${this.botOptions.serverInviteUrl})**._`
)
.setColor(embedOptions.colors.warning)
.setColor(this.embedOptions.colors.warning)
]
});
}
@@ -162,9 +153,9 @@ const command: BaseSlashCommandInteraction = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedOptions.icons.warning} Cannot retrieve audio for track**\nThis audio source cannot be played as the video source has a warning for graphic or sensistive topics. It requires a manual confirmation to to play the video, and because of this I am unable to extract the audio for this source.\n\n_If you think this message is incorrect, please submit a bug report in the **[support server](${botOptions.serverInviteUrl})**._`
`**${this.embedOptions.icons.warning} Cannot retrieve audio for track**\nThis audio source cannot be played as the video source has a warning for graphic or sensistive topics. It requires a manual confirmation to to play the video, and because of this I am unable to extract the audio for this source.\n\n_If you think this message is incorrect, please submit a bug report in the **[support server](${this.botOptions.serverInviteUrl})**._`
)
.setColor(embedOptions.colors.warning)
.setColor(this.embedOptions.colors.warning)
]
});
}
@@ -183,9 +174,9 @@ const command: BaseSlashCommandInteraction = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedOptions.icons.error} Uh-oh... Failed to add track!**\nAfter finding a result, I was unable to retrieve audio for the track.\n\nYou can try to perform the command again.\n\n_If you think this message is incorrect, please submit a bug report in the **[support server](${botOptions.serverInviteUrl})**._`
`**${this.embedOptions.icons.error} Uh-oh... Failed to add track!**\nAfter finding a result, I was unable to retrieve audio for the track.\n\nYou can try to perform the command again.\n\n_If you think this message is incorrect, please submit a bug report in the **[support server](${this.botOptions.serverInviteUrl})**._`
)
.setColor(embedOptions.colors.error)
.setColor(this.embedOptions.colors.error)
.setFooter({ text: `Execution ID: ${executionId}` })
]
});
@@ -199,9 +190,9 @@ const command: BaseSlashCommandInteraction = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedOptions.icons.error} Uh-oh... Failed to add track!**\nSomething unexpected happened and the operation was cancelled.\n\nYou can try to perform the command again.\n\n_If you think this message is incorrect, please submit a bug report in the **[support server](${botOptions.serverInviteUrl})**._`
`**${this.embedOptions.icons.error} Uh-oh... Failed to add track!**\nSomething unexpected happened and the operation was cancelled.\n\nYou can try to perform the command again.\n\n_If you think this message is incorrect, please submit a bug report in the **[support server](${this.botOptions.serverInviteUrl})**._`
)
.setColor(embedOptions.colors.error)
.setColor(this.embedOptions.colors.error)
.setFooter({ text: `Execution ID: ${executionId}` })
]
});
@@ -225,9 +216,9 @@ const command: BaseSlashCommandInteraction = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedOptions.icons.error} Uh-oh... Failed to add track!**\nThere was an issue adding this track to the queue.\n\nYou can try to perform the command again.\n\n_If this problem persists, please submit a bug report in the **[support server](${botOptions.serverInviteUrl})**._`
`**${this.embedOptions.icons.error} Uh-oh... Failed to add track!**\nThere was an issue adding this track to the queue.\n\nYou can try to perform the command again.\n\n_If this problem persists, please submit a bug report in the **[support server](${this.botOptions.serverInviteUrl})**._`
)
.setColor(embedOptions.colors.error)
.setColor(this.embedOptions.colors.error)
.setFooter({ text: `Execution ID: ${executionId}` })
]
});
@@ -243,14 +234,14 @@ const command: BaseSlashCommandInteraction = {
logger.debug(
`Track found but source is arbitrary or missing thumbnail. Using fallback thumbnail url. Query: '${query}'.`
);
track.thumbnail = embedOptions.info.fallbackThumbnailUrl;
track.thumbnail = this.embedOptions.info.fallbackThumbnailUrl;
}
let durationFormat =
Number(track.raw.duration) === 0 || track.duration === '0:00' ? '' : `\`${track.duration}\``;
if (track.raw.live) {
durationFormat = `${embedOptions.icons.liveTrack} \`LIVE\``;
durationFormat = `${this.embedOptions.icons.liveTrack} \`LIVE\``;
}
if (searchResult.playlist && searchResult.tracks.length > 1) {
@@ -270,17 +261,17 @@ const command: BaseSlashCommandInteraction = {
new EmbedBuilder()
.setAuthor({
name: authorName,
iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl
iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl
})
.setDescription(
`**${embedOptions.icons.success} Added playlist to queue**\n**${durationFormat} [${
`**${this.embedOptions.icons.success} Added playlist to queue**\n**${durationFormat} [${
track.title
}](${track.raw.url ?? track.url})**\n\nAnd **${
searchResult.tracks.length - 1
}** more tracks... **\`/queue\`** to view all.`
)
.setThumbnail(track.thumbnail)
.setColor(embedOptions.colors.success)
.setColor(this.embedOptions.colors.success)
]
});
}
@@ -302,15 +293,15 @@ const command: BaseSlashCommandInteraction = {
new EmbedBuilder()
.setAuthor({
name: authorName,
iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl
iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl
})
.setDescription(
`**${embedOptions.icons.audioStartedPlaying} Started playing**\n**${durationFormat} [${
`**${this.embedOptions.icons.audioStartedPlaying} Started playing**\n**${durationFormat} [${
track.title
}](${track.raw.url ?? track.url})**`
)
.setThumbnail(track.thumbnail)
.setColor(embedOptions.colors.success)
.setColor(this.embedOptions.colors.success)
]
});
}
@@ -331,18 +322,18 @@ const command: BaseSlashCommandInteraction = {
new EmbedBuilder()
.setAuthor({
name: authorName,
iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl
iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl
})
.setDescription(
`${embedOptions.icons.success} **Added to queue**\n**${durationFormat} [${track.title}](${
`${this.embedOptions.icons.success} **Added to queue**\n**${durationFormat} [${track.title}](${
track.raw.url ?? track.url
})**`
)
.setThumbnail(track.thumbnail)
.setColor(embedOptions.colors.success)
.setColor(this.embedOptions.colors.success)
]
});
}
};
}
export default command;
export default new PlayCommand();
+33 -34
View File
@@ -1,34 +1,32 @@
import config from 'config';
import { GuildQueue, PlayerTimestamp, Track, useQueue } from 'discord-player';
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { EmbedOptions, PlayerOptions } from '../../../types/configTypes';
import { BaseSlashCommandInteraction } from '../../../types/interactionTypes';
import {
BaseSlashCommandInteraction,
BaseSlashCommandParams,
BaseSlashCommandReturnType
} from '../../../types/interactionTypes';
import { queueDoesNotExist } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
const embedOptions: EmbedOptions = config.get('embedOptions');
const playerOptions: PlayerOptions = config.get('playerOptions');
const command: BaseSlashCommandInteraction = {
isNew: false,
isBeta: false,
data: new SlashCommandBuilder()
.setName('queue')
.setDescription('Show the list of tracks added to the queue.')
.setDMPermission(false)
.setNSFW(false)
.addNumberOption((option) => option.setName('page').setDescription('Page number of the queue').setMinValue(1)),
execute: async ({ interaction, executionId }) => {
const logger: Logger = loggerModule.child({
source: 'queue.js',
module: 'slashCommand',
name: '/queue',
executionId: executionId,
shardId: interaction.guild?.shardId,
guildId: interaction.guild?.id
});
class QueueCommand extends BaseSlashCommandInteraction {
constructor() {
const data = new SlashCommandBuilder()
.setName('queue')
.setDescription('Show the list of tracks added to the queue.')
.addNumberOption((option) =>
option.setName('page').setDescription('Page number of the queue').setMinValue(1)
);
super(data);
}
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction } = params;
const logger = this.getLogger(this.commandName, executionId, interaction);
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
@@ -58,11 +56,11 @@ const command: BaseSlashCommandInteraction = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedOptions.icons.warning} Oops!**\nPage **\`${
`**${this.embedOptions.icons.warning} Oops!**\nPage **\`${
pageIndex + 1
}\`** is not a valid page number.\n\nThere are only a total of **\`${totalPages}\`** pages in the queue.`
)
.setColor(embedOptions.colors.warning)
.setColor(this.embedOptions.colors.warning)
]
});
}
@@ -78,7 +76,7 @@ const command: BaseSlashCommandInteraction = {
Number(track.raw.duration) === 0 || track.duration === '0:00' ? '' : `\`${track.duration}\``;
if (track.raw.live) {
durationFormat = `${embedOptions.icons.liveTrack} \`LIVE\``;
durationFormat = `${this.embedOptions.icons.liveTrack} \`LIVE\``;
}
return `**${pageIndex * 10 + index + 1}.** **${durationFormat} [${track.title}](${
@@ -116,15 +114,16 @@ const command: BaseSlashCommandInteraction = {
new EmbedBuilder()
.setAuthor({
name: `Channel: ${queue.channel!.name} (${queue.channel!.bitrate / 1000}kbps)`,
iconURL: interaction.guild!.iconURL() || embedOptions.info.fallbackIconUrl
iconURL: interaction.guild!.iconURL() || this.embedOptions.info.fallbackIconUrl
})
.setDescription(
`${repeatModeString}` + `**${embedOptions.icons.queue} Tracks in queue**\n${queueString}`
`${repeatModeString}` +
`**${this.embedOptions.icons.queue} Tracks in queue**\n${queueString}`
)
.setFooter({
text: `Page ${pageIndex + 1} of ${totalPages} (${queueLength} tracks)`
})
.setColor(embedOptions.colors.info)
.setColor(this.embedOptions.colors.info)
]
});
} else {
@@ -144,7 +143,7 @@ const command: BaseSlashCommandInteraction = {
}
if (currentTrack.raw.live) {
bar = `${embedOptions.icons.liveTrack} **\`LIVE\`** - Playing continuously from live source.`;
bar = `${this.embedOptions.icons.liveTrack} **\`LIVE\`** - Playing continuously from live source.`;
}
logger.debug('Responding with info embed.');
@@ -153,27 +152,27 @@ const command: BaseSlashCommandInteraction = {
new EmbedBuilder()
.setAuthor({
name: `Channel: ${queue.channel!.name} (${queue.channel!.bitrate / 1000}kbps)`,
iconURL: interaction.guild!.iconURL() || embedOptions.info.fallbackIconUrl
iconURL: interaction.guild!.iconURL() || this.embedOptions.info.fallbackIconUrl
})
.setDescription(
`**${embedOptions.icons.audioPlaying} Now playing**\n` +
`**${this.embedOptions.icons.audioPlaying} Now playing**\n` +
(currentTrack
? `**[${currentTrack.title}](${currentTrack.raw.url ?? currentTrack.url})**`
: 'None') +
`\nRequested by: <@${currentTrack.requestedBy?.id}>` +
`\n ${bar}\n\n` +
`${repeatModeString}` +
`**${embedOptions.icons.queue} Tracks in queue**\n${queueString}`
`**${this.embedOptions.icons.queue} Tracks in queue**\n${queueString}`
)
.setThumbnail(currentTrack.thumbnail)
.setFooter({
text: `Page ${pageIndex + 1} of ${totalPages} (${queueLength} tracks)`
})
.setColor(embedOptions.colors.info)
.setColor(this.embedOptions.colors.info)
]
});
}
}
};
}
export default command;
export default new QueueCommand();
+32 -40
View File
@@ -1,39 +1,31 @@
import config from 'config';
import { GuildQueue, Track, useQueue } from 'discord-player';
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { EmbedOptions } from '../../../types/configTypes';
import { BaseSlashCommandInteraction } from '../../../types/interactionTypes';
import {
BaseSlashCommandInteraction,
BaseSlashCommandParams,
BaseSlashCommandReturnType
} from '../../../types/interactionTypes';
import { queueDoesNotExist } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
const embedOptions: EmbedOptions = config.get('embedOptions');
class RemoveCommand extends BaseSlashCommandInteraction {
constructor() {
const data = new SlashCommandBuilder()
.setName('remove')
.setDescription('Remove a specific track from the queue')
.addNumberOption((option) =>
option
.setName('tracknumber')
.setDescription('Track number to remove from queue.')
.setMinValue(1)
.setRequired(true)
);
super(data);
}
const command: BaseSlashCommandInteraction = {
isNew: false,
isBeta: false,
data: new SlashCommandBuilder()
.setName('remove')
.setDescription('Remove a specific track from the queue.')
.setDMPermission(false)
.setNSFW(false)
.addNumberOption((option) =>
option
.setName('tracknumber')
.setDescription('Track number to remove from queue.')
.setMinValue(1)
.setRequired(true)
),
execute: async ({ interaction, executionId }) => {
const logger: Logger = loggerModule.child({
source: 'remove.js',
module: 'slashCommand',
name: '/remove',
executionId: executionId,
shardId: interaction.guild?.shardId,
guildId: interaction.guild?.id
});
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction } = params;
const logger = this.getLogger(this.commandName, executionId, interaction);
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
@@ -59,9 +51,9 @@ const command: BaseSlashCommandInteraction = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedOptions.icons.warning} Oops!**\nTrack **\`${removeTrackNumber}\`** is not a valid track number. There are a total of **\`${queue.tracks.data.length}\`** tracks in the queue.\n\nView tracks added to the queue with **\`/queue\`**.`
`**${this.embedOptions.icons.warning} Oops!**\nTrack **\`${removeTrackNumber}\`** is not a valid track number. There are a total of **\`${queue.tracks.data.length}\`** tracks in the queue.\n\nView tracks added to the queue with **\`/queue\`**.`
)
.setColor(embedOptions.colors.warning)
.setColor(this.embedOptions.colors.warning)
]
});
}
@@ -75,7 +67,7 @@ const command: BaseSlashCommandInteraction = {
: `\`${removedTrack.duration}\``;
if (removedTrack.raw.live) {
durationFormat = `${embedOptions.icons.liveTrack} \`LIVE\``;
durationFormat = `${this.embedOptions.icons.liveTrack} \`LIVE\``;
}
let authorName: string;
@@ -92,18 +84,18 @@ const command: BaseSlashCommandInteraction = {
new EmbedBuilder()
.setAuthor({
name: authorName,
iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl
iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl
})
.setDescription(
`**${embedOptions.icons.success} Removed track**\n**${durationFormat} [${removedTrack.title}](${
removedTrack.raw.url ?? removedTrack.url
})**`
`**${this.embedOptions.icons.success} Removed track**\n**${durationFormat} [${
removedTrack.title
}](${removedTrack.raw.url ?? removedTrack.url})**`
)
.setThumbnail(removedTrack.thumbnail)
.setColor(embedOptions.colors.success)
.setColor(this.embedOptions.colors.success)
]
});
}
};
}
export default command;
export default new RemoveCommand();
+34 -42
View File
@@ -1,38 +1,30 @@
import config from 'config';
import { GuildQueue, useQueue } from 'discord-player';
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { EmbedOptions } from '../../../types/configTypes';
import { BaseSlashCommandInteraction } from '../../../types/interactionTypes';
import {
BaseSlashCommandInteraction,
BaseSlashCommandParams,
BaseSlashCommandReturnType
} from '../../../types/interactionTypes';
import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
const embedOptions: EmbedOptions = config.get('embedOptions');
class SeekCommand extends BaseSlashCommandInteraction {
constructor() {
const data = new SlashCommandBuilder()
.setName('seek')
.setDescription('Seek to a specified duration in the current track.')
.addStringOption((option) =>
option
.setName('duration')
.setDescription('Duration in format 00:00:00 (HH:mm:ss) to seek to.')
.setRequired(true)
);
super(data);
}
const command: BaseSlashCommandInteraction = {
isNew: false,
isBeta: false,
data: new SlashCommandBuilder()
.setName('seek')
.setDescription('Seek to a specified duration in the current track.')
.setDMPermission(false)
.setNSFW(false)
.addStringOption((option) =>
option
.setName('duration')
.setDescription('Duration in format 00:00:00 (HH:mm:ss) to seek to.')
.setRequired(true)
),
execute: async ({ interaction, executionId }) => {
const logger: Logger = loggerModule.child({
source: 'seek.js',
module: 'slashCommand',
name: '/seek',
executionId: executionId,
shardId: interaction.guild?.shardId,
guildId: interaction.guild?.id
});
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction } = params;
const logger = this.getLogger(this.commandName, executionId, interaction);
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
@@ -78,12 +70,12 @@ const command: BaseSlashCommandInteraction = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedOptions.icons.warning} Oops!**\nYou entered an invalid duration format, **\`${durationString}\`**.\n\nPlease use the format **\`HH:mm:ss\`**, **\`mm:ss\`** or **\`ss\`**, where **\`HH\`** is hours, **\`mm\`** is minutes and **\`ss\`** is seconds.\n\n**Examples:**\n` +
`**${this.embedOptions.icons.warning} Oops!**\nYou entered an invalid duration format, **\`${durationString}\`**.\n\nPlease use the format **\`HH:mm:ss\`**, **\`mm:ss\`** or **\`ss\`**, where **\`HH\`** is hours, **\`mm\`** is minutes and **\`ss\`** is seconds.\n\n**Examples:**\n` +
'- **`/seek`** **`1:24:12`** - Seek to 1 hour, 24 minutes and 12 seconds.\n' +
'- **`/seek`** **`3:27`** - Seek to 3 minutes and 27 seconds.\n' +
'- **`/seek`** **`42`** - Seek to 42 seconds.'
)
.setColor(embedOptions.colors.warning)
.setColor(this.embedOptions.colors.warning)
]
});
}
@@ -100,12 +92,12 @@ const command: BaseSlashCommandInteraction = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedOptions.icons.warning} Oops!**\nYou entered an invalid duration format, **\`${durationString}\`**.\n\nPlease use the format **\`HH:mm:ss\`**, **\`mm:ss\`** or **\`ss\`**, where **\`HH\`** is hours, **\`mm\`** is minutes and **\`ss\`** is seconds.\n\n**Examples:**\n` +
`**${this.embedOptions.icons.warning} Oops!**\nYou entered an invalid duration format, **\`${durationString}\`**.\n\nPlease use the format **\`HH:mm:ss\`**, **\`mm:ss\`** or **\`ss\`**, where **\`HH\`** is hours, **\`mm\`** is minutes and **\`ss\`** is seconds.\n\n**Examples:**\n` +
'- **`/seek`** **`1:24:12`** - Seek to 1 hour, 24 minutes and 12 seconds.\n' +
'- **`/seek`** **`3:27`** - Seek to 3 minutes and 27 seconds.\n' +
'- **`/seek`** **`42`** - Seek to 42 seconds.'
)
.setColor(embedOptions.colors.warning)
.setColor(this.embedOptions.colors.warning)
]
});
}
@@ -123,12 +115,12 @@ const command: BaseSlashCommandInteraction = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedOptions.icons.warning} Oops!**\nYou entered an invalid duration format, **\`${durationString}\`**.\n\nPlease use the format **\`HH:mm:ss\`**, **\`mm:ss\`** or **\`ss\`**, where **\`HH\`** is hours, **\`mm\`** is minutes and **\`ss\`** is seconds.\n\n**Examples:**\n` +
`**${this.embedOptions.icons.warning} Oops!**\nYou entered an invalid duration format, **\`${durationString}\`**.\n\nPlease use the format **\`HH:mm:ss\`**, **\`mm:ss\`** or **\`ss\`**, where **\`HH\`** is hours, **\`mm\`** is minutes and **\`ss\`** is seconds.\n\n**Examples:**\n` +
'- **`/seek`** **`1:24:12`** - Seek to 1 hour, 24 minutes and 12 seconds.\n' +
'- **`/seek`** **`3:27`** - Seek to 3 minutes and 27 seconds.\n' +
'- **`/seek`** **`42`** - Seek to 42 seconds.'
)
.setColor(embedOptions.colors.warning)
.setColor(this.embedOptions.colors.warning)
]
});
}
@@ -146,12 +138,12 @@ const command: BaseSlashCommandInteraction = {
new EmbedBuilder()
.setDescription(
`**${
embedOptions.icons.warning
this.embedOptions.icons.warning
} Oops!**\nYou entered **\`${durationString}\`**, which is a duration that is longer than the duration for the current track.\n\nPlease try a duration that is less than the duration of the track (**\`${
queue.currentTrack!.duration
}\`**).`
)
.setColor(embedOptions.colors.warning)
.setColor(this.embedOptions.colors.warning)
]
});
}
@@ -173,16 +165,16 @@ const command: BaseSlashCommandInteraction = {
new EmbedBuilder()
.setAuthor({
name: authorName,
iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl
iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl
})
.setDescription(
`**${embedOptions.icons.success} Seeking to duration**\nSeeking to **\`${durationString}\`** in current track.`
`**${this.embedOptions.icons.success} Seeking to duration**\nSeeking to **\`${durationString}\`** in current track.`
)
.setThumbnail(queue.currentTrack!.thumbnail)
.setColor(embedOptions.colors.success)
.setColor(this.embedOptions.colors.success)
]
});
}
};
}
export default command;
export default new SeekCommand();
+20 -28
View File
@@ -1,32 +1,24 @@
import config from 'config';
import { GuildQueue, useQueue } from 'discord-player';
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { EmbedOptions } from '../../../types/configTypes';
import { BaseSlashCommandInteraction } from '../../../types/interactionTypes';
import {
BaseSlashCommandInteraction,
BaseSlashCommandParams,
BaseSlashCommandReturnType
} from '../../../types/interactionTypes';
import { queueDoesNotExist, queueIsEmpty } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
const embedOptions: EmbedOptions = config.get('embedOptions');
class ShuffleCommand extends BaseSlashCommandInteraction {
constructor() {
const data = new SlashCommandBuilder()
.setName('shuffle')
.setDescription('Shuffle tracks in the queue randomly.');
super(data);
}
const command: BaseSlashCommandInteraction = {
isNew: false,
isBeta: false,
data: new SlashCommandBuilder()
.setName('shuffle')
.setDescription('Shuffle tracks in the queue randomly.')
.setDMPermission(false)
.setNSFW(false),
execute: async ({ interaction, executionId }) => {
const logger: Logger = loggerModule.child({
source: 'shuffle.js',
module: 'slashCommand',
name: '/shuffle',
executionId: executionId,
shardId: interaction.guild?.shardId,
guildId: interaction.guild?.id
});
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction } = params;
const logger = this.getLogger(this.commandName, executionId, interaction);
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
@@ -60,15 +52,15 @@ const command: BaseSlashCommandInteraction = {
new EmbedBuilder()
.setAuthor({
name: authorName,
iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl
iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl
})
.setDescription(
`**${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\`**.`
`**${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\`**.`
)
.setColor(embedOptions.colors.success)
.setColor(this.embedOptions.colors.success)
]
});
}
};
}
export default command;
export default new ShuffleCommand();
+34 -42
View File
@@ -1,35 +1,27 @@
import config from 'config';
import { GuildQueue, Track, useQueue } from 'discord-player';
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { EmbedOptions } from '../../../types/configTypes';
import { BaseSlashCommandInteraction } from '../../../types/interactionTypes';
import {
BaseSlashCommandInteraction,
BaseSlashCommandParams,
BaseSlashCommandReturnType
} from '../../../types/interactionTypes';
import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
const embedOptions: EmbedOptions = config.get('embedOptions');
class SkipCommand extends BaseSlashCommandInteraction {
constructor() {
const data = new SlashCommandBuilder()
.setName('test')
.setDescription('Skip current or specified track.')
.addNumberOption((option) =>
option.setName('tracknumber').setDescription('Track number to skip to in the queue.').setMinValue(1)
);
super(data);
}
const command: BaseSlashCommandInteraction = {
isNew: false,
isBeta: false,
data: new SlashCommandBuilder()
.setName('skip')
.setDescription('Skip current or specified track.')
.setDMPermission(false)
.setNSFW(false)
.addNumberOption((option) =>
option.setName('tracknumber').setDescription('Track number to skip to in the queue.').setMinValue(1)
),
execute: async ({ interaction, executionId }) => {
const logger: Logger = loggerModule.child({
source: 'skip.js',
module: 'slashCommand',
name: '/skip',
executionId: executionId,
shardId: interaction.guild?.shardId,
guildId: interaction.guild?.id
});
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction } = params;
const logger = this.getLogger(this.commandName, executionId, interaction);
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
@@ -57,9 +49,9 @@ const command: BaseSlashCommandInteraction = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedOptions.icons.warning} Oops!**\nThere are only **\`${queue.tracks.data.length}\`** tracks in the queue. You cannot skip to track **\`${skipToTrack}\`**.\n\nView tracks added to the queue with **\`/queue\`**.`
`**${this.embedOptions.icons.warning} Oops!**\nThere are only **\`${queue.tracks.data.length}\`** tracks in the queue. You cannot skip to track **\`${skipToTrack}\`**.\n\nView tracks added to the queue with **\`/queue\`**.`
)
.setColor(embedOptions.colors.warning)
.setColor(this.embedOptions.colors.warning)
]
});
} else {
@@ -72,7 +64,7 @@ const command: BaseSlashCommandInteraction = {
: `\`${skippedTrack.duration}\``;
if (skippedTrack.raw.live) {
durationFormat = `${embedOptions.icons.liveTrack} \`LIVE\``;
durationFormat = `${this.embedOptions.icons.liveTrack} \`LIVE\``;
}
queue.node.skipTo(skipToTrack - 1);
@@ -92,15 +84,15 @@ const command: BaseSlashCommandInteraction = {
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} [${
`**${this.embedOptions.icons.skipped} Skipped track**\n**${durationFormat} [${
skippedTrack.title
}](${skippedTrack.raw.url ?? skippedTrack.url})**`
)
.setThumbnail(skippedTrack.thumbnail)
.setColor(embedOptions.colors.success)
.setColor(this.embedOptions.colors.success)
]
});
}
@@ -113,9 +105,9 @@ const command: BaseSlashCommandInteraction = {
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)
]
});
}
@@ -128,7 +120,7 @@ const command: BaseSlashCommandInteraction = {
: `\`${skippedTrack.duration}\``;
if (skippedTrack.raw.live) {
durationFormat = `${embedOptions.icons.liveTrack} \`LIVE\``;
durationFormat = `${this.embedOptions.icons.liveTrack} \`LIVE\``;
}
queue.node.skip();
logger.debug('Skipped current track.');
@@ -156,10 +148,10 @@ const command: BaseSlashCommandInteraction = {
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} [${
`**${this.embedOptions.icons.skipped} Skipped track**\n**${durationFormat} [${
skippedTrack.title
}](${skippedTrack.raw.url ?? skippedTrack.url})**` +
`${
@@ -167,17 +159,17 @@ const command: BaseSlashCommandInteraction = {
? ''
: `\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 **\`${loopModeUserString}\`**. You can change it with **\`/loop\`**.`
}`
)
.setThumbnail(skippedTrack.thumbnail)
.setColor(embedOptions.colors.success)
.setColor(this.embedOptions.colors.success)
]
});
}
}
};
}
export default command;
export default new SkipCommand();
+20 -28
View File
@@ -1,32 +1,24 @@
import config from 'config';
import { GuildQueue, useQueue } from 'discord-player';
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { EmbedOptions } from '../../../types/configTypes';
import { BaseSlashCommandInteraction } from '../../../types/interactionTypes';
import {
BaseSlashCommandInteraction,
BaseSlashCommandParams,
BaseSlashCommandReturnType
} from '../../../types/interactionTypes';
import { queueDoesNotExist } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
const embedOptions: EmbedOptions = config.get('embedOptions');
class StopCommand extends BaseSlashCommandInteraction {
constructor() {
const data = new SlashCommandBuilder()
.setName('stop')
.setDescription('Stop playing audio and clear the track queue.');
super(data);
}
const command: BaseSlashCommandInteraction = {
isNew: false,
isBeta: false,
data: new SlashCommandBuilder()
.setName('stop')
.setDescription('Stop playing audio and clear the track queue.')
.setDMPermission(false)
.setNSFW(false),
execute: async ({ interaction, executionId }) => {
const logger: Logger = loggerModule.child({
source: 'stop.js',
module: 'slashCommand',
name: '/stop',
executionId: executionId,
shardId: interaction.guild?.shardId,
guildId: interaction.guild?.id
});
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction } = params;
const logger = this.getLogger(this.commandName, executionId, interaction);
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
@@ -63,15 +55,15 @@ const command: BaseSlashCommandInteraction = {
new EmbedBuilder()
.setAuthor({
name: authorName,
iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl
iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl
})
.setDescription(
`**${embedOptions.icons.success} Stopped playing**\nStopped playing audio and cleared the track queue.\n\nTo play more music, use the **\`/play\`** command!`
`**${this.embedOptions.icons.success} Stopped playing**\nStopped playing audio and cleared the track queue.\n\nTo play more music, use the **\`/play\`** command!`
)
.setColor(embedOptions.colors.success)
.setColor(this.embedOptions.colors.success)
]
});
}
};
}
export default command;
export default new StopCommand();
+2 -5
View File
@@ -15,12 +15,9 @@ class TestCommand extends BaseSlashCommandInteraction {
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction } = params;
const logger = this.getLogger('test.js', executionId, interaction);
const logger = this.getLogger(this.commandName, executionId, interaction);
logger.debug('Responding with success embed.');
return await interaction.editReply({
embeds: [new EmbedBuilder().setDescription(`Success reply from command '${this.commandName}'.`).setColor(this.embedOptions.colors.success)]
});
// logic
}
}
+36 -42
View File
@@ -1,39 +1,31 @@
import config from 'config';
import { GuildQueue, useQueue } from 'discord-player';
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { EmbedOptions } from '../../../types/configTypes';
import { BaseSlashCommandInteraction } from '../../../types/interactionTypes';
import {
BaseSlashCommandInteraction,
BaseSlashCommandParams,
BaseSlashCommandReturnType
} from '../../../types/interactionTypes';
import { queueDoesNotExist } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
const embedOptions: EmbedOptions = config.get('embedOptions');
class VolumeCommand extends BaseSlashCommandInteraction {
constructor() {
const data = new SlashCommandBuilder()
.setName('volume')
.setDescription('Show or set the playback volume for tracks.')
.addNumberOption((option) =>
option
.setName('percentage')
.setDescription('Set volume percentage from 1% to 100%.')
.setMinValue(0)
.setMaxValue(100)
);
super(data);
}
const command: BaseSlashCommandInteraction = {
isNew: false,
isBeta: false,
data: new SlashCommandBuilder()
.setName('volume')
.setDescription('Show or set the playback volume for tracks.')
.setDMPermission(false)
.setNSFW(false)
.addNumberOption((option) =>
option
.setName('percentage')
.setDescription('Set volume percentage from 1% to 100%.')
.setMinValue(0)
.setMaxValue(100)
),
execute: async ({ interaction, executionId }) => {
const logger: Logger = loggerModule.child({
source: 'volume.js',
module: 'slashCommand',
name: '/volume',
executionId: executionId,
shardId: interaction.guild?.shardId,
guildId: interaction.guild?.id
});
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction } = params;
const logger = this.getLogger(this.commandName, executionId, interaction);
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
@@ -62,10 +54,12 @@ const command: BaseSlashCommandInteraction = {
new EmbedBuilder()
.setDescription(
`**${
currentVolume === 0 ? embedOptions.icons.volumeIsMuted : embedOptions.icons.volume
currentVolume === 0
? this.embedOptions.icons.volumeIsMuted
: this.embedOptions.icons.volume
} Playback volume**\nThe playback volume is currently set to **\`${currentVolume}%\`**.`
)
.setColor(embedOptions.colors.info)
.setColor(this.embedOptions.colors.info)
]
});
} else if (volume > 100 || volume < 0) {
@@ -76,9 +70,9 @@ const command: BaseSlashCommandInteraction = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedOptions.icons.warning} Oops!**\nYou cannot set the volume to **\`${volume}%\`**, please pick a value betwen **\`1%\`** and **\`100%\`**.`
`**${this.embedOptions.icons.warning} Oops!**\nYou cannot set the volume to **\`${volume}%\`**, please pick a value betwen **\`1%\`** and **\`100%\`**.`
)
.setColor(embedOptions.colors.warning)
.setColor(this.embedOptions.colors.warning)
]
});
} else {
@@ -100,12 +94,12 @@ const command: BaseSlashCommandInteraction = {
new EmbedBuilder()
.setAuthor({
name: authorName,
iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl
iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl
})
.setDescription(
`**${embedOptions.icons.volumeMuted} Audio muted**\nPlayback audio has been muted, because volume was set to **\`${volume}%\`**.`
`**${this.embedOptions.icons.volumeMuted} Audio muted**\nPlayback audio has been muted, because volume was set to **\`${volume}%\`**.`
)
.setColor(embedOptions.colors.success)
.setColor(this.embedOptions.colors.success)
]
});
}
@@ -116,16 +110,16 @@ const command: BaseSlashCommandInteraction = {
new EmbedBuilder()
.setAuthor({
name: authorName,
iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl
iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl
})
.setDescription(
`**${embedOptions.icons.volumeChanged} Volume changed**\nPlayback volume has been changed to **\`${volume}%\`**.`
`**${this.embedOptions.icons.volumeChanged} Volume changed**\nPlayback volume has been changed to **\`${volume}%\`**.`
)
.setColor(embedOptions.colors.success)
.setColor(this.embedOptions.colors.success)
]
});
}
}
};
}
export default command;
export default new VolumeCommand();