diff --git a/src/types/interactionTypes.ts b/src/classes/interactions.ts similarity index 73% rename from src/types/interactionTypes.ts rename to src/classes/interactions.ts index 9bc3f4f..fd49810 100644 --- a/src/types/interactionTypes.ts +++ b/src/classes/interactions.ts @@ -10,55 +10,16 @@ import { } from 'discord.js'; import { Logger } from 'pino'; import loggerModule from '../services/logger'; -import { ExtendedClient } from './clientTypes'; -import { BotOptions, EmbedOptions } from './configTypes'; - -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; -} - -interface BaseInteractionParams { - executionId: string; -} - -export interface BaseSlashCommandParams extends BaseInteractionParams { - interaction: ChatInputCommandInteraction; - client?: ExtendedClient; -} - -export interface BaseAutocompleteParams extends BaseInteractionParams { - interaction: AutocompleteInteraction; -} - -export interface BaseComponentParams extends BaseInteractionParams { - interaction: MessageComponentInteraction; - referenceId?: string; -} - -export type BaseSlashCommandReturnType = Promise | void>; - -export type BaseAutocompleteReturnType = Promise; - -export type BaseComponentReturnType = Promise | void>; +import { BotOptions, EmbedOptions } from '../types/configTypes'; +import { + BaseAutocompleteParams, + BaseAutocompleteReturnType, + BaseComponentParams, + BaseComponentReturnType, + BaseInteractionParams, + BaseSlashCommandParams, + BaseSlashCommandReturnType +} from '../types/interactionTypes'; abstract class BaseInteraction { protected getLoggerBase( @@ -146,3 +107,8 @@ export abstract class BaseComponentInteraction extends BaseInteraction { abstract execute(params: BaseComponentParams): BaseComponentReturnType; } + +export class CustomError extends Error { + type?: string; + code?: string; +} diff --git a/src/events/interactions/interactionCreate.ts b/src/events/interactions/interactionCreate.ts index b77088e..bcf5e86 100644 --- a/src/events/interactions/interactionCreate.ts +++ b/src/events/interactions/interactionCreate.ts @@ -14,7 +14,7 @@ import { handleComponent } from '../../handlers/interactionComponentHandler'; import { handleError } from '../../handlers/interactionErrorHandler'; import loggerModule from '../../services/logger'; import { ExtendedClient } from '../../types/clientTypes'; -import { CustomError } from '../../types/interactionTypes'; +import { CustomError } from '../../classes/interactions'; module.exports = { name: Events.InteractionCreate, diff --git a/src/events/player/generalError.ts b/src/events/player/generalError.ts index 0b3d8c4..fdcf896 100644 --- a/src/events/player/generalError.ts +++ b/src/events/player/generalError.ts @@ -26,6 +26,7 @@ module.exports = { logger.error(error, "player.events.on('error'): Player queue encountered error event"); + // TODO: check for access to send message to channel to avoid possible DiscordAPIError - Missing Access await queue.metadata?.channel.send({ embeds: [ new EmbedBuilder() diff --git a/src/handlers/interactionAutocompleteHandler.ts b/src/handlers/interactionAutocompleteHandler.ts index ab8e9ac..963dfc8 100644 --- a/src/handlers/interactionAutocompleteHandler.ts +++ b/src/handlers/interactionAutocompleteHandler.ts @@ -2,7 +2,7 @@ import { AutocompleteInteraction } from 'discord.js'; import { Logger } from 'pino'; import loggerModule from '../services/logger'; import { ExtendedClient } from '../types/clientTypes'; -import { BaseAutocompleteInteraction } from '../types/interactionTypes'; +import { BaseAutocompleteInteraction } from '../classes/interactions'; export const handleAutocomplete = async ( interaction: AutocompleteInteraction, diff --git a/src/handlers/interactionCommandHandler.ts b/src/handlers/interactionCommandHandler.ts index 9470f6f..57eb6bf 100644 --- a/src/handlers/interactionCommandHandler.ts +++ b/src/handlers/interactionCommandHandler.ts @@ -2,7 +2,7 @@ import { ChatInputCommandInteraction } from 'discord.js'; import { Logger } from 'pino'; import loggerModule from '../services/logger'; import { ExtendedClient } from '../types/clientTypes'; -import { BaseSlashCommandInteraction } from '../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../classes/interactions'; import { cannotSendMessageInChannel } from '../utils/validation/permissionValidator'; export const handleCommand = async ( diff --git a/src/handlers/interactionComponentHandler.ts b/src/handlers/interactionComponentHandler.ts index e31c180..142f690 100644 --- a/src/handlers/interactionComponentHandler.ts +++ b/src/handlers/interactionComponentHandler.ts @@ -2,7 +2,7 @@ import { MessageComponentInteraction } from 'discord.js'; import { Logger } from 'pino'; import loggerModule from '../services/logger'; import { ExtendedClient } from '../types/clientTypes'; -import { BaseComponentInteraction } from '../types/interactionTypes'; +import { BaseComponentInteraction } from '../classes/interactions'; import { cannotSendMessageInChannel } from '../utils/validation/permissionValidator'; export const handleComponent = async ( diff --git a/src/handlers/interactionErrorHandler.ts b/src/handlers/interactionErrorHandler.ts index 6ce4a3c..d5199ca 100644 --- a/src/handlers/interactionErrorHandler.ts +++ b/src/handlers/interactionErrorHandler.ts @@ -10,7 +10,7 @@ import { import { Logger } from 'pino'; import loggerModule from '../services/logger'; import { BotOptions, EmbedOptions } from '../types/configTypes'; -import { CustomError } from '../types/interactionTypes'; +import { CustomError } from '../classes/interactions'; const embedOptions: EmbedOptions = config.get('embedOptions'); const botOptions: BotOptions = config.get('botOptions'); diff --git a/src/index.ts b/src/index.ts index 3367f1e..27cda8d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,14 +1,13 @@ import 'dotenv/config'; import config from 'config'; -import { Client, Shard, ShardEvents, ShardingManager } from 'discord.js'; +import { Client, Shard, ShardEvents, ShardingManager, ShardingManagerOptions } from 'discord.js'; import { v4 as uuidv4 } from 'uuid'; import { Logger } from 'pino'; import loggerModule from './services/logger'; -import { ShardingOptions } from './types/configTypes'; -const shardingOptions: ShardingOptions = config.get('shardingOptions'); +const shardingOptions: ShardingManagerOptions = config.get('shardingOptions'); const manager: ShardingManager = new ShardingManager('./dist/bot.js', { token: process.env.DISCORD_BOT_TOKEN, diff --git a/src/interactions/autocomplete/lyrics.ts b/src/interactions/autocomplete/lyrics.ts index ae2c12b..731fa7d 100644 --- a/src/interactions/autocomplete/lyrics.ts +++ b/src/interactions/autocomplete/lyrics.ts @@ -1,13 +1,10 @@ import { LyricsData, lyricsExtractor } from '@discord-player/extractor'; import { Player, SearchResult, useMainPlayer } from 'discord-player'; import { ApplicationCommandOptionChoiceData } from 'discord.js'; -import { - BaseAutocompleteInteraction, - BaseAutocompleteParams, - BaseAutocompleteReturnType -} from '../../types/interactionTypes'; +import { BaseAutocompleteParams, BaseAutocompleteReturnType } from '../../types/interactionTypes'; +import { BaseAutocompleteInteraction } from '../../classes/interactions'; -// TODO: create interface for recent query object +// TODO: create type for recent query object const recentQueries = new Map(); class LyricsAutocomplete extends BaseAutocompleteInteraction { @@ -34,7 +31,7 @@ class LyricsAutocomplete extends BaseAutocompleteInteraction { const genius = lyricsExtractor(); const lyricsResult: LyricsData = (await genius.search(query).catch(() => null)) as LyricsData; - // TODO: Update TS Type for lyricsResult and create response object interface + // TODO: Update TS Type for lyricsResult and create response object type let response: ApplicationCommandOptionChoiceData[] = []; if (!lyricsResult) { diff --git a/src/interactions/autocomplete/play.ts b/src/interactions/autocomplete/play.ts index 0b34fee..93881b0 100644 --- a/src/interactions/autocomplete/play.ts +++ b/src/interactions/autocomplete/play.ts @@ -1,12 +1,9 @@ import { Player, SearchResult, useMainPlayer } from 'discord-player'; import { ApplicationCommandOptionChoiceData } from 'discord.js'; -import { - BaseAutocompleteInteraction, - BaseAutocompleteParams, - BaseAutocompleteReturnType -} from '../../types/interactionTypes'; +import { BaseAutocompleteParams, BaseAutocompleteReturnType } from '../../types/interactionTypes'; +import { BaseAutocompleteInteraction } from '../../classes/interactions'; -// TODO: create interface for recent query object +// TODO: create type for recent query object const recentQueries = new Map(); class PlayAutocomplete extends BaseAutocompleteInteraction { diff --git a/src/interactions/commands/info/help.ts b/src/interactions/commands/info/help.ts index 2a6d22a..af722eb 100644 --- a/src/interactions/commands/info/help.ts +++ b/src/interactions/commands/info/help.ts @@ -1,15 +1,10 @@ import { EmbedBuilder, SlashCommandBuilder, SlashCommandNumberOption, SlashCommandStringOption } from 'discord.js'; -import { - BaseSlashCommandInteraction, - BaseSlashCommandParams, - BaseSlashCommandReturnType -} from '../../../types/interactionTypes'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../classes/interactions'; class HelpCommand extends BaseSlashCommandInteraction { constructor() { - const data = new SlashCommandBuilder() - .setName('help') - .setDescription('Show the list of bot commands.'); + const data = new SlashCommandBuilder().setName('help').setDescription('Show the list of bot commands.'); super(data); } diff --git a/src/interactions/commands/info/status.ts b/src/interactions/commands/info/status.ts index d4830a2..97c58d5 100644 --- a/src/interactions/commands/info/status.ts +++ b/src/interactions/commands/info/status.ts @@ -2,11 +2,8 @@ import { EmbedBuilder, Guild, SlashCommandBuilder } from 'discord.js'; import osu from 'node-os-utils'; // @ts-ignore import { version } from '../../../../package.json'; -import { - BaseSlashCommandInteraction, - BaseSlashCommandParams, - BaseSlashCommandReturnType -} from '../../../types/interactionTypes'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../classes/interactions'; import { getUptimeFormatted } from '../../../utils/system/getUptimeFormatted'; class StatusCommand extends BaseSlashCommandInteraction { diff --git a/src/interactions/commands/player/filters.ts b/src/interactions/commands/player/filters.ts index 5380e53..9273003 100644 --- a/src/interactions/commands/player/filters.ts +++ b/src/interactions/commands/player/filters.ts @@ -14,11 +14,8 @@ import { StringSelectMenuOptionBuilder } from 'discord.js'; import { FFmpegFilterOption, FFmpegFilterOptions } from '../../../types/configTypes'; -import { - BaseSlashCommandInteraction, - BaseSlashCommandParams, - BaseSlashCommandReturnType -} from '../../../types/interactionTypes'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../classes/interactions'; import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; @@ -26,9 +23,7 @@ const ffmpegFilterOptions: FFmpegFilterOptions = config.get('ffmpegFilterOptions class FiltersCommand extends BaseSlashCommandInteraction { constructor() { - const data = new SlashCommandBuilder() - .setName('filters') - .setDescription('Toggle various audio filters.'); + const data = new SlashCommandBuilder().setName('filters').setDescription('Toggle various audio filters.'); super(data); } diff --git a/src/interactions/commands/player/leave.ts b/src/interactions/commands/player/leave.ts index 62303cb..983ded7 100644 --- a/src/interactions/commands/player/leave.ts +++ b/src/interactions/commands/player/leave.ts @@ -1,10 +1,7 @@ import { GuildQueue, useQueue } from 'discord-player'; import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js'; -import { - BaseSlashCommandInteraction, - BaseSlashCommandParams, - BaseSlashCommandReturnType -} from '../../../types/interactionTypes'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../classes/interactions'; import { queueDoesNotExist } from '../../../utils/validation/queueValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; diff --git a/src/interactions/commands/player/loop.ts b/src/interactions/commands/player/loop.ts index 92f32f7..ed1096a 100644 --- a/src/interactions/commands/player/loop.ts +++ b/src/interactions/commands/player/loop.ts @@ -1,10 +1,7 @@ import { GuildQueue, QueueRepeatMode, useQueue } from 'discord-player'; import { EmbedBuilder, GuildMember, SlashCommandBuilder, SlashCommandStringOption } from 'discord.js'; -import { - BaseSlashCommandInteraction, - BaseSlashCommandParams, - BaseSlashCommandReturnType -} from '../../../types/interactionTypes'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../classes/interactions'; import { queueDoesNotExist } from '../../../utils/validation/queueValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; diff --git a/src/interactions/commands/player/lyrics.ts b/src/interactions/commands/player/lyrics.ts index 0350e03..793ebb3 100644 --- a/src/interactions/commands/player/lyrics.ts +++ b/src/interactions/commands/player/lyrics.ts @@ -1,11 +1,8 @@ import { LyricsData, lyricsExtractor } from '@discord-player/extractor'; import { GuildQueue, Player, QueryType, useMainPlayer, useQueue } from 'discord-player'; import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; -import { - BaseSlashCommandInteraction, - BaseSlashCommandParams, - BaseSlashCommandReturnType -} from '../../../types/interactionTypes'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../classes/interactions'; import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; diff --git a/src/interactions/commands/player/nowplaying.ts b/src/interactions/commands/player/nowplaying.ts index cb46422..7db0007 100644 --- a/src/interactions/commands/player/nowplaying.ts +++ b/src/interactions/commands/player/nowplaying.ts @@ -11,12 +11,8 @@ import { SlashCommandBuilder } from 'discord.js'; import { PlayerOptions } from '../../../types/configTypes'; -import { - BaseSlashCommandInteraction, - BaseSlashCommandParams, - BaseSlashCommandReturnType, - TrackMetadata -} from '../../../types/interactionTypes'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType, TrackMetadata } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../classes/interactions'; import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; @@ -36,7 +32,7 @@ class NowPlayingCommand extends BaseSlashCommandInteraction { const queue: GuildQueue = useQueue(interaction.guild!.id)!; - // TODO: define TS type/interface for validators + // TODO: define TS type for validators const validators = [ () => notInVoiceChannel({ interaction, executionId }), () => notInSameVoiceChannel({ interaction, queue, executionId }), @@ -128,6 +124,13 @@ class NowPlayingCommand extends BaseSlashCommandInteraction { const loopModeUserString: string = loopModesFormatted.get(queue.repeatMode)!; + const getRepeatModeMessage = (repeatMode: number): string => { + const icon = repeatMode === 3 ? this.embedOptions.icons.autoplay : this.embedOptions.icons.loop; + return `**${icon} Looping**\nLoop mode is set to **\`${loopModeUserString}\`**. You can change it with **\`/loop\`**.\n\n`; + }; + + const repeatModeString: string = queue.repeatMode === 0 ? '' : getRepeatModeMessage(queue.repeatMode); + logger.debug('Successfully retrieved information about the current track.'); logger.debug('Sending info embed with action row components.'); @@ -145,15 +148,7 @@ class NowPlayingCommand extends BaseSlashCommandInteraction { `**[${currentTrack.title}](${currentTrack.raw.url ?? currentTrack.url})**` + `\nRequested by: <@${currentTrack.requestedBy?.id}>` + `\n ${bar}\n\n` + - `${ - queue.repeatMode === 0 - ? '' - : `**${ - queue.repeatMode === 3 - ? this.embedOptions.icons.autoplay - : this.embedOptions.icons.loop - } Looping**\nLoop mode is set to **\`${loopModeUserString}\`**. You can change it with **\`/loop\`**.` - }` + `${repeatModeString}` ) .addFields( { diff --git a/src/interactions/commands/player/pause.ts b/src/interactions/commands/player/pause.ts index 0ff6c73..fa04939 100644 --- a/src/interactions/commands/player/pause.ts +++ b/src/interactions/commands/player/pause.ts @@ -1,11 +1,8 @@ import { GuildQueue, Track, useQueue } from 'discord-player'; import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js'; -import { - BaseSlashCommandInteraction, - BaseSlashCommandParams, - BaseSlashCommandReturnType -} from '../../../types/interactionTypes'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../classes/interactions'; import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; diff --git a/src/interactions/commands/player/play.ts b/src/interactions/commands/player/play.ts index 26f69df..b2d1850 100644 --- a/src/interactions/commands/player/play.ts +++ b/src/interactions/commands/player/play.ts @@ -1,13 +1,9 @@ import config from 'config'; import { GuildQueue, useMainPlayer, useQueue } from 'discord-player'; import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js'; +import { BaseSlashCommandInteraction, CustomError } from '../../../classes/interactions'; import { PlayerOptions } from '../../../types/configTypes'; -import { - BaseSlashCommandInteraction, - BaseSlashCommandParams, - BaseSlashCommandReturnType, - CustomError -} from '../../../types/interactionTypes'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; import { cannotJoinVoiceOrTalk } from '../../../utils/validation/permissionValidator'; import { transformQuery } from '../../../utils/validation/searchQueryValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; diff --git a/src/interactions/commands/player/queue.ts b/src/interactions/commands/player/queue.ts index 95b83d7..ced622e 100644 --- a/src/interactions/commands/player/queue.ts +++ b/src/interactions/commands/player/queue.ts @@ -1,16 +1,12 @@ import config from 'config'; import { GuildQueue, PlayerTimestamp, Track, useQueue } from 'discord-player'; import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; -import { EmbedOptions, PlayerOptions } from '../../../types/configTypes'; -import { - BaseSlashCommandInteraction, - BaseSlashCommandParams, - BaseSlashCommandReturnType -} from '../../../types/interactionTypes'; +import { PlayerOptions } from '../../../types/configTypes'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../classes/interactions'; import { queueDoesNotExist } from '../../../utils/validation/queueValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; -const embedOptions: EmbedOptions = config.get('embedOptions'); const playerOptions: PlayerOptions = config.get('playerOptions'); class QueueCommand extends BaseSlashCommandInteraction { @@ -97,13 +93,12 @@ class QueueCommand extends BaseSlashCommandInteraction { const loopModeUserString: string = loopModesFormatted.get(queue.repeatMode)!; - const repeatModeString: string = `${ - queue.repeatMode === 0 - ? '' - : `**${ - queue.repeatMode === 3 ? embedOptions.icons.autoplay : embedOptions.icons.loop - } Looping**\nLoop mode is set to **\`${loopModeUserString}\`**. You can change it with **\`/loop\`**.\n\n` - }`; + const getRepeatModeMessage = (repeatMode: number): string => { + const icon = repeatMode === 3 ? this.embedOptions.icons.autoplay : this.embedOptions.icons.loop; + return `**${icon} Looping**\nLoop mode is set to **\`${loopModeUserString}\`**. You can change it with **\`/loop\`**.\n\n`; + }; + + const repeatModeString: string = queue.repeatMode === 0 ? '' : getRepeatModeMessage(queue.repeatMode); if (!currentTrack) { logger.debug('Queue exists but there is no current track.'); diff --git a/src/interactions/commands/player/remove.ts b/src/interactions/commands/player/remove.ts index b21a31c..8547853 100644 --- a/src/interactions/commands/player/remove.ts +++ b/src/interactions/commands/player/remove.ts @@ -1,10 +1,7 @@ import { GuildQueue, Track, useQueue } from 'discord-player'; import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js'; -import { - BaseSlashCommandInteraction, - BaseSlashCommandParams, - BaseSlashCommandReturnType -} from '../../../types/interactionTypes'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../classes/interactions'; import { queueDoesNotExist } from '../../../utils/validation/queueValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; diff --git a/src/interactions/commands/player/seek.ts b/src/interactions/commands/player/seek.ts index c39651b..9de0ef9 100644 --- a/src/interactions/commands/player/seek.ts +++ b/src/interactions/commands/player/seek.ts @@ -1,10 +1,7 @@ import { GuildQueue, useQueue } from 'discord-player'; import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js'; -import { - BaseSlashCommandInteraction, - BaseSlashCommandParams, - BaseSlashCommandReturnType -} from '../../../types/interactionTypes'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../classes/interactions'; import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; @@ -14,10 +11,7 @@ class SeekCommand extends BaseSlashCommandInteraction { .setName('seek') .setDescription('Seek to a duration in the current track.') .addStringOption((option) => - option - .setName('duration') - .setDescription('Duration in format 00:00:00 (HH:mm:ss).') - .setRequired(true) + option.setName('duration').setDescription('Duration in format 00:00:00 (HH:mm:ss).').setRequired(true) ); super(data); } diff --git a/src/interactions/commands/player/shuffle.ts b/src/interactions/commands/player/shuffle.ts index d870195..50c69ca 100644 --- a/src/interactions/commands/player/shuffle.ts +++ b/src/interactions/commands/player/shuffle.ts @@ -1,10 +1,7 @@ import { GuildQueue, useQueue } from 'discord-player'; import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js'; -import { - BaseSlashCommandInteraction, - BaseSlashCommandParams, - BaseSlashCommandReturnType -} from '../../../types/interactionTypes'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../classes/interactions'; import { queueDoesNotExist, queueIsEmpty } from '../../../utils/validation/queueValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; diff --git a/src/interactions/commands/player/skip.ts b/src/interactions/commands/player/skip.ts index 1bf00c3..c5c8b43 100644 --- a/src/interactions/commands/player/skip.ts +++ b/src/interactions/commands/player/skip.ts @@ -1,10 +1,7 @@ import { GuildQueue, Track, useQueue } from 'discord-player'; import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js'; -import { - BaseSlashCommandInteraction, - BaseSlashCommandParams, - BaseSlashCommandReturnType -} from '../../../types/interactionTypes'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../classes/interactions'; import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; @@ -134,6 +131,13 @@ class SkipCommand extends BaseSlashCommandInteraction { const loopModeUserString: string = loopModesFormatted.get(queue.repeatMode)!; + const getRepeatModeMessage = (repeatMode: number): string => { + const icon = repeatMode === 3 ? this.embedOptions.icons.autoplaying : this.embedOptions.icons.looping; + return `**${icon} Looping**\nLoop mode is set to **\`${loopModeUserString}\`**. You can change it with **\`/loop\`**.`; + }; + + const repeatModeString: string = queue.repeatMode === 0 ? '' : getRepeatModeMessage(queue.repeatMode); + let authorName: string; if (interaction.member instanceof GuildMember) { @@ -153,16 +157,7 @@ class SkipCommand extends BaseSlashCommandInteraction { .setDescription( `**${this.embedOptions.icons.skipped} Skipped track**\n**${durationFormat} [${ skippedTrack.title - }](${skippedTrack.raw.url ?? skippedTrack.url})**` + - `${ - queue.repeatMode === 0 - ? '' - : `\n\n**${ - queue.repeatMode === 3 - ? this.embedOptions.icons.autoplaying - : this.embedOptions.icons.looping - } Looping**\nLoop mode is set to **\`${loopModeUserString}\`**. You can change it with **\`/loop\`**.` - }` + }](${skippedTrack.raw.url ?? skippedTrack.url})**` + `\n\n${repeatModeString}` ) .setThumbnail(skippedTrack.thumbnail) .setColor(this.embedOptions.colors.success) diff --git a/src/interactions/commands/player/stop.ts b/src/interactions/commands/player/stop.ts index 620d3fd..f2c55e1 100644 --- a/src/interactions/commands/player/stop.ts +++ b/src/interactions/commands/player/stop.ts @@ -1,10 +1,7 @@ import { GuildQueue, useQueue } from 'discord-player'; import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js'; -import { - BaseSlashCommandInteraction, - BaseSlashCommandParams, - BaseSlashCommandReturnType -} from '../../../types/interactionTypes'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../classes/interactions'; import { queueDoesNotExist } from '../../../utils/validation/queueValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; diff --git a/src/interactions/commands/player/volume.ts b/src/interactions/commands/player/volume.ts index 18779e6..ea954b9 100644 --- a/src/interactions/commands/player/volume.ts +++ b/src/interactions/commands/player/volume.ts @@ -1,10 +1,7 @@ import { GuildQueue, useQueue } from 'discord-player'; import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js'; -import { - BaseSlashCommandInteraction, - BaseSlashCommandParams, - BaseSlashCommandReturnType -} from '../../../types/interactionTypes'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../classes/interactions'; import { queueDoesNotExist } from '../../../utils/validation/queueValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; diff --git a/src/interactions/commands/system/guilds.ts b/src/interactions/commands/system/guilds.ts index 0213822..02563b8 100644 --- a/src/interactions/commands/system/guilds.ts +++ b/src/interactions/commands/system/guilds.ts @@ -1,9 +1,6 @@ import { EmbedBuilder, Guild, SlashCommandBuilder } from 'discord.js'; -import { - BaseSlashCommandInteraction, - BaseSlashCommandParams, - BaseSlashCommandReturnType -} from '../../../types/interactionTypes'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../classes/interactions'; import { notValidGuildId } from '../../../utils/validation/systemCommandValidator'; class GuildsCommand extends BaseSlashCommandInteraction { diff --git a/src/interactions/commands/system/reload.ts b/src/interactions/commands/system/reload.ts index 7fd1d30..155cc23 100644 --- a/src/interactions/commands/system/reload.ts +++ b/src/interactions/commands/system/reload.ts @@ -1,10 +1,7 @@ import { ApplicationCommandOption, ApplicationCommandOptionData, EmbedBuilder, SlashCommandBuilder } from 'discord.js'; import { ExtendedClient } from '../../../types/clientTypes'; -import { - BaseSlashCommandInteraction, - BaseSlashCommandParams, - BaseSlashCommandReturnType -} from '../../../types/interactionTypes'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../classes/interactions'; import { notValidGuildId } from '../../../utils/validation/systemCommandValidator'; class ReloadCommand extends BaseSlashCommandInteraction { diff --git a/src/interactions/commands/system/shards.ts b/src/interactions/commands/system/shards.ts index d7ccdaf..72df71d 100644 --- a/src/interactions/commands/system/shards.ts +++ b/src/interactions/commands/system/shards.ts @@ -1,11 +1,7 @@ import { EmbedBuilder, EmbedField, SlashCommandBuilder } from 'discord.js'; import { ExtendedClient } from '../../../types/clientTypes'; -import { - BaseSlashCommandInteraction, - BaseSlashCommandParams, - BaseSlashCommandReturnType, - ShardInfo -} from '../../../types/interactionTypes'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType, ShardInfo } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../classes/interactions'; import { notValidGuildId } from '../../../utils/validation/systemCommandValidator'; class ShardsCommand extends BaseSlashCommandInteraction { diff --git a/src/interactions/commands/system/systemstatus.ts b/src/interactions/commands/system/systemstatus.ts index 93d238c..b5cacb5 100644 --- a/src/interactions/commands/system/systemstatus.ts +++ b/src/interactions/commands/system/systemstatus.ts @@ -2,11 +2,8 @@ import { EmbedBuilder, Guild, SlashCommandBuilder } from 'discord.js'; import osu from 'node-os-utils'; // @ts-ignore import { dependencies, version } from '../../../../package.json'; -import { - BaseSlashCommandInteraction, - BaseSlashCommandParams, - BaseSlashCommandReturnType -} from '../../../types/interactionTypes'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction } from '../../../classes/interactions'; import { getUptimeFormatted } from '../../../utils/system/getUptimeFormatted'; import { notValidGuildId } from '../../../utils/validation/systemCommandValidator'; diff --git a/src/interactions/components/filters-disable-button.ts b/src/interactions/components/filters-disable-button.ts index ca814eb..e1bad53 100644 --- a/src/interactions/components/filters-disable-button.ts +++ b/src/interactions/components/filters-disable-button.ts @@ -1,6 +1,7 @@ import { GuildQueue, useQueue } from 'discord-player'; import { EmbedBuilder, GuildMember } from 'discord.js'; -import { BaseComponentInteraction, BaseComponentParams, BaseComponentReturnType } from '../../types/interactionTypes'; +import { BaseComponentParams, BaseComponentReturnType } from '../../types/interactionTypes'; +import { BaseComponentInteraction } from '../../classes/interactions'; import { queueDoesNotExist } from '../../utils/validation/queueValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../utils/validation/voiceChannelValidator'; diff --git a/src/interactions/components/filters-select-menu.ts b/src/interactions/components/filters-select-menu.ts index e35cae7..526c084 100644 --- a/src/interactions/components/filters-select-menu.ts +++ b/src/interactions/components/filters-select-menu.ts @@ -2,7 +2,8 @@ import config from 'config'; import { GuildQueue, QueueFilters, useQueue } from 'discord-player'; import { EmbedBuilder, GuildMember, StringSelectMenuInteraction } from 'discord.js'; import { FFmpegFilterOption, FFmpegFilterOptions } from '../../types/configTypes'; -import { BaseComponentInteraction, BaseComponentParams, BaseComponentReturnType } from '../../types/interactionTypes'; +import { BaseComponentParams, BaseComponentReturnType } from '../../types/interactionTypes'; +import { BaseComponentInteraction } from '../../classes/interactions'; import { queueDoesNotExist } from '../../utils/validation/queueValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../utils/validation/voiceChannelValidator'; const ffmpegFilterOptions: FFmpegFilterOptions = config.get('ffmpegFilterOptions'); diff --git a/src/interactions/components/nowplaying-skip-button.ts b/src/interactions/components/nowplaying-skip-button.ts index e3cfec4..8c28090 100644 --- a/src/interactions/components/nowplaying-skip-button.ts +++ b/src/interactions/components/nowplaying-skip-button.ts @@ -1,6 +1,7 @@ import { GuildQueue, Track, useQueue } from 'discord-player'; import { EmbedBuilder, GuildMember } from 'discord.js'; -import { BaseComponentInteraction, BaseComponentParams, BaseComponentReturnType } from '../../types/interactionTypes'; +import { BaseComponentParams, BaseComponentReturnType } from '../../types/interactionTypes'; +import { BaseComponentInteraction } from '../../classes/interactions'; import { queueDoesNotExist, queueNoCurrentTrack } from '../../utils/validation/queueValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../utils/validation/voiceChannelValidator'; @@ -79,7 +80,14 @@ class NowplayingSkipButton extends BaseComponentInteraction { [3, 'autoplay'] ]); - const repeatModeUserString: string = loopModesFormatted.get(queue.repeatMode)!; + const loopModeUserString: string = loopModesFormatted.get(queue.repeatMode)!; + + const getRepeatModeMessage = (repeatMode: number): string => { + const icon = repeatMode === 3 ? this.embedOptions.icons.autoplaying : this.embedOptions.icons.looping; + return `**${icon} Looping**\nLoop mode is set to **\`${loopModeUserString}\`**. You can change it with **\`/loop\`**.`; + }; + + const repeatModeString: string = queue.repeatMode === 0 ? '' : getRepeatModeMessage(queue.repeatMode); let authorName: string; @@ -100,16 +108,7 @@ class NowplayingSkipButton extends BaseComponentInteraction { .setDescription( `**${this.embedOptions.icons.skipped} Skipped track**\n**${durationFormat} [${ skippedTrack.title - }](${skippedTrack.raw.url ?? skippedTrack.url})**` + - `${ - queue.repeatMode === 0 - ? '' - : `\n\n**${ - queue.repeatMode === 3 - ? this.embedOptions.icons.autoplaying - : this.embedOptions.icons.looping - } Looping**\nLoop mode is set to ${repeatModeUserString}. You can change it with **\`/loop\`**.` - }` + }](${skippedTrack.raw.url ?? skippedTrack.url})**` + `\n\n${repeatModeString}` ) .setThumbnail(skippedTrack.thumbnail) .setColor(this.embedOptions.colors.success) diff --git a/src/types/clientTypes.ts b/src/types/clientTypes.d.ts similarity index 71% rename from src/types/clientTypes.ts rename to src/types/clientTypes.d.ts index cd2a1b0..01281e0 100644 --- a/src/types/clientTypes.ts +++ b/src/types/clientTypes.d.ts @@ -1,11 +1,15 @@ import { Client, Collection } from 'discord.js'; -import { BaseAutocompleteInteraction, BaseComponentInteraction, BaseSlashCommandInteraction } from './interactionTypes'; +import { + BaseAutocompleteInteraction, + BaseComponentInteraction, + BaseSlashCommandInteraction +} from '../classes/interactions'; type RegisterClientInteractionsFunction = (params: { client: Client; executionId: string }) => void; -export interface ExtendedClient extends Client { +export type ExtendedClient = { registerClientInteractions?: RegisterClientInteractionsFunction; slashCommandInteractions?: Collection; autocompleteInteractions?: Collection; componentInteractions?: Collection; -} +} & Client; diff --git a/src/types/configTypes.ts b/src/types/configTypes.d.ts similarity index 83% rename from src/types/configTypes.ts rename to src/types/configTypes.d.ts index 483b329..6b5f6f7 100644 --- a/src/types/configTypes.ts +++ b/src/types/configTypes.d.ts @@ -1,35 +1,33 @@ -import { ActivityType, ColorResolvable, PresenceUpdateStatus, ShardingManagerOptions } from 'discord.js'; +import { ActivityType, ColorResolvable, PresenceUpdateStatus } from 'discord.js'; import { LogLevel } from './serviceTypes'; -export interface BotOptions { +export type BotOptions = { name: string; botInviteUrl: string; serverInviteUrl: string; -} +}; -export interface ShardingOptions extends ShardingManagerOptions {} - -export interface CustomLoggerOptions { +export type CustomLoggerOptions = { minimumLogLevel: LogLevel; minimumLogLevelConsole: LogLevel; discordPlayerDebug: boolean; -} +}; -export interface SystemOptions { +export type SystemOptions = { systemGuildIds: string[]; systemMessageChannelId: string; systemUserId: string; -} +}; -export interface PresenceStatusOptions { +export type PresenceStatusOptions = { status: PresenceUpdateStatus; activities: { name: string; type: ActivityType; }[]; -} +}; -export interface EmbedOptions { +export type EmbedOptions = { info: { fallbackThumbnailUrl: string; fallbackIconUrl: string; @@ -85,9 +83,9 @@ export interface EmbedOptions { sourceSpotify: string; liveTrack: string; }; -} +}; -export interface PlayerOptions { +export type PlayerOptions = { leaveOnEmpty: boolean; leaveOnEmptyCooldown: number; leaveOnEnd: boolean; @@ -107,22 +105,22 @@ export interface PlayerOptions { leftChar: string; rightChar: string; }; -} +}; -export interface FFmpegFilterOption { +export type FFmpegFilterOption = { label: string; value: string; description: string; emoji: string; -} +}; -export interface FFmpegFilterOptions { +export type FFmpegFilterOptions = { threadAmount: string; availableFilters: FFmpegFilterOption[]; -} +}; -export interface LoadTestOptions { +export type LoadTestOptions = { enabled: boolean; trackUrl: string; channelIdsToJoin: string[]; -} +}; diff --git a/src/types/eventTypes.ts b/src/types/eventTypes.d.ts similarity index 83% rename from src/types/eventTypes.ts rename to src/types/eventTypes.d.ts index ea7580c..98762d9 100644 --- a/src/types/eventTypes.ts +++ b/src/types/eventTypes.d.ts @@ -7,11 +7,11 @@ export type ClientEventArguments = unknown[]; export type ProcessEventArguments = unknown[]; export type PlayerEventArguments = unknown[]; -export interface ExtendedGuildQueuePlayerNode extends GuildQueuePlayerNode { +export type ExtendedGuildQueuePlayerNode = { metadata: | undefined | { client: ExtendedClient; channel: BaseGuildTextChannel; }; -} +} & GuildQueuePlayerNode; diff --git a/src/types/globalTypes.ts b/src/types/globalTypes.d.ts similarity index 100% rename from src/types/globalTypes.ts rename to src/types/globalTypes.d.ts diff --git a/src/types/interactionTypes.d.ts b/src/types/interactionTypes.d.ts new file mode 100644 index 0000000..d6d74ef --- /dev/null +++ b/src/types/interactionTypes.d.ts @@ -0,0 +1,50 @@ +import { + ApplicationCommandOptionChoiceData, + AutocompleteInteraction, + ChatInputCommandInteraction, + Message, + MessageComponentInteraction +} from 'discord.js'; +import { ExtendedClient } from './clientTypes'; + +export type ShardInfo = { + shardId: number; + memUsage: number; + guildCount: number; + guildMemberCount: number; + playerStatistics: { + activeVoiceConnections: number; + totalTracks: number; + totalListeners: number; + }; +}; + +export type TrackMetadata = { + bridge: { + views: number; + }; +}; + +type BaseInteractionParams = { + executionId: string; +}; + +export type BaseSlashCommandParams = { + interaction: ChatInputCommandInteraction; + client?: ExtendedClient; +} & BaseInteractionParams; + +export type BaseAutocompleteParams = { + interaction: AutocompleteInteraction; +} & BaseInteractionParams; + +export type BaseComponentParams = { + interaction: MessageComponentInteraction; + referenceId?: string; +} & BaseInteractionParams; + +export type BaseSlashCommandReturnType = Promise | void>; + +export type BaseAutocompleteReturnType = Promise; + +export type BaseComponentReturnType = Promise | void>; diff --git a/src/types/playerTypes.ts b/src/types/playerTypes.d.ts similarity index 67% rename from src/types/playerTypes.ts rename to src/types/playerTypes.d.ts index 446e646..08425e5 100644 --- a/src/types/playerTypes.ts +++ b/src/types/playerTypes.d.ts @@ -1,6 +1,6 @@ import { Client } from 'discord.js'; -export interface CreatePlayerParams { +export type CreatePlayerParams = { client: Client; executionId: string; -} +}; diff --git a/src/types/serviceTypes.ts b/src/types/serviceTypes.d.ts similarity index 100% rename from src/types/serviceTypes.ts rename to src/types/serviceTypes.d.ts diff --git a/src/types/utilTypes.ts b/src/types/utilTypes.d.ts similarity index 70% rename from src/types/utilTypes.ts rename to src/types/utilTypes.d.ts index 3ea3e2f..b43fa7c 100644 --- a/src/types/utilTypes.ts +++ b/src/types/utilTypes.d.ts @@ -3,94 +3,94 @@ import { ChatInputCommandInteraction, MessageComponentInteraction } from 'discor import { ExtendedClient } from './clientTypes'; -export interface RegisterEventListenersParams { +export type RegisterEventListenersParams = { client: ExtendedClient; player: Player; executionId: string; -} +}; -export interface RegisterClientInteractionsParams { +export type RegisterClientInteractionsParams = { client: ExtendedClient; executionId: string; -} +}; -export interface CustomEvent { +export type CustomEvent = { name: string; // eslint-disable-next-line @typescript-eslint/no-explicit-any execute: (...args: any) => void; once?: boolean; isDebug?: boolean; isPlayerEvent?: boolean; -} +}; -export interface NotInVoiceChannelParams { +export type NotInVoiceChannelParams = { interaction: ChatInputCommandInteraction | MessageComponentInteraction; executionId: string; -} +}; -export interface NotInSameVoiceChannelParams { +export type NotInSameVoiceChannelParams = { interaction: ChatInputCommandInteraction | MessageComponentInteraction; queue: GuildQueue; executionId: string; -} +}; -export interface NotValidGuildIdParams { +export type NotValidGuildIdParams = { interaction: ChatInputCommandInteraction | MessageComponentInteraction; executionId: string; -} +}; -export interface TransformQueryParams { +export type TransformQueryParams = { query: string; executionId: string; -} +}; -export interface QueueDoesNotExistParams { +export type QueueDoesNotExistParams = { interaction: ChatInputCommandInteraction | MessageComponentInteraction; queue: GuildQueue; executionId: string; -} +}; -export interface QueueNoCurrentTrackParams { +export type QueueNoCurrentTrackParams = { interaction: ChatInputCommandInteraction | MessageComponentInteraction; queue: GuildQueue; executionId: string; -} +}; -export interface QueueIsEmptyParams { +export type QueueIsEmptyParams = { interaction: ChatInputCommandInteraction | MessageComponentInteraction; queue: GuildQueue; executionId: string; -} +}; -export interface CannotJoinVoiceOrTalkParams { +export type CannotJoinVoiceOrTalkParams = { interaction: ChatInputCommandInteraction | MessageComponentInteraction; executionId: string; -} +}; -export interface CannotSendMessageInChannelParams { +export type CannotSendMessageInChannelParams = { interaction: ChatInputCommandInteraction | MessageComponentInteraction; executionId: string; -} +}; -export interface GetUptimeFormattedParams { +export type GetUptimeFormattedParams = { executionId: string; -} +}; -export interface StartLoadTestParams { +export type StartLoadTestParams = { client: ExtendedClient; executionId: string; -} +}; -export interface PostBotStatsParams { +export type PostBotStatsParams = { client: ExtendedClient; executionId: string; -} +}; -export interface PostBotStatsSite { +export type PostBotStatsSite = { enabled: boolean; hostname: string; path: string; method: string; body: object; token: string; -} +}; diff --git a/tsconfig.json b/tsconfig.json index 40ab056..512ef9c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,14 +1,14 @@ { "compilerOptions": { - "target": "ES2020", // Specify ECMAScript target version - "module": "commonjs", // Specify module code generation - "outDir": "./dist", // Output directory for compiled files - "rootDir": "./src", // Root directory of source files - "strict": true, // Enable strict type-checking options - "esModuleInterop": true, // Enables ES module interop - "skipLibCheck": true, // Skip type checking of declaration files - "forceConsistentCasingInFileNames": true // Disallow inconsistently-cased references to the same file + "target": "ES2020", + "module": "CommonJS", + "outDir": "./dist", + "rootDir": "./src", + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true }, - "include": ["src/**/*.ts", "src/types/**/*.ts"], // Source files to be compiled - "exclude": ["node_modules"] // Exclude node_modules from compilation + "include": ["src/**/*.ts"], + "exclude": ["node_modules"] }