fix: separated types and classes

This commit is contained in:
Marius Begby committed 2023-09-03 02:19:28 +02:00
1 parent 6dcddee2e9
commit ea32ae6c61
42 files changed
+234 -296

No files matched your search

@@ -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<Message<boolean> | void>;
export type BaseAutocompleteReturnType = Promise<ApplicationCommandOptionChoiceData | void>;
export type BaseComponentReturnType = Promise<Message<boolean> | 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;
}
+1 -1
View File
@@ -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,
+1
View File
@@ -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()
@@ -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,
+1 -1
View File
@@ -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 (
+1 -1
View File
@@ -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 (
+1 -1
View File
@@ -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');
+2 -3
View File
@@ -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,
+4 -7
View File
@@ -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<string>[] = [];
if (!lyricsResult) {
+3 -6
View File
@@ -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 {
+3 -8
View File
@@ -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);
}
+2 -5
View File
@@ -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 {
+3 -8
View File
@@ -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);
}
+2 -5
View File
@@ -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';
+2 -5
View File
@@ -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';
+2 -5
View File
@@ -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';
+11 -16
View File
@@ -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(
{
+2 -5
View File
@@ -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';
+2 -6
View File
@@ -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';
+9 -14
View File
@@ -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.');
+2 -5
View File
@@ -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';
+3 -9
View File
@@ -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);
}
+2 -5
View File
@@ -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';
+10 -15
View File
@@ -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)
+2 -5
View File
@@ -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';
+2 -5
View File
@@ -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';
+2 -5
View File
@@ -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 {
+2 -5
View File
@@ -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 {
+2 -6
View File
@@ -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 {
@@ -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';
@@ -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';
@@ -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');
@@ -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)
+7 -3
View File
@@ -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<string, BaseSlashCommandInteraction>;
autocompleteInteractions?: Collection<string, BaseAutocompleteInteraction>;
componentInteractions?: Collection<string, BaseComponentInteraction>;
}
} & Client;
+19 -21
View File
@@ -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[];
}
};
+2 -2
View File
@@ -7,11 +7,11 @@ export type ClientEventArguments = unknown[];
export type ProcessEventArguments = unknown[];
export type PlayerEventArguments = unknown[];
export interface ExtendedGuildQueuePlayerNode extends GuildQueuePlayerNode<unknown> {
export type ExtendedGuildQueuePlayerNode = {
metadata:
| undefined
| {
client: ExtendedClient;
channel: BaseGuildTextChannel;
};
}
} & GuildQueuePlayerNode<unknown>;
File renamed without changes.
+50
View File
@@ -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<Message<boolean> | void>;
export type BaseAutocompleteReturnType = Promise<ApplicationCommandOptionChoiceData | void>;
export type BaseComponentReturnType = Promise<Message<boolean> | void>;
+2 -2
View File
@@ -1,6 +1,6 @@
import { Client } from 'discord.js';
export interface CreatePlayerParams {
export type CreatePlayerParams = {
client: Client;
executionId: string;
}
};
File renamed without changes.
+32 -32
View File
@@ -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;
}
};
+10 -10
View File
@@ -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"]
}