Merge branch 'main' into configurable-options

This commit is contained in:
Marius Begby committed 2024-01-30 11:35:47 +01:00
commit 0b0c3c4326
41 files changed
+750 -739

No files matched your search

+39
View File
@@ -0,0 +1,39 @@
import { ExtendedGuildQueuePlayerNode } from '../../types/eventTypes';
import { randomUUID as uuidv4 } from 'node:crypto';
import loggerModule from '../../services/logger';
import { Track } from 'discord-player';
import { Snowflake } from 'discord.js';
import { Logger } from 'pino';
// Emitted when the audio player finish playing a track.
module.exports = {
name: 'playerFinish',
isDebug: false,
isPlayerEvent: true,
execute: async (queue: ExtendedGuildQueuePlayerNode, track: Track) => {
const executionId: string = uuidv4();
const logger: Logger = loggerModule.child({
module: 'event',
name: 'playerFinish',
executionId: executionId,
shardId: queue.metadata?.client.shard?.ids[0],
guildId: queue.metadata?.channel.guild.id
});
logger.debug(`playerFinish event: Track [${track.url}] finished playing.`);
const { lastMessage } = queue.metadata || {};
const fetchLastAnnounceMessage =
(await queue.metadata?.channel.messages.fetch(lastMessage?.id as Snowflake)) || undefined;
if (fetchLastAnnounceMessage && fetchLastAnnounceMessage.deletable) {
try {
await fetchLastAnnounceMessage.delete();
} catch (error) {
logger.error(error, 'playerFinish event: Error deleting previous now-playing message.');
}
}
logger.debug('playerFinish event: Previous now-playing message deleted.');
}
};
+53 -4
View File
@@ -1,8 +1,12 @@
import { Track } from 'discord-player';
import { randomUUID as uuidv4 } from 'node:crypto';
import { Logger } from 'pino';
import loggerModule from '../../services/logger';
import { ExtendedGuildQueuePlayerNode } from '../../types/eventTypes';
import { useLanguageTranslator } from '../../common/localeUtil';
import { EmbedBuilder, LocaleString } from 'discord.js';
import { EmbedOptions } from '../../types/configTypes';
import { randomUUID as uuidv4 } from 'node:crypto';
import loggerModule from '../../services/logger';
import { Track } from 'discord-player';
import { Logger } from 'pino';
import config from 'config';
module.exports = {
name: 'playerStart',
@@ -19,5 +23,50 @@ module.exports = {
});
logger.debug(`playerStart event: Started playing '${track.url}'.`);
const { channel, client } = queue.metadata || {};
const embedOptions: EmbedOptions = config.get('embedOptions');
if (!embedOptions.behavior.enablePlayerStartMessages) {
logger.debug('playerStart event: Player start messages are disabled, skipping now-playing message.');
return;
}
if (channel && !client?.channels.cache.get(channel.id)) {
logger.warn(
`playerStart event: No channel found for guild ${queue.metadata?.channel.guild.id}, cannot send now-playing message.`
);
return;
}
const guildLanguage: LocaleString =
queue.metadata?.client.guilds.cache.get(queue.metadata?.channel.guild.id)?.preferredLocale ?? 'en-US';
const translator = useLanguageTranslator(guildLanguage);
const translatedEmbedMessage: string = translator('musicPlayerCommon.nowPlayingTitle', {
icon: embedOptions.icons.audioStartedPlaying
});
const embed = new EmbedBuilder()
.setAuthor({
name: track.requestedBy?.username as string,
iconURL: track.requestedBy?.displayAvatarURL()
})
.setDescription(`${translatedEmbedMessage}\n\`${track.duration}\` [**${track.title}**](${track.url})`)
.setThumbnail(track.thumbnail)
.setColor(embedOptions.colors.info);
try {
const announceMessage = await channel?.send({ embeds: [embed] });
if (queue.metadata && announceMessage) {
queue.metadata.lastMessage = announceMessage;
}
} catch (error) {
logger.error(error, 'playerStart event: Error trying to send now-playing message.');
return;
}
logger.debug('playerStart event: now-playing message sent.');
}
};
+12 -9
View File
@@ -5,6 +5,7 @@ import { getTrackName, isQueryTooShort, shouldUseLastQuery } from '../../common/
import { BaseAutocompleteParams, BaseAutocompleteReturnType, RecentQuery } from '../../types/interactionTypes';
import { TFunction } from 'i18next';
import { useUserTranslator } from '../../common/localeUtil';
import { transformQuery } from '../../utils/validation/searchQueryValidator';
class PlayAutocomplete extends BaseAutocompleteInteraction {
private recentQueries = new Map<string, RecentQuery>();
@@ -18,33 +19,35 @@ class PlayAutocomplete extends BaseAutocompleteInteraction {
const logger = this.getLogger(this.name, executionId, interaction);
const translator = useUserTranslator(interaction);
const query: string = interaction.options.getString('query', true);
const searchQuery: string = interaction.options.getString('query', true);
const transformedQuery = transformQuery({ query: searchQuery, executionId });
const { lastQuery, result, timestamp } = this.recentQueries.get(interaction.user.id) || {};
if (shouldUseLastQuery(query, lastQuery, timestamp)) {
logger.debug(`Responding with results from lastQuery for query '${query}'`);
if (shouldUseLastQuery(transformedQuery, lastQuery, timestamp)) {
logger.debug(`Responding with results from lastQuery for query '${transformedQuery}'`);
return interaction.respond(result as ApplicationCommandOptionChoiceData<string | number>[]);
}
if (isQueryTooShort(query)) {
logger.debug(`Responding with empty results due to < 3 length for query '${query}'`);
if (isQueryTooShort(transformedQuery)) {
logger.debug(`Responding with empty results due to < 3 length for query '${transformedQuery}'`);
return interaction.respond([]);
}
const autocompleteChoices: ApplicationCommandOptionChoiceData<string>[] = await this.getAutocompleteChoices(
query,
transformedQuery,
translator
);
if (!autocompleteChoices || autocompleteChoices.length === 0) {
logger.debug(`Responding with empty results for query '${query}'`);
logger.debug(`Responding with empty results for query '${transformedQuery}'`);
return interaction.respond([]);
}
this.updateRecentQuery(interaction.user.id, query, autocompleteChoices);
this.updateRecentQuery(interaction.user.id, transformedQuery, autocompleteChoices);
logger.debug(`Responding to autocomplete with results for query: '${query}'.`);
logger.debug(`Responding to autocomplete with results for query: '${transformedQuery}'.`);
return interaction.respond(autocompleteChoices);
}
-102
View File
@@ -1,102 +0,0 @@
import { EmbedBuilder, Guild, SlashCommandBuilder } from 'discord.js';
import { Logger } from 'pino';
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { ExtendedClient } from '../../../types/clientTypes';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { checkValidGuildId } from '../../../utils/validation/systemCommandValidator';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { TFunction } from 'i18next';
class GuildsCommand extends BaseSlashCommandInteraction {
constructor() {
const data = localizeCommand(new SlashCommandBuilder().setName('guilds'));
const isSystemCommand: boolean = true;
super(data, isSystemCommand);
}
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction, client } = params;
const logger = this.getLogger(this.name, executionId, interaction);
const translator = useServerTranslator(interaction);
await this.runValidators({ interaction, executionId }, [checkValidGuildId]);
const shardGuilds = await this.fetchShardGuilds(client!, logger);
const totalGuildCount = shardGuilds.length;
logger.debug(`Successfully fetched ${totalGuildCount} guilds.`);
const guildListFormatted = this.formatGuildListAsString(shardGuilds);
const totalMemberCount = this.calculateTotalMemberCount(shardGuilds);
let embedDescription = this.buildEmbedDescription(
totalGuildCount,
guildListFormatted,
totalMemberCount,
translator
);
if (embedDescription.length >= 4000) {
logger.debug('Embed description is too long, truncating.');
embedDescription = `${embedDescription.slice(0, 3996)}...`;
}
logger.debug('Responding with info embed.');
return await interaction.editReply({
embeds: [new EmbedBuilder().setDescription(embedDescription).setColor(this.embedOptions.colors.info)]
});
}
private async fetchShardGuilds(client: ExtendedClient, logger: Logger): Promise<Guild[]> {
logger.debug('Fetching guilds from all shards.');
const guilds = await client!.shard!.broadcastEval((c) => c.guilds.cache.map((guild) => guild));
return guilds.flat(1) as Guild[];
}
private formatGuildListAsString(shardGuilds: Guild[]): string {
const guilds = this.mapGuilds(shardGuilds);
const topGuilds = this.getTopGuilds(guilds);
return this.guildsToString(topGuilds);
}
private mapGuilds(shardGuilds: Guild[]) {
return shardGuilds.map((guild) => ({ name: guild.name, memberCount: guild.memberCount }));
}
private getTopGuilds(guilds: { name: string; memberCount: number }[]) {
return guilds.sort((a, b) => b.memberCount - a.memberCount).slice(0, 25);
}
private guildsToString(guilds: { name: string; memberCount: number }[]) {
return guilds.map((guild, index) => `${index + 1}. \`${guild.name} (#${guild.memberCount})\``).join('\n');
}
private calculateTotalMemberCount(shardGuilds: Guild[]): number {
return shardGuilds.reduce((a, b) => a + b.memberCount, 0);
}
private buildEmbedDescription(
totalGuildCount: number,
guildListFormattedString: string,
totalMemberCount: number,
translator: TFunction
): string {
const guildCount = Math.max(totalGuildCount, 25);
return (
translator('commands.guilds.topGuildsByMemberCount', {
icon: this.embedOptions.icons.bot,
count: guildCount,
totalCount: totalGuildCount
}) +
'\n' +
guildListFormattedString +
'\n' +
'\n' +
translator('commands.guilds.totalMembers', {
count: totalMemberCount
})
);
}
}
export default new GuildsCommand();
@@ -1,13 +1,13 @@
import { GuildQueue, GuildQueueHistory, Track, useHistory, useQueue } from 'discord-player';
import { ChatInputCommandInteraction, EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { checkHistoryExists, checkQueueCurrentTrack } from '../../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { BaseSlashCommandInteraction } from '../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../types/interactionTypes';
import { checkHistoryExists, checkQueueCurrentTrack } from '../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { Logger } from 'pino';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { localizeCommand, useServerTranslator } from '../../common/localeUtil';
import { TFunction } from 'i18next';
import { formatSlashCommand } from '../../../common/formattingUtils';
import { formatSlashCommand } from '../../common/formattingUtils';
class BackCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -16,17 +16,17 @@ import {
StringSelectMenuOptionBuilder
} from 'discord.js';
import { Logger } from 'pino';
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { BaseSlashCommandInteraction } from '../../classes/interactions';
import {
BiquadFilterOptions,
EqualizerFilterOptions,
FFmpegFilterOptions,
FilterOption
} from '../../../types/configTypes';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { checkQueueCurrentTrack, checkQueueExists } from '../../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
} from '../../types/configTypes';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../types/interactionTypes';
import { checkQueueCurrentTrack, checkQueueExists } from '../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { localizeCommand, useServerTranslator } from '../../common/localeUtil';
import { TFunction } from 'i18next';
const ffmpegFilterOptions: FFmpegFilterOptions = config.get('ffmpegFilterOptions');
@@ -13,10 +13,10 @@ import {
SlashCommandNumberOption,
SlashCommandStringOption
} from 'discord.js';
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { CommandMetadata, localizeCommand, translatorInstance, useServerTranslator } from '../../../common/localeUtil';
import { ExtendedClient } from '../../../types/clientTypes';
import { BaseSlashCommandInteraction } from '../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../types/interactionTypes';
import { CommandMetadata, localizeCommand, translatorInstance, useServerTranslator } from '../../common/localeUtil';
import { ExtendedClient } from '../../types/clientTypes';
class HelpCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -12,13 +12,13 @@ import {
SlashCommandBuilder
} from 'discord.js';
import { Logger } from 'pino';
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { checkHistoryExists } from '../../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { BaseSlashCommandInteraction } from '../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../types/interactionTypes';
import { checkHistoryExists } from '../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { localizeCommand, useServerTranslator } from '../../common/localeUtil';
import { TFunction } from 'i18next';
import { formatRepeatModeDetailed, formatSlashCommand } from '../../../common/formattingUtils';
import { formatRepeatModeDetailed, formatSlashCommand } from '../../common/formattingUtils';
class HistoryCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -1,12 +1,12 @@
import { GuildQueue, useMainPlayer, useQueue } from 'discord-player';
import { ChatInputCommandInteraction, EmbedBuilder, GuildMember, Message, SlashCommandBuilder } from 'discord.js';
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { checkInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { checkVoicePermissionJoinAndTalk } from '../../../utils/validation/permissionValidator';
import { BaseSlashCommandInteraction } from '../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../types/interactionTypes';
import { checkInVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { checkVoicePermissionJoinAndTalk } from '../../utils/validation/permissionValidator';
import { Logger } from 'pino';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { formatSlashCommand } from '../../../common/formattingUtils';
import { localizeCommand, useServerTranslator } from '../../common/localeUtil';
import { formatSlashCommand } from '../../common/formattingUtils';
import { TFunction } from 'i18next';
class JoinCommand extends BaseSlashCommandInteraction {
@@ -1,11 +1,11 @@
import { GuildQueue, useQueue } from 'discord-player';
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { checkQueueExists } from '../../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { formatSlashCommand } from '../../../common/formattingUtils';
import { BaseSlashCommandInteraction } from '../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../types/interactionTypes';
import { checkQueueExists } from '../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { localizeCommand, useServerTranslator } from '../../common/localeUtil';
import { formatSlashCommand } from '../../common/formattingUtils';
class LeaveCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -7,13 +7,13 @@ import {
SlashCommandIntegerOption
} from 'discord.js';
import { Logger } from 'pino';
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { checkQueueExists } from '../../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { BaseSlashCommandInteraction } from '../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../types/interactionTypes';
import { checkQueueExists } from '../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { localizeCommand, useServerTranslator } from '../../common/localeUtil';
import { TFunction } from 'i18next';
import { formatRepeatMode } from '../../../common/formattingUtils';
import { formatRepeatMode } from '../../common/formattingUtils';
class LoopCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -2,11 +2,11 @@ import { LyricsData, lyricsExtractor } from '@discord-player/extractor';
import { GuildQueue, Player, QueryType, SearchResult, Track, useMainPlayer, useQueue } from 'discord-player';
import { ChatInputCommandInteraction, EmbedBuilder, Message, SlashCommandBuilder } from 'discord.js';
import { Logger } from 'pino';
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { checkQueueCurrentTrack, checkQueueExists } from '../../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { BaseSlashCommandInteraction } from '../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../types/interactionTypes';
import { checkQueueCurrentTrack, checkQueueExists } from '../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { localizeCommand, useServerTranslator } from '../../common/localeUtil';
import { TFunction } from 'i18next';
class LyricsCommand extends BaseSlashCommandInteraction {
@@ -1,13 +1,13 @@
import { GuildQueue, Track, useQueue } from 'discord-player';
import { ChatInputCommandInteraction, EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { checkQueueCurrentTrack, checkQueueExists } from '../../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { BaseSlashCommandInteraction } from '../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../types/interactionTypes';
import { checkQueueCurrentTrack, checkQueueExists } from '../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { Logger } from 'pino';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { localizeCommand, useServerTranslator } from '../../common/localeUtil';
import { TFunction } from 'i18next';
import { formatSlashCommand } from '../../../common/formattingUtils';
import { formatSlashCommand } from '../../common/formattingUtils';
class MoveCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -10,13 +10,13 @@ import {
EmbedField,
SlashCommandBuilder
} from 'discord.js';
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType, TrackMetadata } from '../../../types/interactionTypes';
import { checkQueueCurrentTrack, checkQueueExists } from '../../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { BaseSlashCommandInteraction } from '../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType, TrackMetadata } from '../../types/interactionTypes';
import { checkQueueCurrentTrack, checkQueueExists } from '../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { localizeCommand, useServerTranslator } from '../../common/localeUtil';
import { TFunction } from 'i18next';
import { formatRepeatModeDetailed } from '../../../common/formattingUtils';
import { formatRepeatModeDetailed } from '../../common/formattingUtils';
class NowPlayingCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -1,11 +1,11 @@
import { GuildQueue, Track, useQueue } from 'discord-player';
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import { Logger } from 'pino';
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { checkQueueCurrentTrack, checkQueueExists } from '../../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { BaseSlashCommandInteraction } from '../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../types/interactionTypes';
import { checkQueueCurrentTrack, checkQueueExists } from '../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { localizeCommand, useServerTranslator } from '../../common/localeUtil';
class PauseCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -8,14 +8,14 @@ import {
SlashCommandBuilder
} from 'discord.js';
import { Logger } from 'pino';
import { BaseSlashCommandInteraction, CustomError } from '../../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { checkVoicePermissionJoinAndTalk } from '../../../utils/validation/permissionValidator';
import { transformQuery } from '../../../utils/validation/searchQueryValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { BaseSlashCommandInteraction, CustomError } from '../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../types/interactionTypes';
import { checkVoicePermissionJoinAndTalk } from '../../utils/validation/permissionValidator';
import { transformQuery } from '../../utils/validation/searchQueryValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { localizeCommand, useServerTranslator } from '../../common/localeUtil';
import { TFunction } from 'i18next';
import { formatSlashCommand } from '../../../common/formattingUtils';
import { formatSlashCommand } from '../../common/formattingUtils';
class PlayCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -190,13 +190,15 @@ class PlayCommand extends BaseSlashCommandInteraction {
embedFooter = this.getDisplayFooterTrackPosition(posistionFirstTrackInPlaylist, translator);
}
} else if (queue.currentTrack === track && queue.tracks.data.length === 0) {
message =
translator('musicPlayerCommon.nowPlayingTitle', {
icon: this.embedOptions.icons.audioStartedPlaying
}) +
'\n' +
trackUrl;
embedFooter = undefined;
if (!this.embedOptions.behavior.enablePlayerStartMessages) {
message =
translator('musicPlayerCommon.nowPlayingTitle', {
icon: this.embedOptions.icons.audioStartedPlaying
}) +
'\n' +
trackUrl;
embedFooter = undefined;
}
}
const embed = new EmbedBuilder()
@@ -12,12 +12,12 @@ import {
SlashCommandBuilder
} from 'discord.js';
import { Logger } from 'pino';
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { checkQueueExists } from '../../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { formatDuration, formatRepeatModeDetailed, formatSlashCommand } from '../../../common/formattingUtils';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { BaseSlashCommandInteraction } from '../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../types/interactionTypes';
import { checkQueueExists } from '../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { formatDuration, formatRepeatModeDetailed, formatSlashCommand } from '../../common/formattingUtils';
import { localizeCommand, useServerTranslator } from '../../common/localeUtil';
import { TFunction } from 'i18next';
class QueueCommand extends BaseSlashCommandInteraction {
@@ -6,11 +6,11 @@ import {
SlashCommandBuilder
} from 'discord.js';
import { Logger } from 'pino';
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { ExtendedClient } from '../../../types/clientTypes';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { checkValidGuildId } from '../../../utils/validation/systemCommandValidator';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { BaseSlashCommandInteraction } from '../../classes/interactions';
import { ExtendedClient } from '../../types/clientTypes';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../types/interactionTypes';
import { checkValidGuildId } from '../../utils/validation/systemCommandValidator';
import { localizeCommand, useServerTranslator } from '../../common/localeUtil';
import { TFunction } from 'i18next';
class ReloadCommand extends BaseSlashCommandInteraction {
@@ -1,13 +1,13 @@
import { GuildQueue, Track, useQueue } from 'discord-player';
import { ChatInputCommandInteraction, EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { checkQueueExists } from '../../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { BaseSlashCommandInteraction } from '../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../types/interactionTypes';
import { checkQueueExists } from '../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { Logger } from 'pino';
import { TFunction } from 'i18next';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { formatSlashCommand } from '../../../common/formattingUtils';
import { localizeCommand, useServerTranslator } from '../../common/localeUtil';
import { formatSlashCommand } from '../../common/formattingUtils';
class RemoveCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -1,13 +1,13 @@
import { GuildQueue, useQueue } from 'discord-player';
import { ChatInputCommandInteraction, EmbedBuilder, Message, SlashCommandBuilder } from 'discord.js';
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { checkQueueCurrentTrack, checkQueueExists } from '../../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { BaseSlashCommandInteraction } from '../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../types/interactionTypes';
import { checkQueueCurrentTrack, checkQueueExists } from '../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { Logger } from 'pino';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { localizeCommand, useServerTranslator } from '../../common/localeUtil';
import { TFunction } from 'i18next';
import { formatSlashCommand } from '../../../common/formattingUtils';
import { formatSlashCommand } from '../../common/formattingUtils';
class SeekCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -5,12 +5,12 @@ import {
EmbedFooterData,
SlashCommandBuilder
} from 'discord.js';
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { ExtendedClient } from '../../../types/clientTypes';
import { BaseSlashCommandParams, BaseSlashCommandReturnType, ShardInfo } from '../../../types/interactionTypes';
import { checkValidGuildId } from '../../../utils/validation/systemCommandValidator';
import { BaseSlashCommandInteraction } from '../../classes/interactions';
import { ExtendedClient } from '../../types/clientTypes';
import { BaseSlashCommandParams, BaseSlashCommandReturnType, ShardInfo } from '../../types/interactionTypes';
import { checkValidGuildId } from '../../utils/validation/systemCommandValidator';
import { Logger } from 'pino';
import { localizeCommand } from '../../../common/localeUtil';
import { localizeCommand } from '../../common/localeUtil';
class ShardsCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -1,11 +1,11 @@
import { GuildQueue, useQueue } from 'discord-player';
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { checkQueueEmpty, checkQueueExists } from '../../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { formatSlashCommand } from '../../../common/formattingUtils';
import { BaseSlashCommandInteraction } from '../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../types/interactionTypes';
import { checkQueueEmpty, checkQueueExists } from '../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { localizeCommand, useServerTranslator } from '../../common/localeUtil';
import { formatSlashCommand } from '../../common/formattingUtils';
class ShuffleCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -1,13 +1,13 @@
import { GuildQueue, Track, useQueue } from 'discord-player';
import { ChatInputCommandInteraction, EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { checkQueueCurrentTrack, checkQueueExists } from '../../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { BaseSlashCommandInteraction } from '../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../types/interactionTypes';
import { checkQueueCurrentTrack, checkQueueExists } from '../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { Logger } from 'pino';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { localizeCommand, useServerTranslator } from '../../common/localeUtil';
import { TFunction } from 'i18next';
import { formatRepeatModeDetailed, formatSlashCommand } from '../../../common/formattingUtils';
import { formatRepeatModeDetailed, formatSlashCommand } from '../../common/formattingUtils';
class SkipCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -1,5 +1,5 @@
// @ts-ignore
import { version } from '../../../../package.json';
import { version } from '../../../package.json';
import {
APIActionRowComponent,
APIButtonComponent,
@@ -10,10 +10,10 @@ import {
EmbedBuilder,
SlashCommandBuilder
} from 'discord.js';
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { getBotStatistics, getDiscordStatus, getPlayerStatistics, getSystemStatus } from '../../../common/statusUtils';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { BaseSlashCommandInteraction } from '../../classes/interactions';
import { getBotStatistics, getDiscordStatus, getPlayerStatistics, getSystemStatus } from '../../common/statusUtils';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../types/interactionTypes';
import { localizeCommand, useServerTranslator } from '../../common/localeUtil';
class StatusCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -1,11 +1,11 @@
import { GuildQueue, QueueRepeatMode, useQueue } from 'discord-player';
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { checkQueueExists } from '../../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { formatSlashCommand } from '../../../common/formattingUtils';
import { BaseSlashCommandInteraction } from '../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../types/interactionTypes';
import { checkQueueExists } from '../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { localizeCommand, useServerTranslator } from '../../common/localeUtil';
import { formatSlashCommand } from '../../common/formattingUtils';
class StopCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -1,11 +1,11 @@
// @ts-ignore
import { dependencies, version } from '../../../../package.json';
import { dependencies, version } from '../../../package.json';
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { getBotStatistics, getDiscordStatus, getPlayerStatistics, getSystemStatus } from '../../../common/statusUtils';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { checkValidGuildId } from '../../../utils/validation/systemCommandValidator';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { BaseSlashCommandInteraction } from '../../classes/interactions';
import { getBotStatistics, getDiscordStatus, getPlayerStatistics, getSystemStatus } from '../../common/statusUtils';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../types/interactionTypes';
import { checkValidGuildId } from '../../utils/validation/systemCommandValidator';
import { localizeCommand, useServerTranslator } from '../../common/localeUtil';
class SystemStatusCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -1,11 +1,11 @@
import { GuildQueue, useQueue } from 'discord-player';
import { ChatInputCommandInteraction, EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { checkQueueExists } from '../../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { BaseSlashCommandInteraction } from '../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../types/interactionTypes';
import { checkQueueExists } from '../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { Logger } from 'pino';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { localizeCommand, useServerTranslator } from '../../common/localeUtil';
import { TFunction } from 'i18next';
class VolumeCommand extends BaseSlashCommandInteraction {
+1 -1
View File
@@ -1,4 +1,4 @@
import helpCommand from '../interactions/commands/info/help';
import helpCommand from '../interactions/slashcommands/help';
import { SlashCommandNumberOption } from 'discord.js';
import { BaseSlashCommandInteraction } from '../classes/interactions';
+3
View File
@@ -43,6 +43,9 @@ export type EmbedOptions = {
components: {
showButtonLabels: boolean;
};
behavior: {
enablePlayerStartMessages: boolean;
};
icons: {
logo: string;
beta: string;
+2 -1
View File
@@ -1,5 +1,5 @@
import { BaseGuildTextChannel, Message } from 'discord.js';
import { GuildQueuePlayerNode } from 'discord-player';
import { BaseGuildTextChannel } from 'discord.js';
import { ExtendedClient } from './clientTypes';
export type ClientEventArguments = unknown[];
@@ -12,5 +12,6 @@ export type ExtendedGuildQueuePlayerNode = {
| {
client: ExtendedClient;
channel: BaseGuildTextChannel;
lastMessage: Message;
};
} & GuildQueuePlayerNode<unknown>;
+9 -12
View File
@@ -20,7 +20,6 @@ const logger: Logger = loggerModule.child({
const userSlashCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[] = [];
const systemSlashCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[] = [];
const commandFolders: string[] = fs.readdirSync(path.resolve('./dist/interactions/commands'));
if (!process.env.DISCORD_BOT_TOKEN) {
throw new Error('DISCORD_BOT_TOKEN environment variable is not set.');
@@ -40,18 +39,16 @@ const rest: REST = new REST({ version: '10' }).setToken(process.env.DISCORD_BOT_
process.exit(1);
}
for (const folder of commandFolders) {
const commandFiles: string[] = fs
.readdirSync(path.resolve(`./dist/interactions/commands/${folder}`))
.filter((file) => file.endsWith('.js'));
const commandFiles: string[] = fs
.readdirSync(path.resolve('./dist/interactions/slashcommands'))
.filter((file) => file.endsWith('.js'));
for (const file of commandFiles) {
const { default: command } = await import(`../interactions/commands/${folder}/${file}`);
const slashCommand = command as BaseSlashCommandInteraction;
slashCommand.isSystemCommand
? systemSlashCommands.push(slashCommand.data.toJSON())
: userSlashCommands.push(slashCommand.data.toJSON());
}
for (const file of commandFiles) {
const { default: command } = await import(`../interactions/slashcommands/${file}`);
const slashCommand = command as BaseSlashCommandInteraction;
slashCommand.isSystemCommand
? systemSlashCommands.push(slashCommand.data.toJSON())
: userSlashCommands.push(slashCommand.data.toJSON());
}
try {
+17 -24
View File
@@ -25,35 +25,28 @@ async function registerSlashCommandInteractions(logger: Logger, client: Extended
logger.debug('Registering client slash command interactions...');
client.slashCommandInteractions = new Collection();
const baseFolderPath = './dist/interactions/commands';
const slashCommandInteractionFolders: string[] = fs.readdirSync(path.resolve(baseFolderPath));
const basePath = './dist/interactions/slashcommands';
for (const categoryFolder of slashCommandInteractionFolders) {
logger.trace(`Registering client commands for folder '${categoryFolder}'...`);
logger.trace('Registering client commands...');
const files: string[] = fs
.readdirSync(path.resolve(`${baseFolderPath}/${categoryFolder}`))
.filter((file) => file.endsWith('.js'));
const files: string[] = fs.readdirSync(path.resolve(`${basePath}`)).filter((file) => file.endsWith('.js'));
for (const file of files) {
try {
const filePath = path.resolve(`${baseFolderPath}/${categoryFolder}/${file}`);
for (const file of files) {
try {
const filePath = path.resolve(`${basePath}/${file}`);
// delete require cache for file
delete require.cache[filePath];
// delete require cache for file
delete require.cache[filePath];
// import and register to client collection
const { default: slashCommandInteraction } = await import(filePath);
client.slashCommandInteractions.delete(slashCommandInteraction.name);
client.slashCommandInteractions.set(slashCommandInteraction.name, slashCommandInteraction);
} catch (error) {
if (error instanceof Error) {
logger.error(
`Error registering slash command interaction '${categoryFolder}/${file}': ${error.message}`
);
} else {
throw error;
}
// import and register to client collection
const { default: slashCommandInteraction } = await import(filePath);
client.slashCommandInteractions.delete(slashCommandInteraction.name);
client.slashCommandInteractions.set(slashCommandInteraction.name, slashCommandInteraction);
} catch (error) {
if (error instanceof Error) {
logger.error(`Error registering slash command interaction '${file}': ${error.message}`);
} else {
throw error;
}
}
}
@@ -27,6 +27,15 @@ export const transformQuery = ({ query, executionId }: TransformQueryParams) =>
query = `https://open.spotify.com/${type}/${trackId}`;
}
}
// if /track/id is in url TWICE, remove the second one, e.g. https://open.spotify.com/track/123/track/123
const trackIdRegex: RegExp = new RegExp('https://open.spotify.com/track/([a-zA-Z0-9]+)');
const trackIdMatches: RegExpMatchArray | null = query.match(trackIdRegex);
if (trackIdMatches) {
logger.debug(`Transforming Spotify url to remove duplicate track id from query '${query}'.`);
const trackId: string = trackIdMatches[1];
query = `https://open.spotify.com/track/${trackId}`;
}
} catch (error) {
logger.error(error, 'Error while validating or transforming Spotify url.');
}