mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-01 14:38:48 +00:00
feat!: Extract logic for autocomplete and component interactions
This commit is contained in:
1 parent
f16a18deb5
commit
1ec1281e98
29 files changed
+694
-442
No files matched your search
@@ -1 +1,2 @@
|
|||||||
* text=auto eol=crlf
|
* text=auto eol=crlf
|
||||||
|
*.js linguist-language=TypeScript
|
||||||
+16
-14
@@ -20,17 +20,19 @@ const logger = loggerModule.child({
|
|||||||
});
|
});
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const client: ExtendedClient = await createClient({ executionId });
|
try {
|
||||||
const player = await createPlayer({ client, executionId });
|
const client: ExtendedClient = await createClient({ executionId });
|
||||||
|
const player = await createPlayer({ client, executionId });
|
||||||
client.on('allShardsReady', async () => {
|
|
||||||
client.registerClientCommands = registerClientCommands;
|
client.on('allShardsReady', async () => {
|
||||||
await registerEventListeners({ client, player, executionId });
|
client.registerClientCommands = registerClientCommands;
|
||||||
await registerClientCommands({ client, executionId });
|
await registerEventListeners({ client, player, executionId });
|
||||||
client.emit('ready', client as Client);
|
await registerClientCommands({ client, executionId });
|
||||||
});
|
client.emit('ready', client as Client);
|
||||||
|
});
|
||||||
client.login(process.env.DISCORD_BOT_TOKEN);
|
|
||||||
})().catch((error) => {
|
client.login(process.env.DISCORD_BOT_TOKEN);
|
||||||
logger.error(error);
|
} catch (error) {
|
||||||
});
|
logger.error(error);
|
||||||
|
}
|
||||||
|
})();
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
import config from 'config';
|
import config from 'config';
|
||||||
import {
|
import {
|
||||||
|
AutocompleteInteraction,
|
||||||
|
ChatInputCommandInteraction,
|
||||||
EmbedBuilder,
|
EmbedBuilder,
|
||||||
Events,
|
Events,
|
||||||
Interaction,
|
Interaction,
|
||||||
@@ -37,136 +39,276 @@ module.exports = {
|
|||||||
const componentId = interaction.customId.split('_')[0];
|
const componentId = interaction.customId.split('_')[0];
|
||||||
const trackId = interaction.customId.split('_')[1];
|
const trackId = interaction.customId.split('_')[1];
|
||||||
const componentModule = await import(`../../interactions/components/${componentId}.js`);
|
const componentModule = await import(`../../interactions/components/${componentId}.js`);
|
||||||
componentModule.execute({ interaction, trackId, executionId });
|
await componentModule.execute({ interaction, trackId, executionId });
|
||||||
};
|
};
|
||||||
|
|
||||||
switch (interactionType) {
|
const handleAutocomplete = async (interaction: AutocompleteInteraction) => {
|
||||||
case InteractionType.ApplicationCommand:
|
//const command = client.commands?.get(interaction.commandName) as Command;
|
||||||
interactionString = 'ApplicationCommand';
|
const autocompleteModule = await import(`../../interactions/autocomplete/${interaction.commandName}.js`);
|
||||||
break;
|
const { default: autocomplete } = autocompleteModule;
|
||||||
case InteractionType.MessageComponent:
|
await autocomplete.execute({ interaction, executionId });
|
||||||
interactionString = 'MessageComponent';
|
};
|
||||||
handleComponent(interaction as MessageComponentInteraction);
|
|
||||||
|
|
||||||
break;
|
const handleCommand = async (interaction: ChatInputCommandInteraction) => {
|
||||||
case InteractionType.ApplicationCommandAutocomplete:
|
|
||||||
interactionString = 'ApplicationCommandAutocomplete';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
interactionString = 'Unknown';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.debug(`Interaction of type '${interactionString}' created.`);
|
|
||||||
|
|
||||||
// TODO: separate slash commands and autocomplete into separate files
|
|
||||||
// /src/interactions/commands and /src/interactions/autocomplete
|
|
||||||
if (interaction.isChatInputCommand() || interaction.isAutocomplete()) {
|
|
||||||
const command = client.commands?.get(interaction.commandName) as Command;
|
const command = client.commands?.get(interaction.commandName) as Command;
|
||||||
|
if (!command) {
|
||||||
|
logger.warn(`Interaction created but command '${interaction.commandName}' was not found.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (interaction.isChatInputCommand()) {
|
logger.debug(`Chat input command interaction created for '${interaction.commandName}'.`);
|
||||||
if (!command) {
|
//try {
|
||||||
logger.warn(`Interaction created but command '${interaction.commandName}' was not found.`);
|
await interaction.deferReply();
|
||||||
return;
|
|
||||||
}
|
|
||||||
logger.debug(`Chat input command interaction created for '${interaction.commandName}'.`);
|
|
||||||
try {
|
|
||||||
await interaction.deferReply();
|
|
||||||
|
|
||||||
if (await cannotSendMessageInChannel({ interaction, executionId })) {
|
if (await cannotSendMessageInChannel({ interaction, executionId })) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const inputTime: number = new Date().getTime();
|
const inputTime: number = new Date().getTime();
|
||||||
|
|
||||||
await command.execute({ interaction, client, executionId });
|
await command.execute({ interaction, client, executionId });
|
||||||
|
|
||||||
const outputTime: number = new Date().getTime();
|
/* doesnt work because need to find subfolder
|
||||||
const executionTime: number = outputTime - inputTime;
|
/* Update registerClientCommands to registerClientInteractions
|
||||||
|
/* Add client.interactions with { commandInteractions, componentInteractions, autocompleteInteractions
|
||||||
|
const commandModule = await import(`../../interactions/commands/SUBFOLDER/${interaction.commandName}.js`);
|
||||||
|
const { default: command } = commandModule;
|
||||||
|
await command.execute({ interaction, client, executionId });
|
||||||
|
*/
|
||||||
|
|
||||||
logger.info(`Command '${interaction}' executed in ${executionTime} ms.`);
|
const outputTime: number = new Date().getTime();
|
||||||
} catch (error) {
|
const executionTime: number = outputTime - inputTime;
|
||||||
if (error instanceof Error) {
|
|
||||||
logger.warn(
|
|
||||||
error,
|
|
||||||
`Command '${interaction}' throwed an unhandled error and might have failed to execute properly.`
|
|
||||||
);
|
|
||||||
|
|
||||||
if (
|
logger.info(`Command '${interaction}' executed in ${executionTime} ms.`);
|
||||||
error.message === 'Unknown interaction' ||
|
/*
|
||||||
error.message === 'Interaction has already been acknowledged.'
|
} catch (error) {
|
||||||
) {
|
if (error instanceof Error) {
|
||||||
logger.debug(
|
logger.warn(
|
||||||
'Command failed to be responded to, unknown interaction or already acknowledged.'
|
error,
|
||||||
);
|
`Command '${interaction}' throwed an unhandled error and might have failed to execute properly.`
|
||||||
return;
|
);
|
||||||
} else {
|
|
||||||
if (!interaction.deferred || !interaction.replied) {
|
|
||||||
logger.warn('Interaction was not deferred or replied to, and an error was thrown.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (interaction.replied) {
|
if (
|
||||||
// If the interaction has already been replied to, most likely command executed successfully or error is already handled.
|
error.message === 'Unknown interaction' ||
|
||||||
return;
|
error.message === 'Interaction has already been acknowledged.'
|
||||||
} else if (interaction.deferred) {
|
) {
|
||||||
logger.info('Interaction was deferred, editing reply and sending Uh-oh message.');
|
logger.debug('Command failed to be responded to, unknown interaction or already acknowledged.');
|
||||||
await interaction.editReply({
|
|
||||||
embeds: [
|
|
||||||
new EmbedBuilder()
|
|
||||||
.setDescription(
|
|
||||||
`**${embedOptions.icons.error} Uh-oh... _Something_ went wrong!**\nThere was an unexpected error while trying to execute this command.\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})**._`
|
|
||||||
)
|
|
||||||
.setColor(embedOptions.colors.error)
|
|
||||||
.setFooter({ text: `Execution ID: ${executionId}` })
|
|
||||||
]
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
logger.info(
|
|
||||||
'Interaction was not deferred or replied, sending new reply with Uh-oh message.'
|
|
||||||
);
|
|
||||||
await interaction.reply({
|
|
||||||
embeds: [
|
|
||||||
new EmbedBuilder()
|
|
||||||
.setDescription(
|
|
||||||
`**${embedOptions.icons.error} Uh-oh... _Something_ went wrong!**\nThere was an unexpected error while trying to execute this command.\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})**._`
|
|
||||||
)
|
|
||||||
.setColor(embedOptions.colors.error)
|
|
||||||
.setFooter({ text: `Execution ID: ${executionId}` })
|
|
||||||
]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (interaction.isAutocomplete()) {
|
|
||||||
logger.debug('Autocomplete interaction created.');
|
|
||||||
try {
|
|
||||||
command?.autocomplete && (await command?.autocomplete({ interaction, executionId }));
|
|
||||||
} catch (error) {
|
|
||||||
if (error instanceof Error) {
|
|
||||||
if (
|
|
||||||
error.message === 'Unknown interaction' ||
|
|
||||||
error.message === 'Interaction has already been acknowledged.'
|
|
||||||
) {
|
|
||||||
logger.debug(
|
|
||||||
'Autocomplete failed to be responded to, unknown interaction or already acknowledged.'
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
logger.warn(error, 'Autocomplete failed to execute.');
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
throw error;
|
if (!interaction.deferred || !interaction.replied) {
|
||||||
|
logger.warn('Interaction was not deferred or replied to, and an error was thrown.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (interaction.replied) {
|
||||||
|
// If the interaction has already been replied to, most likely command executed successfully or error is already handled.
|
||||||
|
return;
|
||||||
|
} else if (interaction.deferred) {
|
||||||
|
logger.info('Interaction was deferred, editing reply and sending Uh-oh message.');
|
||||||
|
await interaction.editReply({
|
||||||
|
embeds: [
|
||||||
|
new EmbedBuilder()
|
||||||
|
.setDescription(
|
||||||
|
`**${embedOptions.icons.error} Uh-oh... _Something_ went wrong!**\nThere was an unexpected error while trying to execute this command.\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})**._`
|
||||||
|
)
|
||||||
|
.setColor(embedOptions.colors.error)
|
||||||
|
.setFooter({ text: `Execution ID: ${executionId}` })
|
||||||
|
]
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
logger.info(
|
||||||
|
'Interaction was not deferred or replied, sending new reply with Uh-oh message.'
|
||||||
|
);
|
||||||
|
await interaction.reply({
|
||||||
|
embeds: [
|
||||||
|
new EmbedBuilder()
|
||||||
|
.setDescription(
|
||||||
|
`**${embedOptions.icons.error} Uh-oh... _Something_ went wrong!**\nThere was an unexpected error while trying to execute this command.\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})**._`
|
||||||
|
)
|
||||||
|
.setColor(embedOptions.colors.error)
|
||||||
|
.setFooter({ text: `Execution ID: ${executionId}` })
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
*/
|
||||||
logger.warn('Interaction created but was not a chat input or autocomplete interaction.');
|
};
|
||||||
logger.trace(interaction);
|
|
||||||
|
try {
|
||||||
|
switch (interactionType) {
|
||||||
|
case InteractionType.ApplicationCommand:
|
||||||
|
interactionString = 'ApplicationCommand';
|
||||||
|
handleCommand(interaction as ChatInputCommandInteraction);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case InteractionType.ApplicationCommandAutocomplete:
|
||||||
|
interactionString = 'ApplicationCommandAutocomplete';
|
||||||
|
handleAutocomplete(interaction as AutocompleteInteraction);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case InteractionType.MessageComponent:
|
||||||
|
interactionString = 'MessageComponent';
|
||||||
|
handleComponent(interaction as MessageComponentInteraction);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
interactionString = 'Unknown';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug(`Interaction of type '${interactionString}' created.`);
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error, `Error handling interaction of type '${interactionString}'`);
|
||||||
|
|
||||||
|
const errorReply = {
|
||||||
|
embeds: [
|
||||||
|
new EmbedBuilder()
|
||||||
|
.setDescription(
|
||||||
|
`**${embedOptions.icons.error} Uh-oh... _Something_ went wrong!**\nThere was an unexpected error while trying to execute this command.\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})**._`
|
||||||
|
)
|
||||||
|
.setColor(embedOptions.colors.error)
|
||||||
|
.setFooter({ text: `Execution ID: ${executionId}` })
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleErrorWithReplyToUser = async (interaction: Interaction, error: Error) => {
|
||||||
|
logger.error(error, `Error handling interaction of type '${interactionString}'`);
|
||||||
|
if (interaction.channel) {
|
||||||
|
// Send message to user in channel where interaction was made
|
||||||
|
logger.debug(`Sending error reply to channel '${interaction.channel.id}'.`);
|
||||||
|
await interaction.channel.send(errorReply);
|
||||||
|
} else {
|
||||||
|
// Send message to user in DMs
|
||||||
|
logger.debug(`Sending error reply to user '${interaction.user.id}'.`);
|
||||||
|
await interaction.user.send(errorReply);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
switch (true) {
|
||||||
|
case interaction instanceof ChatInputCommandInteraction:
|
||||||
|
await handleErrorWithReplyToUser(interaction, error as Error);
|
||||||
|
break;
|
||||||
|
case interaction instanceof AutocompleteInteraction:
|
||||||
|
await handleErrorWithReplyToUser(interaction, error as Error);
|
||||||
|
break;
|
||||||
|
case interaction instanceof MessageComponentInteraction:
|
||||||
|
await handleErrorWithReplyToUser(interaction, error as Error);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// Something else went wrong
|
||||||
|
logger.error(error, 'Unhandled error while handling unkown interaction.');
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (interaction.isAutocomplete()) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
command?.autocomplete && (await command?.autocomplete({ interaction, executionId }));
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
if (
|
||||||
|
error.message === 'Unknown interaction' ||
|
||||||
|
error.message === 'Interaction has already been acknowledged.'
|
||||||
|
) {
|
||||||
|
logger.debug(
|
||||||
|
'Autocomplete failed to be responded to, unknown interaction or already acknowledged.'
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
logger.warn(error, 'Autocomplete failed to execute.');
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (interaction.isChatInputCommand()) {
|
||||||
|
const command = client.commands?.get(interaction.commandName) as Command;
|
||||||
|
if (!command) {
|
||||||
|
logger.warn(`Interaction created but command '${interaction.commandName}' was not found.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
logger.debug(`Chat input command interaction created for '${interaction.commandName}'.`);
|
||||||
|
try {
|
||||||
|
await interaction.deferReply();
|
||||||
|
|
||||||
|
if (await cannotSendMessageInChannel({ interaction, executionId })) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const inputTime: number = new Date().getTime();
|
||||||
|
|
||||||
|
await command.execute({ interaction, client, executionId });
|
||||||
|
|
||||||
|
const outputTime: number = new Date().getTime();
|
||||||
|
const executionTime: number = outputTime - inputTime;
|
||||||
|
|
||||||
|
logger.info(`Command '${interaction}' executed in ${executionTime} ms.`);
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
logger.warn(
|
||||||
|
error,
|
||||||
|
`Command '${interaction}' throwed an unhandled error and might have failed to execute properly.`
|
||||||
|
);
|
||||||
|
|
||||||
|
if (
|
||||||
|
error.message === 'Unknown interaction' ||
|
||||||
|
error.message === 'Interaction has already been acknowledged.'
|
||||||
|
) {
|
||||||
|
logger.debug('Command failed to be responded to, unknown interaction or already acknowledged.');
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
if (!interaction.deferred || !interaction.replied) {
|
||||||
|
logger.warn('Interaction was not deferred or replied to, and an error was thrown.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (interaction.replied) {
|
||||||
|
// If the interaction has already been replied to, most likely command executed successfully or error is already handled.
|
||||||
|
return;
|
||||||
|
} else if (interaction.deferred) {
|
||||||
|
logger.info('Interaction was deferred, editing reply and sending Uh-oh message.');
|
||||||
|
await interaction.editReply({
|
||||||
|
embeds: [
|
||||||
|
new EmbedBuilder()
|
||||||
|
.setDescription(
|
||||||
|
`**${embedOptions.icons.error} Uh-oh... _Something_ went wrong!**\nThere was an unexpected error while trying to execute this command.\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})**._`
|
||||||
|
)
|
||||||
|
.setColor(embedOptions.colors.error)
|
||||||
|
.setFooter({ text: `Execution ID: ${executionId}` })
|
||||||
|
]
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
logger.info(
|
||||||
|
'Interaction was not deferred or replied, sending new reply with Uh-oh message.'
|
||||||
|
);
|
||||||
|
await interaction.reply({
|
||||||
|
embeds: [
|
||||||
|
new EmbedBuilder()
|
||||||
|
.setDescription(
|
||||||
|
`**${embedOptions.icons.error} Uh-oh... _Something_ went wrong!**\nThere was an unexpected error while trying to execute this command.\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})**._`
|
||||||
|
)
|
||||||
|
.setColor(embedOptions.colors.error)
|
||||||
|
.setFooter({ text: `Execution ID: ${executionId}` })
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
import { useMainPlayer } from 'discord-player';
|
||||||
|
import loggerModule from '../../services/logger';
|
||||||
|
import { CustomAutocompleteInteraction } from '../../types/interactionTypes';
|
||||||
|
import { lyricsExtractor } from '@discord-player/extractor';
|
||||||
|
|
||||||
|
const loggerTemplate = loggerModule.child({
|
||||||
|
source: 'lyrics.js',
|
||||||
|
module: 'slashCommand',
|
||||||
|
name: '/lyrics'
|
||||||
|
});
|
||||||
|
|
||||||
|
const recentQueries = new Map();
|
||||||
|
|
||||||
|
const autocomplete: CustomAutocompleteInteraction = {
|
||||||
|
execute: async ({ interaction, executionId }) => {
|
||||||
|
// TODO: Extract autocomplete logic
|
||||||
|
const logger = loggerTemplate.child({
|
||||||
|
executionId: executionId,
|
||||||
|
shardId: interaction.guild?.shardId,
|
||||||
|
guildId: interaction.guild?.id
|
||||||
|
});
|
||||||
|
|
||||||
|
const query = interaction.options.getString('query', true);
|
||||||
|
|
||||||
|
const { lastQuery, result, timestamp } = recentQueries.get(interaction.user.id) || {};
|
||||||
|
|
||||||
|
if (lastQuery && (query.startsWith(lastQuery) || lastQuery.startsWith(query)) && Date.now() - timestamp < 500) {
|
||||||
|
logger.debug(`Responding with results from lastQuery for query '${query}'`);
|
||||||
|
return interaction.respond(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (query.length < 3) {
|
||||||
|
logger.debug(`Responding with empty results due to < 3 length for query '${query}'`);
|
||||||
|
return interaction.respond([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
const genius = lyricsExtractor();
|
||||||
|
const lyricsResult = await genius.search(query).catch(() => null);
|
||||||
|
let response = [];
|
||||||
|
|
||||||
|
if (!lyricsResult) {
|
||||||
|
logger.debug(`No Genius lyrics found for query '${query}', using player.search() as fallback.`);
|
||||||
|
const player = useMainPlayer()!;
|
||||||
|
const searchResults = await player.search(query);
|
||||||
|
response = searchResults.tracks.slice(0, 1).map((track) => ({
|
||||||
|
name:
|
||||||
|
`${track.title} [Artist: ${track.author}]`.length > 100
|
||||||
|
? `${track.title}`.slice(0, 100)
|
||||||
|
: `${track.title} [Artist: ${track.author}]`,
|
||||||
|
value: track.title.slice(0, 100)
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
logger.debug(`Found Genius lyrics for query '${query}'.`);
|
||||||
|
response = [
|
||||||
|
{
|
||||||
|
name: `${lyricsResult.title} [Artist: ${lyricsResult.artist.name}]`.slice(0, 100),
|
||||||
|
value: lyricsResult.title.slice(0, 100)
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!response || response.length === 0) {
|
||||||
|
logger.debug(`Responding with empty results for query '${query}'`);
|
||||||
|
return interaction.respond([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
recentQueries.set(interaction.user.id, {
|
||||||
|
lastQuery: query,
|
||||||
|
result: response,
|
||||||
|
timestamp: Date.now()
|
||||||
|
});
|
||||||
|
|
||||||
|
logger.debug(`Responding to autocomplete with results for query: '${query}'.`);
|
||||||
|
return interaction.respond(response);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default autocomplete;
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
import { useMainPlayer } from 'discord-player';
|
||||||
|
import loggerModule from '../../services/logger';
|
||||||
|
import { CustomAutocompleteInteraction } from '../../types/interactionTypes';
|
||||||
|
|
||||||
|
const loggerTemplate = loggerModule.child({
|
||||||
|
source: 'play.js',
|
||||||
|
module: 'slashCommand',
|
||||||
|
name: '/play'
|
||||||
|
});
|
||||||
|
|
||||||
|
const recentQueries = new Map();
|
||||||
|
|
||||||
|
const autocomplete: CustomAutocompleteInteraction = {
|
||||||
|
execute: async ({ interaction, executionId }) => {
|
||||||
|
const logger = loggerTemplate.child({
|
||||||
|
executionId: executionId,
|
||||||
|
shardId: interaction.guild?.shardId,
|
||||||
|
guildId: interaction.guild?.id
|
||||||
|
});
|
||||||
|
|
||||||
|
const player = useMainPlayer()!;
|
||||||
|
const query = interaction.options.getString('query', true);
|
||||||
|
|
||||||
|
const { lastQuery, results, timestamp } = recentQueries.get(interaction.user.id) || {};
|
||||||
|
|
||||||
|
if (lastQuery && (query.startsWith(lastQuery) || lastQuery.startsWith(query)) && Date.now() - timestamp < 500) {
|
||||||
|
logger.debug(`Responding with results from lastQuery for query '${query}'`);
|
||||||
|
return interaction.respond(results);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (query.length < 3) {
|
||||||
|
logger.debug(`Responding with empty results due to < 3 length for query '${query}'`);
|
||||||
|
return interaction.respond([]);
|
||||||
|
}
|
||||||
|
const searchResults = await player.search(query);
|
||||||
|
|
||||||
|
let response = [];
|
||||||
|
|
||||||
|
response = searchResults.tracks.slice(0, 5).map((track) => {
|
||||||
|
if (track.url.length > 100) {
|
||||||
|
track.url = track.title.slice(0, 100);
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
name:
|
||||||
|
`${track.title} [Author: ${track.author}]`.length > 100
|
||||||
|
? `${track.title}`.slice(0, 100)
|
||||||
|
: `${track.title} [Author: ${track.author}]`,
|
||||||
|
value: track.url
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
recentQueries.set(interaction.user.id, {
|
||||||
|
lastQuery: query,
|
||||||
|
results: response,
|
||||||
|
timestamp: Date.now()
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response || response.length === 0) {
|
||||||
|
logger.debug(`Responding with empty results for query '${query}'`);
|
||||||
|
return interaction.respond([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug(`Responding to autocomplete with results for query: '${query}'.`);
|
||||||
|
return interaction.respond(response);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default autocomplete;
|
||||||
@@ -2,12 +2,13 @@ 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 { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
|
||||||
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');
|
||||||
module.exports = {
|
|
||||||
|
const command: CustomSlashCommandInteraction = {
|
||||||
isNew: false,
|
isNew: false,
|
||||||
isBeta: false,
|
isBeta: false,
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
@@ -15,7 +16,7 @@ module.exports = {
|
|||||||
.setDescription('Show a list of commands and their usage.')
|
.setDescription('Show a list of commands and their usage.')
|
||||||
.setDMPermission(false)
|
.setDMPermission(false)
|
||||||
.setNSFW(false),
|
.setNSFW(false),
|
||||||
execute: async ({ interaction, client, executionId }: CommandParams) => {
|
execute: async ({ interaction, client, executionId }) => {
|
||||||
const logger = loggerModule.child({
|
const logger = loggerModule.child({
|
||||||
source: 'help.js',
|
source: 'help.js',
|
||||||
module: 'slashCommand',
|
module: 'slashCommand',
|
||||||
@@ -69,3 +70,5 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default command;
|
||||||
@@ -5,12 +5,13 @@ 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 { EmbedOptions } from '../../../types/configTypes';
|
import { EmbedOptions } from '../../../types/configTypes';
|
||||||
import { getUptimeFormatted } from '../../../utils/system/getUptimeFormatted';
|
import { getUptimeFormatted } from '../../../utils/system/getUptimeFormatted';
|
||||||
|
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
|
||||||
|
|
||||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||||
module.exports = {
|
|
||||||
|
const command: CustomSlashCommandInteraction = {
|
||||||
isNew: false,
|
isNew: false,
|
||||||
isBeta: false,
|
isBeta: false,
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
@@ -18,7 +19,7 @@ module.exports = {
|
|||||||
.setDescription('Show the bot and system status.')
|
.setDescription('Show the bot and system status.')
|
||||||
.setDMPermission(false)
|
.setDMPermission(false)
|
||||||
.setNSFW(false),
|
.setNSFW(false),
|
||||||
execute: async ({ interaction, client, executionId }: CommandParams) => {
|
execute: async ({ interaction, client, executionId }) => {
|
||||||
const logger = loggerModule.child({
|
const logger = loggerModule.child({
|
||||||
source: 'status.js',
|
source: 'status.js',
|
||||||
module: 'slashCommand',
|
module: 'slashCommand',
|
||||||
@@ -133,3 +134,5 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default command;
|
||||||
@@ -15,14 +15,15 @@ import {
|
|||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
|
|
||||||
import loggerModule from '../../../services/logger';
|
import loggerModule from '../../../services/logger';
|
||||||
import { CommandParams, CustomError } from '../../../types/commandTypes';
|
import { CustomError, CustomSlashCommandInteraction } from '../../../types/interactionTypes';
|
||||||
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');
|
||||||
module.exports = {
|
|
||||||
|
const command: CustomSlashCommandInteraction = {
|
||||||
isNew: false,
|
isNew: false,
|
||||||
isBeta: false,
|
isBeta: false,
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
@@ -30,7 +31,7 @@ module.exports = {
|
|||||||
.setDescription('Toggle various audio filters during playback.')
|
.setDescription('Toggle various audio filters during playback.')
|
||||||
.setDMPermission(false)
|
.setDMPermission(false)
|
||||||
.setNSFW(false),
|
.setNSFW(false),
|
||||||
execute: async ({ interaction, executionId }: CommandParams) => {
|
execute: async ({ interaction, executionId }) => {
|
||||||
const logger = loggerModule.child({
|
const logger = loggerModule.child({
|
||||||
source: 'filters.js',
|
source: 'filters.js',
|
||||||
module: 'slashCommand',
|
module: 'slashCommand',
|
||||||
@@ -237,3 +238,5 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default command;
|
||||||
@@ -3,12 +3,13 @@ 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 { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
|
||||||
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 = {
|
|
||||||
|
const command: CustomSlashCommandInteraction = {
|
||||||
isNew: false,
|
isNew: false,
|
||||||
isBeta: false,
|
isBeta: false,
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
@@ -16,7 +17,7 @@ module.exports = {
|
|||||||
.setDescription('Clear the track queue and remove the bot from voice channel.')
|
.setDescription('Clear the track queue and remove the bot from voice channel.')
|
||||||
.setDMPermission(false)
|
.setDMPermission(false)
|
||||||
.setNSFW(false),
|
.setNSFW(false),
|
||||||
execute: async ({ interaction, executionId }: CommandParams) => {
|
execute: async ({ interaction, executionId }) => {
|
||||||
const logger = loggerModule.child({
|
const logger = loggerModule.child({
|
||||||
source: 'leave.js',
|
source: 'leave.js',
|
||||||
module: 'slashCommand',
|
module: 'slashCommand',
|
||||||
@@ -80,3 +81,5 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default command;
|
||||||
@@ -1,16 +1,17 @@
|
|||||||
import config from 'config';
|
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, SlashCommandStringOption } from 'discord.js';
|
||||||
|
|
||||||
import loggerModule from '../../../services/logger';
|
import loggerModule from '../../../services/logger';
|
||||||
import { CommandParams } from '../../../types/commandTypes';
|
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
|
||||||
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');
|
||||||
module.exports = {
|
|
||||||
|
const command: CustomSlashCommandInteraction = {
|
||||||
isNew: false,
|
isNew: false,
|
||||||
isBeta: false,
|
isBeta: false,
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
@@ -18,8 +19,8 @@ module.exports = {
|
|||||||
.setDescription('Toggle looping a track, the whole queue or autoplay.')
|
.setDescription('Toggle looping a track, the whole queue or autoplay.')
|
||||||
.setDMPermission(false)
|
.setDMPermission(false)
|
||||||
.setNSFW(false)
|
.setNSFW(false)
|
||||||
.addStringOption((option) =>
|
.addStringOption(() =>
|
||||||
option
|
new SlashCommandStringOption()
|
||||||
.setName('mode')
|
.setName('mode')
|
||||||
.setDescription('Mode to set for looping.')
|
.setDescription('Mode to set for looping.')
|
||||||
.setRequired(false)
|
.setRequired(false)
|
||||||
@@ -30,7 +31,7 @@ module.exports = {
|
|||||||
{ name: 'Disabled', value: '0' }
|
{ name: 'Disabled', value: '0' }
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
execute: async ({ interaction, executionId }: CommandParams) => {
|
execute: async ({ interaction, executionId }) => {
|
||||||
const logger = loggerModule.child({
|
const logger = loggerModule.child({
|
||||||
source: 'loop.js',
|
source: 'loop.js',
|
||||||
module: 'slashCommand',
|
module: 'slashCommand',
|
||||||
@@ -184,3 +185,5 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default command;
|
||||||
@@ -5,13 +5,12 @@ 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 { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
|
||||||
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 loggerTemplate = loggerModule.child({
|
const loggerTemplate = loggerModule.child({
|
||||||
source: 'lyrics.js',
|
source: 'lyrics.js',
|
||||||
@@ -19,7 +18,7 @@ const loggerTemplate = loggerModule.child({
|
|||||||
name: '/lyrics'
|
name: '/lyrics'
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = {
|
const command: CustomSlashCommandInteraction = {
|
||||||
isNew: false,
|
isNew: false,
|
||||||
isBeta: false,
|
isBeta: false,
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
@@ -36,67 +35,7 @@ module.exports = {
|
|||||||
.setMaxLength(500)
|
.setMaxLength(500)
|
||||||
.setAutocomplete(true)
|
.setAutocomplete(true)
|
||||||
),
|
),
|
||||||
autocomplete: async ({ interaction, executionId }: CommandAutocompleteParams) => {
|
execute: async ({ interaction, executionId }) => {
|
||||||
const logger = loggerTemplate.child({
|
|
||||||
executionId: executionId,
|
|
||||||
shardId: interaction.guild?.shardId,
|
|
||||||
guildId: interaction.guild?.id
|
|
||||||
});
|
|
||||||
|
|
||||||
const query = interaction.options.getString('query', true);
|
|
||||||
|
|
||||||
const { lastQuery, result, timestamp } = recentQueries.get(interaction.user.id) || {};
|
|
||||||
|
|
||||||
if (lastQuery && (query.startsWith(lastQuery) || lastQuery.startsWith(query)) && Date.now() - timestamp < 500) {
|
|
||||||
logger.debug(`Responding with results from lastQuery for query '${query}'`);
|
|
||||||
return interaction.respond(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (query.length < 3) {
|
|
||||||
logger.debug(`Responding with empty results due to < 3 length for query '${query}'`);
|
|
||||||
return interaction.respond([]);
|
|
||||||
}
|
|
||||||
|
|
||||||
const genius = lyricsExtractor();
|
|
||||||
const lyricsResult = await genius.search(query).catch(() => null);
|
|
||||||
let response = [];
|
|
||||||
|
|
||||||
if (!lyricsResult) {
|
|
||||||
logger.debug(`No Genius lyrics found for query '${query}', using player.search() as fallback.`);
|
|
||||||
const player = useMainPlayer()!;
|
|
||||||
const searchResults = await player.search(query);
|
|
||||||
response = searchResults.tracks.slice(0, 1).map((track) => ({
|
|
||||||
name:
|
|
||||||
`${track.title} [Artist: ${track.author}]`.length > 100
|
|
||||||
? `${track.title}`.slice(0, 100)
|
|
||||||
: `${track.title} [Artist: ${track.author}]`,
|
|
||||||
value: track.title.slice(0, 100)
|
|
||||||
}));
|
|
||||||
} else {
|
|
||||||
logger.debug(`Found Genius lyrics for query '${query}'.`);
|
|
||||||
response = [
|
|
||||||
{
|
|
||||||
name: `${lyricsResult.title} [Artist: ${lyricsResult.artist.name}]`.slice(0, 100),
|
|
||||||
value: lyricsResult.title.slice(0, 100)
|
|
||||||
}
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!response || response.length === 0) {
|
|
||||||
logger.debug(`Responding with empty results for query '${query}'`);
|
|
||||||
return interaction.respond([]);
|
|
||||||
}
|
|
||||||
|
|
||||||
recentQueries.set(interaction.user.id, {
|
|
||||||
lastQuery: query,
|
|
||||||
result: response,
|
|
||||||
timestamp: Date.now()
|
|
||||||
});
|
|
||||||
|
|
||||||
logger.debug(`Responding to autocomplete with results for query: '${query}'.`);
|
|
||||||
return interaction.respond(response);
|
|
||||||
},
|
|
||||||
execute: async ({ interaction, executionId }: CommandParams) => {
|
|
||||||
const logger = loggerTemplate.child({
|
const logger = loggerTemplate.child({
|
||||||
executionId: executionId,
|
executionId: executionId,
|
||||||
shardId: interaction.guild?.shardId,
|
shardId: interaction.guild?.shardId,
|
||||||
@@ -267,3 +206,5 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default command;
|
||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
|
|
||||||
import loggerModule from '../../../services/logger';
|
import loggerModule from '../../../services/logger';
|
||||||
import { CommandParams, TrackMetadata } from '../../../types/commandTypes';
|
import { CustomSlashCommandInteraction, TrackMetadata } from '../../../types/interactionTypes';
|
||||||
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';
|
||||||
@@ -19,7 +19,7 @@ import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validat
|
|||||||
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 = {
|
const command: CustomSlashCommandInteraction = {
|
||||||
isNew: false,
|
isNew: false,
|
||||||
isBeta: false,
|
isBeta: false,
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
@@ -27,7 +27,7 @@ module.exports = {
|
|||||||
.setDescription('Show information about the track currently playing.')
|
.setDescription('Show information about the track currently playing.')
|
||||||
.setDMPermission(false)
|
.setDMPermission(false)
|
||||||
.setNSFW(false),
|
.setNSFW(false),
|
||||||
execute: async ({ interaction, executionId }: CommandParams) => {
|
execute: async ({ interaction, executionId }) => {
|
||||||
const logger = loggerModule.child({
|
const logger = loggerModule.child({
|
||||||
source: 'nowplaying.js',
|
source: 'nowplaying.js',
|
||||||
module: 'slashCommand',
|
module: 'slashCommand',
|
||||||
@@ -136,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.');
|
||||||
await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setAuthor({
|
.setAuthor({
|
||||||
@@ -185,7 +185,7 @@ module.exports = {
|
|||||||
],
|
],
|
||||||
components: [nowPlayingActionRow as APIActionRowComponent<APIMessageActionRowComponent>]
|
components: [nowPlayingActionRow as APIActionRowComponent<APIMessageActionRowComponent>]
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.debug('Finished sending response.');
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default command;
|
||||||
@@ -3,13 +3,14 @@ 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 { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
|
||||||
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 = {
|
|
||||||
|
const command: CustomSlashCommandInteraction = {
|
||||||
isNew: false,
|
isNew: false,
|
||||||
isBeta: false,
|
isBeta: false,
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
@@ -17,7 +18,7 @@ module.exports = {
|
|||||||
.setDescription('Pause or resume the current track.')
|
.setDescription('Pause or resume the current track.')
|
||||||
.setDMPermission(false)
|
.setDMPermission(false)
|
||||||
.setNSFW(false),
|
.setNSFW(false),
|
||||||
execute: async ({ interaction, executionId }: CommandParams) => {
|
execute: async ({ interaction, executionId }) => {
|
||||||
const logger = loggerModule.child({
|
const logger = loggerModule.child({
|
||||||
source: 'pause.js',
|
source: 'pause.js',
|
||||||
module: 'slashCommand',
|
module: 'slashCommand',
|
||||||
@@ -87,3 +88,5 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default command;
|
||||||
@@ -3,7 +3,7 @@ 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 { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
|
||||||
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';
|
||||||
@@ -12,7 +12,6 @@ import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validat
|
|||||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||||
const botOptions: BotOptions = config.get('botOptions');
|
const botOptions: BotOptions = config.get('botOptions');
|
||||||
const playerOptions: PlayerOptions = config.get('playerOptions');
|
const playerOptions: PlayerOptions = config.get('playerOptions');
|
||||||
const recentQueries = new Map();
|
|
||||||
|
|
||||||
const loggerTemplate = loggerModule.child({
|
const loggerTemplate = loggerModule.child({
|
||||||
source: 'play.js',
|
source: 'play.js',
|
||||||
@@ -20,7 +19,7 @@ const loggerTemplate = loggerModule.child({
|
|||||||
name: '/play'
|
name: '/play'
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = {
|
const command: CustomSlashCommandInteraction = {
|
||||||
isNew: false,
|
isNew: false,
|
||||||
isBeta: false,
|
isBeta: false,
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
@@ -37,59 +36,7 @@ module.exports = {
|
|||||||
.setMaxLength(500)
|
.setMaxLength(500)
|
||||||
.setAutocomplete(true)
|
.setAutocomplete(true)
|
||||||
),
|
),
|
||||||
autocomplete: async ({ interaction, executionId }: CommandAutocompleteParams) => {
|
execute: async ({ interaction, executionId }) => {
|
||||||
const logger = loggerTemplate.child({
|
|
||||||
executionId: executionId,
|
|
||||||
shardId: interaction.guild?.shardId,
|
|
||||||
guildId: interaction.guild?.id
|
|
||||||
});
|
|
||||||
|
|
||||||
const player = useMainPlayer()!;
|
|
||||||
const query = interaction.options.getString('query', true);
|
|
||||||
|
|
||||||
const { lastQuery, results, timestamp } = recentQueries.get(interaction.user.id) || {};
|
|
||||||
|
|
||||||
if (lastQuery && (query.startsWith(lastQuery) || lastQuery.startsWith(query)) && Date.now() - timestamp < 500) {
|
|
||||||
logger.debug(`Responding with results from lastQuery for query '${query}'`);
|
|
||||||
return interaction.respond(results);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (query.length < 3) {
|
|
||||||
logger.debug(`Responding with empty results due to < 3 length for query '${query}'`);
|
|
||||||
return interaction.respond([]);
|
|
||||||
}
|
|
||||||
const searchResults = await player.search(query);
|
|
||||||
|
|
||||||
let response = [];
|
|
||||||
|
|
||||||
response = searchResults.tracks.slice(0, 5).map((track) => {
|
|
||||||
if (track.url.length > 100) {
|
|
||||||
track.url = track.title.slice(0, 100);
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
name:
|
|
||||||
`${track.title} [Author: ${track.author}]`.length > 100
|
|
||||||
? `${track.title}`.slice(0, 100)
|
|
||||||
: `${track.title} [Author: ${track.author}]`,
|
|
||||||
value: track.url
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
recentQueries.set(interaction.user.id, {
|
|
||||||
lastQuery: query,
|
|
||||||
results: response,
|
|
||||||
timestamp: Date.now()
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!response || response.length === 0) {
|
|
||||||
logger.debug(`Responding with empty results for query '${query}'`);
|
|
||||||
return interaction.respond([]);
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.debug(`Responding to autocomplete with results for query: '${query}'.`);
|
|
||||||
return interaction.respond(response);
|
|
||||||
},
|
|
||||||
execute: async ({ interaction, executionId }: CommandParams) => {
|
|
||||||
const logger = loggerTemplate.child({
|
const logger = loggerTemplate.child({
|
||||||
executionId: executionId,
|
executionId: executionId,
|
||||||
shardId: interaction.guild?.shardId,
|
shardId: interaction.guild?.shardId,
|
||||||
@@ -411,3 +358,5 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default command;
|
||||||
@@ -3,13 +3,14 @@ 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 { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
|
||||||
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');
|
||||||
module.exports = {
|
|
||||||
|
const command: CustomSlashCommandInteraction = {
|
||||||
isNew: false,
|
isNew: false,
|
||||||
isBeta: false,
|
isBeta: false,
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
@@ -18,7 +19,7 @@ module.exports = {
|
|||||||
.setDMPermission(false)
|
.setDMPermission(false)
|
||||||
.setNSFW(false)
|
.setNSFW(false)
|
||||||
.addNumberOption((option) => option.setName('page').setDescription('Page number of the queue').setMinValue(1)),
|
.addNumberOption((option) => option.setName('page').setDescription('Page number of the queue').setMinValue(1)),
|
||||||
execute: async ({ interaction, executionId }: CommandParams) => {
|
execute: async ({ interaction, executionId }) => {
|
||||||
const logger = loggerModule.child({
|
const logger = loggerModule.child({
|
||||||
source: 'queue.js',
|
source: 'queue.js',
|
||||||
module: 'slashCommand',
|
module: 'slashCommand',
|
||||||
@@ -207,3 +208,5 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default command;
|
||||||
@@ -3,13 +3,14 @@ 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 { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
|
||||||
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 = {
|
|
||||||
|
const command: CustomSlashCommandInteraction = {
|
||||||
isNew: false,
|
isNew: false,
|
||||||
isBeta: false,
|
isBeta: false,
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
@@ -24,7 +25,7 @@ module.exports = {
|
|||||||
.setMinValue(1)
|
.setMinValue(1)
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
),
|
),
|
||||||
execute: async ({ interaction, executionId }: CommandParams) => {
|
execute: async ({ interaction, executionId }) => {
|
||||||
const logger = loggerModule.child({
|
const logger = loggerModule.child({
|
||||||
source: 'remove.js',
|
source: 'remove.js',
|
||||||
module: 'slashCommand',
|
module: 'slashCommand',
|
||||||
@@ -104,3 +105,5 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default command;
|
||||||
@@ -3,13 +3,14 @@ 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 { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
|
||||||
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 = {
|
|
||||||
|
const command: CustomSlashCommandInteraction = {
|
||||||
isNew: false,
|
isNew: false,
|
||||||
isBeta: false,
|
isBeta: false,
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
@@ -23,7 +24,7 @@ module.exports = {
|
|||||||
.setDescription('Duration in format 00:00:00 (HH:mm:ss) to seek to.')
|
.setDescription('Duration in format 00:00:00 (HH:mm:ss) to seek to.')
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
),
|
),
|
||||||
execute: async ({ interaction, executionId }: CommandParams) => {
|
execute: async ({ interaction, executionId }) => {
|
||||||
const logger = loggerModule.child({
|
const logger = loggerModule.child({
|
||||||
source: 'seek.js',
|
source: 'seek.js',
|
||||||
module: 'slashCommand',
|
module: 'slashCommand',
|
||||||
@@ -186,3 +187,5 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default command;
|
||||||
@@ -3,13 +3,14 @@ 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 { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
|
||||||
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 = {
|
|
||||||
|
const command: CustomSlashCommandInteraction = {
|
||||||
isNew: false,
|
isNew: false,
|
||||||
isBeta: false,
|
isBeta: false,
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
@@ -17,7 +18,7 @@ module.exports = {
|
|||||||
.setDescription('Shuffle tracks in the queue randomly.')
|
.setDescription('Shuffle tracks in the queue randomly.')
|
||||||
.setDMPermission(false)
|
.setDMPermission(false)
|
||||||
.setNSFW(false),
|
.setNSFW(false),
|
||||||
execute: async ({ interaction, executionId }: CommandParams) => {
|
execute: async ({ interaction, executionId }) => {
|
||||||
const logger = loggerModule.child({
|
const logger = loggerModule.child({
|
||||||
source: 'shuffle.js',
|
source: 'shuffle.js',
|
||||||
module: 'slashCommand',
|
module: 'slashCommand',
|
||||||
@@ -72,3 +73,5 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default command;
|
||||||
@@ -3,13 +3,14 @@ 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 { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
|
||||||
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 = {
|
|
||||||
|
const command: CustomSlashCommandInteraction = {
|
||||||
isNew: false,
|
isNew: false,
|
||||||
isBeta: false,
|
isBeta: false,
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
@@ -20,7 +21,7 @@ module.exports = {
|
|||||||
.addNumberOption((option) =>
|
.addNumberOption((option) =>
|
||||||
option.setName('tracknumber').setDescription('Track number to skip to in the queue.').setMinValue(1)
|
option.setName('tracknumber').setDescription('Track number to skip to in the queue.').setMinValue(1)
|
||||||
),
|
),
|
||||||
execute: async ({ interaction, executionId }: CommandParams) => {
|
execute: async ({ interaction, executionId }) => {
|
||||||
const logger = loggerModule.child({
|
const logger = loggerModule.child({
|
||||||
source: 'skip.js',
|
source: 'skip.js',
|
||||||
module: 'slashCommand',
|
module: 'slashCommand',
|
||||||
@@ -181,3 +182,5 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default command;
|
||||||
@@ -3,12 +3,13 @@ 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 { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
|
||||||
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 = {
|
|
||||||
|
const command: CustomSlashCommandInteraction = {
|
||||||
isNew: false,
|
isNew: false,
|
||||||
isBeta: false,
|
isBeta: false,
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
@@ -16,7 +17,7 @@ module.exports = {
|
|||||||
.setDescription('Stop playing audio and clear the track queue.')
|
.setDescription('Stop playing audio and clear the track queue.')
|
||||||
.setDMPermission(false)
|
.setDMPermission(false)
|
||||||
.setNSFW(false),
|
.setNSFW(false),
|
||||||
execute: async ({ interaction, executionId }: CommandParams) => {
|
execute: async ({ interaction, executionId }) => {
|
||||||
const logger = loggerModule.child({
|
const logger = loggerModule.child({
|
||||||
source: 'stop.js',
|
source: 'stop.js',
|
||||||
module: 'slashCommand',
|
module: 'slashCommand',
|
||||||
@@ -82,3 +83,5 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default command;
|
||||||
@@ -3,13 +3,14 @@ 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 { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
|
||||||
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 = {
|
|
||||||
|
const command: CustomSlashCommandInteraction = {
|
||||||
isNew: false,
|
isNew: false,
|
||||||
isBeta: false,
|
isBeta: false,
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
@@ -24,7 +25,7 @@ module.exports = {
|
|||||||
.setMinValue(0)
|
.setMinValue(0)
|
||||||
.setMaxValue(100)
|
.setMaxValue(100)
|
||||||
),
|
),
|
||||||
execute: async ({ interaction, executionId }: CommandParams) => {
|
execute: async ({ interaction, executionId }) => {
|
||||||
const logger = loggerModule.child({
|
const logger = loggerModule.child({
|
||||||
source: 'volume.js',
|
source: 'volume.js',
|
||||||
module: 'slashCommand',
|
module: 'slashCommand',
|
||||||
@@ -126,3 +127,5 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default command;
|
||||||
@@ -2,12 +2,13 @@ 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 { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
|
||||||
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 = {
|
|
||||||
|
const command: CustomSlashCommandInteraction = {
|
||||||
isSystemCommand: true,
|
isSystemCommand: true,
|
||||||
isNew: false,
|
isNew: false,
|
||||||
isBeta: false,
|
isBeta: false,
|
||||||
@@ -16,7 +17,7 @@ module.exports = {
|
|||||||
.setDescription('Show list of guilds where bot is added.')
|
.setDescription('Show list of guilds where bot is added.')
|
||||||
.setDMPermission(false)
|
.setDMPermission(false)
|
||||||
.setNSFW(false),
|
.setNSFW(false),
|
||||||
execute: async ({ interaction, client, executionId }: CommandParams) => {
|
execute: async ({ interaction, client, executionId }) => {
|
||||||
const logger = loggerModule.child({
|
const logger = loggerModule.child({
|
||||||
source: 'guilds.js',
|
source: 'guilds.js',
|
||||||
module: 'slashCommand',
|
module: 'slashCommand',
|
||||||
@@ -86,3 +87,5 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default command;
|
||||||
@@ -3,12 +3,13 @@ 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 { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
|
||||||
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 = {
|
|
||||||
|
const command: CustomSlashCommandInteraction = {
|
||||||
isSystemCommand: true,
|
isSystemCommand: true,
|
||||||
isNew: false,
|
isNew: false,
|
||||||
isBeta: false,
|
isBeta: false,
|
||||||
@@ -17,7 +18,7 @@ module.exports = {
|
|||||||
.setDescription('Reload the bot commands.')
|
.setDescription('Reload the bot commands.')
|
||||||
.setDMPermission(false)
|
.setDMPermission(false)
|
||||||
.setNSFW(false),
|
.setNSFW(false),
|
||||||
execute: async ({ interaction, client, executionId }: CommandParams) => {
|
execute: async ({ interaction, client, executionId }) => {
|
||||||
const logger = loggerModule.child({
|
const logger = loggerModule.child({
|
||||||
source: 'reload.js',
|
source: 'reload.js',
|
||||||
module: 'slashCommand',
|
module: 'slashCommand',
|
||||||
@@ -82,3 +83,5 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default command;
|
||||||
@@ -3,12 +3,13 @@ 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 { ShardInfo, CustomSlashCommandInteraction } from '../../../types/interactionTypes';
|
||||||
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 = {
|
|
||||||
|
const command: CustomSlashCommandInteraction = {
|
||||||
isSystemCommand: true,
|
isSystemCommand: true,
|
||||||
isNew: false,
|
isNew: false,
|
||||||
isBeta: false,
|
isBeta: false,
|
||||||
@@ -34,7 +35,7 @@ module.exports = {
|
|||||||
)
|
)
|
||||||
|
|
||||||
.addNumberOption((option) => option.setName('page').setDescription('Page number to show').setMinValue(1)),
|
.addNumberOption((option) => option.setName('page').setDescription('Page number to show').setMinValue(1)),
|
||||||
execute: async ({ interaction, client, executionId }: CommandParams) => {
|
execute: async ({ interaction, client, executionId }) => {
|
||||||
const logger = loggerModule.child({
|
const logger = loggerModule.child({
|
||||||
source: 'shards.js',
|
source: 'shards.js',
|
||||||
module: 'slashCommand',
|
module: 'slashCommand',
|
||||||
@@ -198,3 +199,5 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default command;
|
||||||
@@ -5,14 +5,14 @@ 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 { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
|
||||||
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');
|
||||||
|
|
||||||
module.exports = {
|
const command: CustomSlashCommandInteraction = {
|
||||||
isSystemCommand: true,
|
isSystemCommand: true,
|
||||||
isNew: false,
|
isNew: false,
|
||||||
isBeta: false,
|
isBeta: false,
|
||||||
@@ -21,7 +21,7 @@ module.exports = {
|
|||||||
.setDescription('Show the bot and system status.')
|
.setDescription('Show the bot and system status.')
|
||||||
.setDMPermission(false)
|
.setDMPermission(false)
|
||||||
.setNSFW(false),
|
.setNSFW(false),
|
||||||
execute: async ({ interaction, client, executionId }: CommandParams) => {
|
execute: async ({ interaction, client, executionId }) => {
|
||||||
const logger = loggerModule.child({
|
const logger = loggerModule.child({
|
||||||
source: 'systemstatus.js',
|
source: 'systemstatus.js',
|
||||||
module: 'slashCommand',
|
module: 'slashCommand',
|
||||||
@@ -171,3 +171,5 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default command;
|
||||||
@@ -4,108 +4,112 @@ import { EmbedBuilder, GuildMember } from 'discord.js';
|
|||||||
|
|
||||||
import loggerModule from '../../services/logger';
|
import loggerModule from '../../services/logger';
|
||||||
import { EmbedOptions } from '../../types/configTypes';
|
import { EmbedOptions } from '../../types/configTypes';
|
||||||
import { ComponentInteractionParams } from '../../types/interactionTypes';
|
import { CustomComponentInteraction } from '../../types/interactionTypes';
|
||||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||||
|
|
||||||
export const execute = async ({ interaction, trackId, executionId }: ComponentInteractionParams) => {
|
const component: CustomComponentInteraction = {
|
||||||
const logger = loggerModule.child({
|
execute: async ({ interaction, trackId, executionId }) => {
|
||||||
source: 'nowplaying-skip.js',
|
const logger = loggerModule.child({
|
||||||
module: 'componentInteraction',
|
source: 'nowplaying-skip.js',
|
||||||
name: 'nowplaying-skip',
|
module: 'componentInteraction',
|
||||||
executionId: executionId,
|
name: 'nowplaying-skip',
|
||||||
shardId: interaction.guild?.shardId,
|
executionId: executionId,
|
||||||
guildId: interaction.guild?.id
|
shardId: interaction.guild?.shardId,
|
||||||
});
|
guildId: interaction.guild?.id
|
||||||
|
});
|
||||||
|
|
||||||
const queue: NodeResolvable = useQueue(interaction.guild!.id)!;
|
const queue: NodeResolvable = useQueue(interaction.guild!.id)!;
|
||||||
|
|
||||||
logger.debug(`Received skip confirmation for track id ${trackId}.`);
|
logger.debug(`Received skip confirmation for track id ${trackId}.`);
|
||||||
if (!queue || (queue.tracks.data.length === 0 && !queue.currentTrack)) {
|
if (!queue || (queue.tracks.data.length === 0 && !queue.currentTrack)) {
|
||||||
logger.debug('Tried skipping track but there was no queue.');
|
logger.debug('Tried skipping track but there was no queue.');
|
||||||
|
|
||||||
logger.debug('Responding with warning embed.');
|
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({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
|
.setAuthor({
|
||||||
|
name: authorName,
|
||||||
|
iconURL: interaction.user.avatarURL() || ''
|
||||||
|
})
|
||||||
.setDescription(
|
.setDescription(
|
||||||
`**${embedOptions.icons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with **\`/play\`**!`
|
`**${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\`**.`
|
||||||
|
}`
|
||||||
)
|
)
|
||||||
.setColor(embedOptions.colors.warning)
|
.setThumbnail(skippedTrack.thumbnail)
|
||||||
|
.setColor(embedOptions.colors.success)
|
||||||
],
|
],
|
||||||
components: []
|
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: []
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default component;
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
import { AutocompleteInteraction, ChatInputCommandInteraction } from 'discord.js';
|
|
||||||
|
|
||||||
import { ExtendedClient } from './clientTypes';
|
|
||||||
|
|
||||||
export interface CommandParams {
|
|
||||||
interaction: ChatInputCommandInteraction;
|
|
||||||
client: ExtendedClient | undefined;
|
|
||||||
executionId: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface CommandAutocompleteParams {
|
|
||||||
interaction: AutocompleteInteraction;
|
|
||||||
client: ExtendedClient | undefined;
|
|
||||||
executionId: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ShardInfo {
|
|
||||||
shardId: number;
|
|
||||||
memUsage: number;
|
|
||||||
guildCount: number;
|
|
||||||
guildMemberCount: number;
|
|
||||||
playerStatistics: {
|
|
||||||
activeVoiceConnections: number;
|
|
||||||
totalTracks: number;
|
|
||||||
totalListeners: number;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface TrackMetadata {
|
|
||||||
bridge: {
|
|
||||||
views: number;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export class CustomError extends Error {
|
|
||||||
type?: string;
|
|
||||||
code?: string;
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,61 @@
|
|||||||
import { MessageComponentInteraction } from 'discord.js';
|
import { AutocompleteInteraction, ChatInputCommandInteraction, Message, MessageComponentInteraction, SlashCommandBuilder } from 'discord.js';
|
||||||
|
import { ExtendedClient } from './clientTypes';
|
||||||
|
|
||||||
export interface ComponentInteractionParams {
|
// Local types
|
||||||
|
interface CommandParams {
|
||||||
|
client?: ExtendedClient;
|
||||||
|
executionId: string;
|
||||||
|
interaction: ChatInputCommandInteraction;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AutocompleteParams {
|
||||||
|
executionId: string;
|
||||||
|
interaction: AutocompleteInteraction;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ComponentParams {
|
||||||
interaction: MessageComponentInteraction;
|
interaction: MessageComponentInteraction;
|
||||||
trackId?: string;
|
trackId?: string;
|
||||||
executionId: string;
|
executionId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Interaction types
|
||||||
|
export interface CustomSlashCommandInteraction {
|
||||||
|
isNew: boolean;
|
||||||
|
isBeta: boolean;
|
||||||
|
isSystemCommand?: boolean;
|
||||||
|
data: Omit<SlashCommandBuilder, 'addSubcommand' | 'addSubcommandGroup'>;
|
||||||
|
execute(params: CommandParams): Promise<Message<boolean> | undefined>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CustomAutocompleteInteraction {
|
||||||
|
execute(params: AutocompleteParams): Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CustomComponentInteraction {
|
||||||
|
execute(params: ComponentParams): Promise<Message<boolean> | undefined>;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Command specific types
|
||||||
|
export interface ShardInfo {
|
||||||
|
shardId: number;
|
||||||
|
memUsage: number;
|
||||||
|
guildCount: number;
|
||||||
|
guildMemberCount: number;
|
||||||
|
playerStatistics: {
|
||||||
|
activeVoiceConnections: number;
|
||||||
|
totalTracks: number;
|
||||||
|
totalListeners: number;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TrackMetadata {
|
||||||
|
bridge: {
|
||||||
|
views: number;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CustomError extends Error {
|
||||||
|
type?: string;
|
||||||
|
code?: string;
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@ import path from 'node:path';
|
|||||||
import loggerModule from '../services/logger';
|
import loggerModule from '../services/logger';
|
||||||
import { RegisterClientCommandsParams } from '../types/utilTypes';
|
import { RegisterClientCommandsParams } from '../types/utilTypes';
|
||||||
|
|
||||||
export const registerClientCommands = ({ client, executionId }: RegisterClientCommandsParams) => {
|
export const registerClientCommands = async ({ client, executionId }: RegisterClientCommandsParams) => {
|
||||||
const logger = loggerModule.child({
|
const logger = loggerModule.child({
|
||||||
source: 'registerClientCommands.js',
|
source: 'registerClientCommands.js',
|
||||||
module: 'register',
|
module: 'register',
|
||||||
@@ -30,10 +30,11 @@ export const registerClientCommands = ({ client, executionId }: RegisterClientCo
|
|||||||
delete require.cache[require.resolve(`../interactions/commands/${folder}/${file}`)];
|
delete require.cache[require.resolve(`../interactions/commands/${folder}/${file}`)];
|
||||||
|
|
||||||
// register command
|
// register command
|
||||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
//const command = require(`../interactions/commands/${folder}/${file}`);
|
||||||
const command = require(`../interactions/commands/${folder}/${file}`);
|
const commandModule = await import(`../interactions/commands/${folder}/${file}`);
|
||||||
client.commands.delete(command.data.name);
|
|
||||||
client.commands.set(command.data.name, command);
|
client.commands.delete(commandModule.default.data.name);
|
||||||
|
client.commands.set(commandModule.default.data.name, commandModule.default);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
logger.error(`Error registering command ${folder}/${file}: ${error.message}`);
|
logger.error(`Error registering command ${folder}/${file}: ${error.message}`);
|
||||||
|
|||||||
Reference in new issue
Block a user