mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-04 06:28:53 +00:00
feat!: Change interaction structure and handling of component responses
This commit is contained in:
1 parent
905df36ef8
commit
9b02b21283
24 files changed
+232
-239
No files matched your search
@@ -1,5 +1,5 @@
|
|||||||
import config from 'config';
|
import config from 'config';
|
||||||
import { EmbedBuilder, Events, Interaction, StringSelectMenuInteraction } from 'discord.js';
|
import { EmbedBuilder, Events, Interaction } from 'discord.js';
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
|
|
||||||
import loggerModule from '../../services/logger';
|
import loggerModule from '../../services/logger';
|
||||||
@@ -24,15 +24,11 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (interaction.isMessageComponent()) {
|
if (interaction.isMessageComponent()) {
|
||||||
if (interaction instanceof StringSelectMenuInteraction) {
|
await interaction.deferReply();
|
||||||
logger.debug(
|
const componentId = interaction.customId.split('_')[0];
|
||||||
`Message component interaction created for id ${interaction.customId}${
|
const trackId = interaction.customId.split('_')[1];
|
||||||
interaction.values ? ' and values ' + interaction.values : ''
|
const componentModule = await import(`../../interactions/component/${componentId}.js`);
|
||||||
}.`
|
return componentModule.execute({ interaction, trackId, executionId });
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (interaction.isChatInputCommand() || interaction.isAutocomplete()) {
|
if (interaction.isChatInputCommand() || interaction.isAutocomplete()) {
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import config from 'config';
|
import config from 'config';
|
||||||
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||||
|
|
||||||
import loggerModule from '../../services/logger';
|
import loggerModule from '../../../services/logger';
|
||||||
import { CommandParams } from '../../types/commandTypes';
|
import { CommandParams } from '../../../types/commandTypes';
|
||||||
import { BotOptions, EmbedOptions } from '../../types/configTypes';
|
import { BotOptions, EmbedOptions } from '../../../types/configTypes';
|
||||||
|
|
||||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||||
const botOptions: BotOptions = config.get('botOptions');
|
const botOptions: BotOptions = config.get('botOptions');
|
||||||
@@ -3,11 +3,11 @@ import { EmbedBuilder, Guild, SlashCommandBuilder } from 'discord.js';
|
|||||||
import osu from 'node-os-utils';
|
import osu from 'node-os-utils';
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import { version } from '../../../package.json';
|
import { version } from '../../../../package.json';
|
||||||
import loggerModule from '../../services/logger';
|
import loggerModule from '../../../services/logger';
|
||||||
import { CommandParams } from '../../types/commandTypes';
|
import { CommandParams } from '../../../types/commandTypes';
|
||||||
import { EmbedOptions } from '../../types/configTypes';
|
import { EmbedOptions } from '../../../types/configTypes';
|
||||||
import { getUptimeFormatted } from '../../utils/system/getUptimeFormatted';
|
import { getUptimeFormatted } from '../../../utils/system/getUptimeFormatted';
|
||||||
|
|
||||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@@ -14,11 +14,11 @@ import {
|
|||||||
StringSelectMenuOptionBuilder
|
StringSelectMenuOptionBuilder
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
|
|
||||||
import loggerModule from '../../services/logger';
|
import loggerModule from '../../../services/logger';
|
||||||
import { CommandParams, CustomError } from '../../types/commandTypes';
|
import { CommandParams, CustomError } from '../../../types/commandTypes';
|
||||||
import { EmbedOptions, FFmpegFilterOption, FFmpegFilterOptions } from '../../types/configTypes';
|
import { EmbedOptions, FFmpegFilterOption, FFmpegFilterOptions } from '../../../types/configTypes';
|
||||||
import { queueDoesNotExist, queueNoCurrentTrack } from '../../utils/validation/queueValidator';
|
import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator';
|
||||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../utils/validation/voiceChannelValidator';
|
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||||
|
|
||||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||||
const ffmpegFilterOptions: FFmpegFilterOptions = config.get('ffmpegFilterOptions');
|
const ffmpegFilterOptions: FFmpegFilterOptions = config.get('ffmpegFilterOptions');
|
||||||
@@ -2,10 +2,10 @@ import config from 'config';
|
|||||||
import { NodeResolvable, useQueue } from 'discord-player';
|
import { NodeResolvable, useQueue } from 'discord-player';
|
||||||
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
|
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
|
||||||
|
|
||||||
import loggerModule from '../../services/logger';
|
import loggerModule from '../../../services/logger';
|
||||||
import { CommandParams } from '../../types/commandTypes';
|
import { CommandParams } from '../../../types/commandTypes';
|
||||||
import { EmbedOptions } from '../../types/configTypes';
|
import { EmbedOptions } from '../../../types/configTypes';
|
||||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../utils/validation/voiceChannelValidator';
|
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||||
|
|
||||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@@ -2,11 +2,11 @@ import config from 'config';
|
|||||||
import { NodeResolvable, useQueue } from 'discord-player';
|
import { NodeResolvable, useQueue } from 'discord-player';
|
||||||
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
|
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
|
||||||
|
|
||||||
import loggerModule from '../../services/logger';
|
import loggerModule from '../../../services/logger';
|
||||||
import { CommandParams } from '../../types/commandTypes';
|
import { CommandParams } from '../../../types/commandTypes';
|
||||||
import { BotOptions, EmbedOptions } from '../../types/configTypes';
|
import { BotOptions, EmbedOptions } from '../../../types/configTypes';
|
||||||
import { queueDoesNotExist } from '../../utils/validation/queueValidator';
|
import { queueDoesNotExist } from '../../../utils/validation/queueValidator';
|
||||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../utils/validation/voiceChannelValidator';
|
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||||
|
|
||||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||||
const botOptions: BotOptions = config.get('botOptions');
|
const botOptions: BotOptions = config.get('botOptions');
|
||||||
@@ -4,11 +4,11 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
|||||||
|
|
||||||
import { lyricsExtractor } from '@discord-player/extractor';
|
import { lyricsExtractor } from '@discord-player/extractor';
|
||||||
|
|
||||||
import loggerModule from '../../services/logger';
|
import loggerModule from '../../../services/logger';
|
||||||
import { CommandAutocompleteParams, CommandParams } from '../../types/commandTypes';
|
import { CommandAutocompleteParams, CommandParams } from '../../../types/commandTypes';
|
||||||
import { EmbedOptions } from '../../types/configTypes';
|
import { EmbedOptions } from '../../../types/configTypes';
|
||||||
import { queueDoesNotExist, queueNoCurrentTrack } from '../../utils/validation/queueValidator';
|
import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator';
|
||||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../utils/validation/voiceChannelValidator';
|
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||||
|
|
||||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||||
const recentQueries = new Map();
|
const recentQueries = new Map();
|
||||||
+13
-134
@@ -7,19 +7,18 @@ import {
|
|||||||
ButtonStyle,
|
ButtonStyle,
|
||||||
ComponentType,
|
ComponentType,
|
||||||
EmbedBuilder,
|
EmbedBuilder,
|
||||||
GuildMember,
|
|
||||||
Interaction,
|
|
||||||
SlashCommandBuilder
|
SlashCommandBuilder
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
|
|
||||||
import loggerModule from '../../services/logger';
|
import loggerModule from '../../../services/logger';
|
||||||
import { CommandParams, TrackMetadata, CustomError } from '../../types/commandTypes';
|
import { CommandParams, TrackMetadata } from '../../../types/commandTypes';
|
||||||
import { EmbedOptions, PlayerOptions } from '../../types/configTypes';
|
import { EmbedOptions, PlayerOptions } from '../../../types/configTypes';
|
||||||
import { queueDoesNotExist, queueNoCurrentTrack } from '../../utils/validation/queueValidator';
|
import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator';
|
||||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../utils/validation/voiceChannelValidator';
|
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||||
|
|
||||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||||
const playerOptions: PlayerOptions = config.get('playerOptions');
|
const playerOptions: PlayerOptions = config.get('playerOptions');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
isNew: false,
|
isNew: false,
|
||||||
isBeta: false,
|
isBeta: false,
|
||||||
@@ -110,15 +109,18 @@ module.exports = {
|
|||||||
bar = `${embedOptions.icons.liveTrack} **\`LIVE\`** - Playing continuously from live source.`;
|
bar = `${embedOptions.icons.liveTrack} **\`LIVE\`** - Playing continuously from live source.`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const customId = `nowplaying-skip-button_${currentTrack.id}`;
|
||||||
|
logger.debug(`Generated custom id for skip button: ${customId}`);
|
||||||
|
|
||||||
const nowPlayingButton = new ButtonBuilder()
|
const nowPlayingButton = new ButtonBuilder()
|
||||||
.setCustomId('nowplaying-skip')
|
.setCustomId(customId)
|
||||||
.setLabel('Skip track')
|
.setLabel('Skip track')
|
||||||
.setStyle(ButtonStyle.Secondary)
|
.setStyle(ButtonStyle.Secondary)
|
||||||
.setEmoji(embedOptions.icons.nextTrack)
|
.setEmoji(embedOptions.icons.nextTrack)
|
||||||
.toJSON(); // Convert the builder to a raw object
|
.toJSON();
|
||||||
|
|
||||||
const nowPlayingActionRow: APIActionRowComponent<APIMessageActionRowComponent> = {
|
const nowPlayingActionRow: APIActionRowComponent<APIMessageActionRowComponent> = {
|
||||||
type: ComponentType.ActionRow, // This might vary based on your discord.js version
|
type: ComponentType.ActionRow,
|
||||||
components: [nowPlayingButton]
|
components: [nowPlayingButton]
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -134,7 +136,7 @@ module.exports = {
|
|||||||
logger.debug('Successfully retrieved information about the current track.');
|
logger.debug('Successfully retrieved information about the current track.');
|
||||||
|
|
||||||
logger.debug('Sending info embed with action row components.');
|
logger.debug('Sending info embed with action row components.');
|
||||||
const response = await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setAuthor({
|
.setAuthor({
|
||||||
@@ -185,128 +187,5 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
logger.debug('Finished sending response.');
|
logger.debug('Finished sending response.');
|
||||||
|
|
||||||
const collectorFilter = (i: Interaction) => i.user.id === interaction.user.id;
|
|
||||||
try {
|
|
||||||
const confirmation = await response.awaitMessageComponent({
|
|
||||||
filter: collectorFilter,
|
|
||||||
time: 300_000
|
|
||||||
});
|
|
||||||
|
|
||||||
confirmation.deferUpdate();
|
|
||||||
|
|
||||||
logger.debug('Received component interaction response.');
|
|
||||||
|
|
||||||
if (confirmation.customId === 'nowplaying-skip') {
|
|
||||||
logger.debug('Received skip confirmation.');
|
|
||||||
if (!queue || (queue.tracks.data.length === 0 && !queue.currentTrack)) {
|
|
||||||
logger.debug('Tried skipping track but there was no queue.');
|
|
||||||
|
|
||||||
logger.debug('Responding with warning embed.');
|
|
||||||
return await interaction.followUp({
|
|
||||||
embeds: [
|
|
||||||
new EmbedBuilder()
|
|
||||||
.setDescription(
|
|
||||||
`**${embedOptions.icons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with **\`/play\`**!`
|
|
||||||
)
|
|
||||||
.setColor(embedOptions.colors.warning)
|
|
||||||
],
|
|
||||||
components: []
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (queue.currentTrack !== currentTrack) {
|
|
||||||
logger.debug(
|
|
||||||
'Tried skipping track but it is not the current track and therefore already skipped/removed.'
|
|
||||||
);
|
|
||||||
|
|
||||||
logger.debug('Responding with warning embed.');
|
|
||||||
return await interaction.followUp({
|
|
||||||
embeds: [
|
|
||||||
new EmbedBuilder()
|
|
||||||
.setDescription(
|
|
||||||
`**${embedOptions.icons.warning} Oops!**\nThis track has already been skipped or is no longer playing.`
|
|
||||||
)
|
|
||||||
.setColor(embedOptions.colors.warning)
|
|
||||||
],
|
|
||||||
components: []
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const skippedTrack = queue.currentTrack;
|
|
||||||
let durationFormat =
|
|
||||||
Number(skippedTrack.raw.duration) === 0 || skippedTrack.duration === '0:00'
|
|
||||||
? ''
|
|
||||||
: `\`${skippedTrack.duration}\``;
|
|
||||||
|
|
||||||
if (skippedTrack.raw.live) {
|
|
||||||
durationFormat = `${embedOptions.icons.liveTrack} \`LIVE\``;
|
|
||||||
}
|
|
||||||
queue.node.skip();
|
|
||||||
logger.debug('Skipped the track.');
|
|
||||||
|
|
||||||
const repeatModeUserString = loopModesFormatted.get(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.followUp({
|
|
||||||
embeds: [
|
|
||||||
new EmbedBuilder()
|
|
||||||
.setAuthor({
|
|
||||||
name: authorName,
|
|
||||||
iconURL: interaction.user.avatarURL() || ''
|
|
||||||
})
|
|
||||||
.setDescription(
|
|
||||||
`**${embedOptions.icons.skipped} Skipped track**\n**${durationFormat} [${
|
|
||||||
skippedTrack.title
|
|
||||||
}](${skippedTrack.raw.url ?? skippedTrack.url})**` +
|
|
||||||
`${
|
|
||||||
queue.repeatMode === 0
|
|
||||||
? ''
|
|
||||||
: `\n\n**${
|
|
||||||
queue.repeatMode === 3
|
|
||||||
? embedOptions.icons.autoplaying
|
|
||||||
: embedOptions.icons.looping
|
|
||||||
} Looping**\nLoop mode is set to ${repeatModeUserString}. You can change it with **\`/loop\`**.`
|
|
||||||
}`
|
|
||||||
)
|
|
||||||
.setThumbnail(skippedTrack.thumbnail)
|
|
||||||
.setColor(embedOptions.colors.success)
|
|
||||||
],
|
|
||||||
components: []
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
if (error instanceof CustomError) {
|
|
||||||
if (error.code === 'InteractionCollectorError') {
|
|
||||||
logger.debug('Interaction response timed out.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (error.message === 'Collector received no interactions before ending with reason: time') {
|
|
||||||
logger.debug('Interaction response timed out.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.error(error, 'Unhandled error while awaiting or handling component interaction.');
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
if (
|
|
||||||
error instanceof Error &&
|
|
||||||
error.message === 'Collector received no interactions before ending with reason: time'
|
|
||||||
) {
|
|
||||||
logger.debug('Interaction response timed out.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -2,11 +2,11 @@ import config from 'config';
|
|||||||
import { NodeResolvable, useQueue } from 'discord-player';
|
import { NodeResolvable, useQueue } from 'discord-player';
|
||||||
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
|
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
|
||||||
|
|
||||||
import loggerModule from '../../services/logger';
|
import loggerModule from '../../../services/logger';
|
||||||
import { CommandParams } from '../../types/commandTypes';
|
import { CommandParams } from '../../../types/commandTypes';
|
||||||
import { EmbedOptions } from '../../types/configTypes';
|
import { EmbedOptions } from '../../../types/configTypes';
|
||||||
import { queueDoesNotExist, queueNoCurrentTrack } from '../../utils/validation/queueValidator';
|
import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator';
|
||||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../utils/validation/voiceChannelValidator';
|
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||||
|
|
||||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@@ -2,12 +2,12 @@ import config from 'config';
|
|||||||
import { useMainPlayer, useQueue } from 'discord-player';
|
import { useMainPlayer, useQueue } from 'discord-player';
|
||||||
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
|
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
|
||||||
|
|
||||||
import loggerModule from '../../services/logger';
|
import loggerModule from '../../../services/logger';
|
||||||
import { CommandAutocompleteParams, CommandParams } from '../../types/commandTypes';
|
import { CommandAutocompleteParams, CommandParams } from '../../../types/commandTypes';
|
||||||
import { BotOptions, EmbedOptions, PlayerOptions } from '../../types/configTypes';
|
import { BotOptions, EmbedOptions, PlayerOptions } from '../../../types/configTypes';
|
||||||
import { cannotJoinVoiceOrTalk } from '../../utils/validation/permissionValidator';
|
import { cannotJoinVoiceOrTalk } from '../../../utils/validation/permissionValidator';
|
||||||
import { transformQuery } from '../../utils/validation/searchQueryValidator';
|
import { transformQuery } from '../../../utils/validation/searchQueryValidator';
|
||||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../utils/validation/voiceChannelValidator';
|
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||||
|
|
||||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||||
const botOptions: BotOptions = config.get('botOptions');
|
const botOptions: BotOptions = config.get('botOptions');
|
||||||
@@ -2,10 +2,10 @@ import config from 'config';
|
|||||||
import { NodeResolvable, useQueue } from 'discord-player';
|
import { NodeResolvable, useQueue } from 'discord-player';
|
||||||
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||||
|
|
||||||
import loggerModule from '../../services/logger';
|
import loggerModule from '../../../services/logger';
|
||||||
import { CommandParams } from '../../types/commandTypes';
|
import { CommandParams } from '../../../types/commandTypes';
|
||||||
import { EmbedOptions, PlayerOptions } from '../../types/configTypes';
|
import { EmbedOptions, PlayerOptions } from '../../../types/configTypes';
|
||||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../utils/validation/voiceChannelValidator';
|
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||||
|
|
||||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||||
const playerOptions: PlayerOptions = config.get('playerOptions');
|
const playerOptions: PlayerOptions = config.get('playerOptions');
|
||||||
@@ -2,11 +2,11 @@ import config from 'config';
|
|||||||
import { NodeResolvable, useQueue } from 'discord-player';
|
import { NodeResolvable, useQueue } from 'discord-player';
|
||||||
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
|
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
|
||||||
|
|
||||||
import loggerModule from '../../services/logger';
|
import loggerModule from '../../../services/logger';
|
||||||
import { CommandParams } from '../../types/commandTypes';
|
import { CommandParams } from '../../../types/commandTypes';
|
||||||
import { EmbedOptions } from '../../types/configTypes';
|
import { EmbedOptions } from '../../../types/configTypes';
|
||||||
import { queueDoesNotExist } from '../../utils/validation/queueValidator';
|
import { queueDoesNotExist } from '../../../utils/validation/queueValidator';
|
||||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../utils/validation/voiceChannelValidator';
|
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||||
|
|
||||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@@ -2,11 +2,11 @@ import config from 'config';
|
|||||||
import { NodeResolvable, useQueue } from 'discord-player';
|
import { NodeResolvable, useQueue } from 'discord-player';
|
||||||
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
|
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
|
||||||
|
|
||||||
import loggerModule from '../../services/logger';
|
import loggerModule from '../../../services/logger';
|
||||||
import { CommandParams } from '../../types/commandTypes';
|
import { CommandParams } from '../../../types/commandTypes';
|
||||||
import { EmbedOptions } from '../../types/configTypes';
|
import { EmbedOptions } from '../../../types/configTypes';
|
||||||
import { queueDoesNotExist, queueNoCurrentTrack } from '../../utils/validation/queueValidator';
|
import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator';
|
||||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../utils/validation/voiceChannelValidator';
|
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||||
|
|
||||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@@ -2,11 +2,11 @@ import config from 'config';
|
|||||||
import { NodeResolvable, useQueue } from 'discord-player';
|
import { NodeResolvable, useQueue } from 'discord-player';
|
||||||
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
|
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
|
||||||
|
|
||||||
import loggerModule from '../../services/logger';
|
import loggerModule from '../../../services/logger';
|
||||||
import { CommandParams } from '../../types/commandTypes';
|
import { CommandParams } from '../../../types/commandTypes';
|
||||||
import { EmbedOptions } from '../../types/configTypes';
|
import { EmbedOptions } from '../../../types/configTypes';
|
||||||
import { queueDoesNotExist, queueIsEmpty } from '../../utils/validation/queueValidator';
|
import { queueDoesNotExist, queueIsEmpty } from '../../../utils/validation/queueValidator';
|
||||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../utils/validation/voiceChannelValidator';
|
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||||
|
|
||||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@@ -2,11 +2,11 @@ import config from 'config';
|
|||||||
import { NodeResolvable, useQueue } from 'discord-player';
|
import { NodeResolvable, useQueue } from 'discord-player';
|
||||||
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
|
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
|
||||||
|
|
||||||
import loggerModule from '../../services/logger';
|
import loggerModule from '../../../services/logger';
|
||||||
import { CommandParams } from '../../types/commandTypes';
|
import { CommandParams } from '../../../types/commandTypes';
|
||||||
import { EmbedOptions } from '../../types/configTypes';
|
import { EmbedOptions } from '../../../types/configTypes';
|
||||||
import { queueDoesNotExist, queueNoCurrentTrack } from '../../utils/validation/queueValidator';
|
import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator';
|
||||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../utils/validation/voiceChannelValidator';
|
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||||
|
|
||||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@@ -2,10 +2,10 @@ import config from 'config';
|
|||||||
import { NodeResolvable, useQueue } from 'discord-player';
|
import { NodeResolvable, useQueue } from 'discord-player';
|
||||||
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
|
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
|
||||||
|
|
||||||
import loggerModule from '../../services/logger';
|
import loggerModule from '../../../services/logger';
|
||||||
import { CommandParams } from '../../types/commandTypes';
|
import { CommandParams } from '../../../types/commandTypes';
|
||||||
import { EmbedOptions } from '../../types/configTypes';
|
import { EmbedOptions } from '../../../types/configTypes';
|
||||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../utils/validation/voiceChannelValidator';
|
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||||
|
|
||||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@@ -2,11 +2,11 @@ import config from 'config';
|
|||||||
import { NodeResolvable, useQueue } from 'discord-player';
|
import { NodeResolvable, useQueue } from 'discord-player';
|
||||||
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
|
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
|
||||||
|
|
||||||
import loggerModule from '../../services/logger';
|
import loggerModule from '../../../services/logger';
|
||||||
import { CommandParams } from '../../types/commandTypes';
|
import { CommandParams } from '../../../types/commandTypes';
|
||||||
import { EmbedOptions } from '../../types/configTypes';
|
import { EmbedOptions } from '../../../types/configTypes';
|
||||||
import { queueDoesNotExist } from '../../utils/validation/queueValidator';
|
import { queueDoesNotExist } from '../../../utils/validation/queueValidator';
|
||||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../utils/validation/voiceChannelValidator';
|
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||||
|
|
||||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
import config from 'config';
|
import config from 'config';
|
||||||
import { EmbedBuilder, Guild, SlashCommandBuilder } from 'discord.js';
|
import { EmbedBuilder, Guild, SlashCommandBuilder } from 'discord.js';
|
||||||
|
|
||||||
import loggerModule from '../../services/logger';
|
import loggerModule from '../../../services/logger';
|
||||||
import { CommandParams } from '../../types/commandTypes';
|
import { CommandParams } from '../../../types/commandTypes';
|
||||||
import { EmbedOptions } from '../../types/configTypes';
|
import { EmbedOptions } from '../../../types/configTypes';
|
||||||
import { notValidGuildId } from '../../utils/validation/systemCommandValidator';
|
import { notValidGuildId } from '../../../utils/validation/systemCommandValidator';
|
||||||
|
|
||||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
import config from 'config';
|
import config from 'config';
|
||||||
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||||
|
|
||||||
import loggerModule from '../../services/logger';
|
import loggerModule from '../../../services/logger';
|
||||||
import { ExtendedClient } from '../../types/clientTypes';
|
import { ExtendedClient } from '../../../types/clientTypes';
|
||||||
import { CommandParams } from '../../types/commandTypes';
|
import { CommandParams } from '../../../types/commandTypes';
|
||||||
import { EmbedOptions } from '../../types/configTypes';
|
import { EmbedOptions } from '../../../types/configTypes';
|
||||||
import { notValidGuildId } from '../../utils/validation/systemCommandValidator';
|
import { notValidGuildId } from '../../../utils/validation/systemCommandValidator';
|
||||||
|
|
||||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
import config from 'config';
|
import config from 'config';
|
||||||
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||||
|
|
||||||
import loggerModule from '../../services/logger';
|
import loggerModule from '../../../services/logger';
|
||||||
import { ExtendedClient } from '../../types/clientTypes';
|
import { ExtendedClient } from '../../../types/clientTypes';
|
||||||
import { CommandParams, ShardInfo } from '../../types/commandTypes';
|
import { CommandParams, ShardInfo } from '../../../types/commandTypes';
|
||||||
import { EmbedOptions } from '../../types/configTypes';
|
import { EmbedOptions } from '../../../types/configTypes';
|
||||||
import { notValidGuildId } from '../../utils/validation/systemCommandValidator';
|
import { notValidGuildId } from '../../../utils/validation/systemCommandValidator';
|
||||||
|
|
||||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||||
module.exports = {
|
module.exports = {
|
||||||
+6
-6
@@ -3,12 +3,12 @@ import { EmbedBuilder, Guild, SlashCommandBuilder } from 'discord.js';
|
|||||||
import osu from 'node-os-utils';
|
import osu from 'node-os-utils';
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import { dependencies, version } from '../../../package.json';
|
import { dependencies, version } from '../../../../package.json';
|
||||||
import loggerModule from '../../services/logger';
|
import loggerModule from '../../../services/logger';
|
||||||
import { CommandParams } from '../../types/commandTypes';
|
import { CommandParams } from '../../../types/commandTypes';
|
||||||
import { EmbedOptions } from '../../types/configTypes';
|
import { EmbedOptions } from '../../../types/configTypes';
|
||||||
import { getUptimeFormatted } from '../../utils/system/getUptimeFormatted';
|
import { getUptimeFormatted } from '../../../utils/system/getUptimeFormatted';
|
||||||
import { notValidGuildId } from '../../utils/validation/systemCommandValidator';
|
import { notValidGuildId } from '../../../utils/validation/systemCommandValidator';
|
||||||
|
|
||||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||||
|
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
import config from 'config';
|
||||||
|
import { NodeResolvable, useQueue } from 'discord-player';
|
||||||
|
import { EmbedBuilder, GuildMember } from 'discord.js';
|
||||||
|
|
||||||
|
import loggerModule from '../../services/logger';
|
||||||
|
import { EmbedOptions } from '../../types/configTypes';
|
||||||
|
import { ComponentInteractionParams } from '../../types/interactionTypes';
|
||||||
|
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||||
|
|
||||||
|
export const execute = async ({ interaction, trackId, executionId }: ComponentInteractionParams) => {
|
||||||
|
const logger = loggerModule.child({
|
||||||
|
source: 'nowplaying-skip.js',
|
||||||
|
module: 'componentInteraction',
|
||||||
|
name: 'nowplaying-skip',
|
||||||
|
executionId: executionId,
|
||||||
|
shardId: interaction.guild?.shardId,
|
||||||
|
guildId: interaction.guild?.id
|
||||||
|
});
|
||||||
|
|
||||||
|
const queue: NodeResolvable = useQueue(interaction.guild!.id)!;
|
||||||
|
|
||||||
|
logger.debug(`Received skip confirmation for track id ${trackId}.`);
|
||||||
|
if (!queue || (queue.tracks.data.length === 0 && !queue.currentTrack)) {
|
||||||
|
logger.debug('Tried skipping track but there was no queue.');
|
||||||
|
|
||||||
|
logger.debug('Responding with warning embed.');
|
||||||
|
return await interaction.editReply({
|
||||||
|
embeds: [
|
||||||
|
new EmbedBuilder()
|
||||||
|
.setDescription(
|
||||||
|
`**${embedOptions.icons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with **\`/play\`**!`
|
||||||
|
)
|
||||||
|
.setColor(embedOptions.colors.warning)
|
||||||
|
],
|
||||||
|
components: []
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (queue.currentTrack!.id !== trackId) {
|
||||||
|
logger.debug('Tried skipping track but it is not the current track and therefore already skipped/removed.');
|
||||||
|
|
||||||
|
logger.debug('Responding with warning embed.');
|
||||||
|
return await interaction.editReply({
|
||||||
|
embeds: [
|
||||||
|
new EmbedBuilder()
|
||||||
|
.setDescription(
|
||||||
|
`**${embedOptions.icons.warning} Oops!**\nThis track has already been skipped or is no longer playing.`
|
||||||
|
)
|
||||||
|
.setColor(embedOptions.colors.warning)
|
||||||
|
],
|
||||||
|
components: []
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const skippedTrack = queue.currentTrack!;
|
||||||
|
let durationFormat =
|
||||||
|
Number(skippedTrack.raw.duration) === 0 || skippedTrack.duration === '0:00'
|
||||||
|
? ''
|
||||||
|
: `\`${skippedTrack.duration}\``;
|
||||||
|
|
||||||
|
if (skippedTrack.raw.live) {
|
||||||
|
durationFormat = `${embedOptions.icons.liveTrack} \`LIVE\``;
|
||||||
|
}
|
||||||
|
queue.node.skip();
|
||||||
|
logger.debug('Skipped the track.');
|
||||||
|
|
||||||
|
const loopModesFormatted = new Map([
|
||||||
|
[0, 'disabled'],
|
||||||
|
[1, 'track'],
|
||||||
|
[2, 'queue'],
|
||||||
|
[3, 'autoplay']
|
||||||
|
]);
|
||||||
|
|
||||||
|
const repeatModeUserString = loopModesFormatted.get(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() || ''
|
||||||
|
})
|
||||||
|
.setDescription(
|
||||||
|
`**${embedOptions.icons.skipped} Skipped track**\n**${durationFormat} [${skippedTrack.title}](${
|
||||||
|
skippedTrack.raw.url ?? skippedTrack.url
|
||||||
|
})**` +
|
||||||
|
`${
|
||||||
|
queue.repeatMode === 0
|
||||||
|
? ''
|
||||||
|
: `\n\n**${
|
||||||
|
queue.repeatMode === 3
|
||||||
|
? embedOptions.icons.autoplaying
|
||||||
|
: embedOptions.icons.looping
|
||||||
|
} Looping**\nLoop mode is set to ${repeatModeUserString}. You can change it with **\`/loop\`**.`
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
.setThumbnail(skippedTrack.thumbnail)
|
||||||
|
.setColor(embedOptions.colors.success)
|
||||||
|
],
|
||||||
|
components: []
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import { MessageComponentInteraction } from 'discord.js';
|
||||||
|
|
||||||
|
export interface ComponentInteractionParams {
|
||||||
|
interaction: MessageComponentInteraction;
|
||||||
|
trackId?: string;
|
||||||
|
executionId: string;
|
||||||
|
}
|
||||||
@@ -17,21 +17,21 @@ export const registerClientCommands = ({ client, executionId }: RegisterClientCo
|
|||||||
logger.debug('Registering client commands...');
|
logger.debug('Registering client commands...');
|
||||||
client.commands = new Collection();
|
client.commands = new Collection();
|
||||||
|
|
||||||
const commandFolders = fs.readdirSync(path.resolve('./dist/commands'));
|
const commandFolders = fs.readdirSync(path.resolve('./dist/interactions/commands'));
|
||||||
for (const folder of commandFolders) {
|
for (const folder of commandFolders) {
|
||||||
logger.trace(`Registering client commands for folder '${folder}'...`);
|
logger.trace(`Registering client commands for folder '${folder}'...`);
|
||||||
const commandFiles = fs
|
const commandFiles = fs
|
||||||
.readdirSync(path.resolve(`./dist/commands/${folder}`))
|
.readdirSync(path.resolve(`./dist/interactions/commands/${folder}`))
|
||||||
.filter((file) => file.endsWith('.js'));
|
.filter((file) => file.endsWith('.js'));
|
||||||
|
|
||||||
for (const file of commandFiles) {
|
for (const file of commandFiles) {
|
||||||
try {
|
try {
|
||||||
// delete command from require cache
|
// delete command from require cache
|
||||||
delete require.cache[require.resolve(`../commands/${folder}/${file}`)];
|
delete require.cache[require.resolve(`../interactions/commands/${folder}/${file}`)];
|
||||||
|
|
||||||
// register command
|
// register command
|
||||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||||
const command = require(`../commands/${folder}/${file}`);
|
const command = require(`../interactions/commands/${folder}/${file}`);
|
||||||
client.commands.delete(command.data.name);
|
client.commands.delete(command.data.name);
|
||||||
client.commands.set(command.data.name, command);
|
client.commands.set(command.data.name, command);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in new issue
Block a user