fix: more type annotation

This commit is contained in:
Marius Begby committed 2023-08-30 14:12:55 +02:00
1 parent 3ac692d8eb
commit 2560f0fe9a
65 files changed
+408 -343

No files matched your search

+8 -6
View File
@@ -2,7 +2,9 @@ import config from 'config';
import { GuildQueue, QueueFilters, useQueue } from 'discord-player';
import {
APIActionRowComponent,
APIButtonComponent,
APIMessageActionRowComponent,
APIStringSelectComponent,
ButtonBuilder,
ButtonStyle,
ComponentType,
@@ -11,10 +13,10 @@ import {
StringSelectMenuBuilder,
StringSelectMenuOptionBuilder
} from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { EmbedOptions, FFmpegFilterOption, FFmpegFilterOptions } from '../../../types/configTypes';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
@@ -30,7 +32,7 @@ const command: CustomSlashCommandInteraction = {
.setDMPermission(false)
.setNSFW(false),
execute: async ({ interaction, executionId }) => {
const logger = loggerModule.child({
const logger: Logger = loggerModule.child({
source: 'filters.js',
module: 'slashCommand',
name: '/filters',
@@ -57,7 +59,7 @@ const command: CustomSlashCommandInteraction = {
const filterOptions: StringSelectMenuOptionBuilder[] = [];
ffmpegFilterOptions.availableFilters.forEach((filter: FFmpegFilterOption) => {
let isEnabled = false;
let isEnabled: boolean = false;
if (queue.filters.ffmpeg.filters.includes(filter.value as keyof QueueFilters)) {
isEnabled = true;
@@ -73,7 +75,7 @@ const command: CustomSlashCommandInteraction = {
);
});
const filterSelect = new StringSelectMenuBuilder()
const filterSelect: APIStringSelectComponent = new StringSelectMenuBuilder()
.setCustomId('filters-select-menu')
.setPlaceholder('Select multiple options.')
.setMinValues(0)
@@ -86,7 +88,7 @@ const command: CustomSlashCommandInteraction = {
components: [filterSelect]
};
const disableButton = new ButtonBuilder()
const disableButton: APIButtonComponent = new ButtonBuilder()
.setCustomId('filters-disable-button')
.setLabel('Disable all filters')
.setStyle(ButtonStyle.Secondary)
+4 -4
View File
@@ -1,12 +1,12 @@
import config from 'config';
import { GuildQueue, useQueue } from 'discord-player';
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { EmbedOptions } from '../../../types/configTypes';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { queueDoesNotExist } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
const embedOptions: EmbedOptions = config.get('embedOptions');
@@ -19,7 +19,7 @@ const command: CustomSlashCommandInteraction = {
.setDMPermission(false)
.setNSFW(false),
execute: async ({ interaction, executionId }) => {
const logger = loggerModule.child({
const logger: Logger = loggerModule.child({
source: 'leave.js',
module: 'slashCommand',
name: '/leave',
+10 -9
View File
@@ -1,10 +1,10 @@
import config from 'config';
import { GuildQueue, useQueue } from 'discord-player';
import { GuildQueue, QueueRepeatMode, useQueue } from 'discord-player';
import { EmbedBuilder, GuildMember, SlashCommandBuilder, SlashCommandStringOption } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { BotOptions, EmbedOptions } from '../../../types/configTypes';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { queueDoesNotExist } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
@@ -32,7 +32,7 @@ const command: CustomSlashCommandInteraction = {
)
),
execute: async ({ interaction, executionId }) => {
const logger = loggerModule.child({
const logger: Logger = loggerModule.child({
source: 'loop.js',
module: 'slashCommand',
name: '/loop',
@@ -55,17 +55,18 @@ const command: CustomSlashCommandInteraction = {
}
}
const loopModesFormatted = new Map([
// TODO: create type for loop modes formatted
const loopModesFormatted: Map<number, string> = new Map([
[0, 'disabled'],
[1, 'track'],
[2, 'queue'],
[3, 'autoplay']
]);
const mode = parseInt(interaction.options.getString('mode')!);
const modeUserString = loopModesFormatted.get(mode);
const currentMode = queue.repeatMode;
const currentModeUserString = loopModesFormatted.get(currentMode);
const mode: number = parseInt(interaction.options.getString('mode')!);
const modeUserString: string = loopModesFormatted.get(mode)!;
const currentMode: QueueRepeatMode = queue.repeatMode;
const currentModeUserString: string = loopModesFormatted.get(currentMode)!;
if (!mode && mode !== 0) {
logger.debug('No mode input was provided, responding with current loop mode.');
+12 -11
View File
@@ -1,18 +1,19 @@
import config from 'config';
import { GuildQueue, QueryType, useMainPlayer, useQueue } from 'discord-player';
import { GuildQueue, Player, QueryType, useMainPlayer, useQueue } from 'discord-player';
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import { lyricsExtractor } from '@discord-player/extractor';
import { LyricsData, lyricsExtractor } from '@discord-player/extractor';
import loggerModule from '../../../services/logger';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { EmbedOptions } from '../../../types/configTypes';
import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { Logger } from 'pino';
const embedOptions: EmbedOptions = config.get('embedOptions');
const loggerTemplate = loggerModule.child({
const loggerTemplate: Logger = loggerModule.child({
source: 'lyrics.js',
module: 'slashCommand',
name: '/lyrics'
@@ -36,15 +37,15 @@ const command: CustomSlashCommandInteraction = {
.setAutocomplete(true)
),
execute: async ({ interaction, executionId }) => {
const logger = loggerTemplate.child({
const logger: Logger = loggerTemplate.child({
executionId: executionId,
shardId: interaction.guild?.shardId,
guildId: interaction.guild?.id
});
const query = interaction.options.getString('query');
const query: string = interaction.options.getString('query')!;
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
let geniusSearchQuery = '';
let geniusSearchQuery: string = '';
if (!query) {
const validators = [
@@ -70,7 +71,7 @@ const command: CustomSlashCommandInteraction = {
let searchResult;
if (query) {
logger.debug(`Query input provided, using query '${query}' for player.search().`);
const player = useMainPlayer()!;
const player: Player = useMainPlayer()!;
const searchResults = await player.search(query, {
searchEngine: QueryType.SPOTIFY_SEARCH
});
@@ -97,7 +98,7 @@ const command: CustomSlashCommandInteraction = {
// get lyrics
const genius = lyricsExtractor();
let lyricsResult = await genius.search(geniusSearchQuery).catch(() => null);
let lyricsResult: LyricsData | null = await genius.search(geniusSearchQuery).catch(() => null);
// try again with shorter query (some titles just have added info in the end)
if (!lyricsResult && geniusSearchQuery.length > 20) {
@@ -155,10 +156,10 @@ const command: CustomSlashCommandInteraction = {
// If message length is too long, split into multiple messages
if (lyricsResult.lyrics.length > 3800) {
logger.debug('Lyrics text too long, splitting into multiple messages.');
const messageCount = Math.ceil(lyricsResult.lyrics.length / 3800);
for (let i = 0; i < messageCount; i++) {
const messageCount: number = Math.ceil(lyricsResult.lyrics.length / 3800);
for (let i: number = 0; i < messageCount; i++) {
logger.debug(`Lyrics, sending message ${i + 1} of ${messageCount}.`);
const message = lyricsResult.lyrics.slice(i * 3800, (i + 1) * 3800);
const message: string = lyricsResult.lyrics.slice(i * 3800, (i + 1) * 3800);
if (i === 0) {
logger.debug('Responding with info embed for first message with lyrics.');
await interaction.editReply({
+18 -15
View File
@@ -1,7 +1,8 @@
import config from 'config';
import { GuildQueue, Track, useQueue } from 'discord-player';
import { GuildQueue, PlayerTimestamp, Track, useQueue } from 'discord-player';
import {
APIActionRowComponent,
APIButtonComponent,
APIMessageActionRowComponent,
ButtonBuilder,
ButtonStyle,
@@ -15,6 +16,7 @@ import { CustomSlashCommandInteraction, TrackMetadata } from '../../../types/int
import { EmbedOptions, PlayerOptions } from '../../../types/configTypes';
import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { Logger } from 'pino';
const embedOptions: EmbedOptions = config.get('embedOptions');
const playerOptions: PlayerOptions = config.get('playerOptions');
@@ -28,7 +30,7 @@ const command: CustomSlashCommandInteraction = {
.setDMPermission(false)
.setNSFW(false),
execute: async ({ interaction, executionId }) => {
const logger = loggerModule.child({
const logger: Logger = loggerModule.child({
source: 'nowplaying.js',
module: 'slashCommand',
name: '/nowplaying',
@@ -39,6 +41,7 @@ const command: CustomSlashCommandInteraction = {
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
// TODO: define TS type/interface for validators
const validators = [
() => notInVoiceChannel({ interaction, executionId }),
() => notInSameVoiceChannel({ interaction, queue, executionId }),
@@ -52,7 +55,7 @@ const command: CustomSlashCommandInteraction = {
}
}
const sourceStringsFormatted = new Map([
const sourceStringsFormatted: Map<string, string> = new Map([
['youtube', 'YouTube'],
['soundcloud', 'SoundCloud'],
['spotify', 'Spotify'],
@@ -60,7 +63,7 @@ const command: CustomSlashCommandInteraction = {
['arbitrary', 'Direct source']
]);
const sourceIcons = new Map([
const sourceIcons: Map<string, string> = new Map([
['youtube', embedOptions.icons.sourceYouTube],
['soundcloud', embedOptions.icons.sourceSoundCloud],
['spotify', embedOptions.icons.sourceSpotify],
@@ -70,15 +73,15 @@ const command: CustomSlashCommandInteraction = {
const currentTrack: Track = queue.currentTrack!;
let author = currentTrack.author ? currentTrack.author : 'Unavailable';
let author: string = currentTrack.author ? currentTrack.author : 'Unavailable';
if (author === 'cdn.discordapp.com') {
author = 'Unavailable';
}
const plays = currentTrack.views !== 0 ? currentTrack.views : 0;
const plays: number = currentTrack.views !== 0 ? currentTrack.views : 0;
let displayPlays: string = plays.toLocaleString('en-US');
const metadata = currentTrack.metadata as TrackMetadata;
const metadata: TrackMetadata = currentTrack.metadata as TrackMetadata;
if (plays === 0 && metadata.bridge && metadata.bridge.views !== 0 && metadata.bridge.views !== undefined) {
displayPlays = metadata.bridge.views.toLocaleString('en-US');
@@ -86,10 +89,10 @@ const command: CustomSlashCommandInteraction = {
displayPlays = 'Unavailable';
}
const source = sourceStringsFormatted.get(currentTrack.raw.source!) ?? 'Unavailable';
const queueLength = queue.tracks.data.length;
const timestamp = queue.node.getTimestamp()!;
let bar = `**\`${timestamp.current.label}\`** ${queue.node.createProgressBar({
const source: string = sourceStringsFormatted.get(currentTrack.raw.source!) ?? 'Unavailable';
const queueLength: number = queue.tracks.data.length;
const timestamp: PlayerTimestamp = queue.node.getTimestamp()!;
let bar: string = `**\`${timestamp.current.label}\`** ${queue.node.createProgressBar({
queue: false,
length: playerOptions.progressBar.length ?? 12,
timecodes: playerOptions.progressBar.timecodes ?? false,
@@ -106,10 +109,10 @@ const command: CustomSlashCommandInteraction = {
bar = `${embedOptions.icons.liveTrack} **\`LIVE\`** - Playing continuously from live source.`;
}
const customId = `nowplaying-skip-button_${currentTrack.id}`;
const customId: string = `nowplaying-skip-button_${currentTrack.id}`;
logger.debug(`Generated custom id for skip button: ${customId}`);
const nowPlayingButton = new ButtonBuilder()
const nowPlayingButton: APIButtonComponent = new ButtonBuilder()
.setCustomId(customId)
.setLabel('Skip track')
.setStyle(ButtonStyle.Secondary)
@@ -121,14 +124,14 @@ const command: CustomSlashCommandInteraction = {
components: [nowPlayingButton]
};
const loopModesFormatted = new Map([
const loopModesFormatted: Map<number, string> = new Map([
[0, 'disabled'],
[1, 'track'],
[2, 'queue'],
[3, 'autoplay']
]);
const loopModeUserString = loopModesFormatted.get(queue.repeatMode);
const loopModeUserString: string = loopModesFormatted.get(queue.repeatMode)!;
logger.debug('Successfully retrieved information about the current track.');
+5 -5
View File
@@ -1,10 +1,10 @@
import config from 'config';
import { GuildQueue, useQueue } from 'discord-player';
import { GuildQueue, Track, useQueue } from 'discord-player';
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { EmbedOptions } from '../../../types/configTypes';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
@@ -19,7 +19,7 @@ const command: CustomSlashCommandInteraction = {
.setDMPermission(false)
.setNSFW(false),
execute: async ({ interaction, executionId }) => {
const logger = loggerModule.child({
const logger: Logger = loggerModule.child({
source: 'pause.js',
module: 'slashCommand',
name: '/pause',
@@ -43,7 +43,7 @@ const command: CustomSlashCommandInteraction = {
}
}
const currentTrack = queue.currentTrack!;
const currentTrack: Track = queue.currentTrack!;
let durationFormat =
Number(currentTrack.raw.duration) === 0 || currentTrack.duration === '0:00'
+2 -1
View File
@@ -8,12 +8,13 @@ import { BotOptions, EmbedOptions, PlayerOptions } from '../../../types/configTy
import { cannotJoinVoiceOrTalk } from '../../../utils/validation/permissionValidator';
import { transformQuery } from '../../../utils/validation/searchQueryValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { Logger } from 'pino';
const embedOptions: EmbedOptions = config.get('embedOptions');
const botOptions: BotOptions = config.get('botOptions');
const playerOptions: PlayerOptions = config.get('playerOptions');
const loggerTemplate = loggerModule.child({
const loggerTemplate: Logger = loggerModule.child({
source: 'play.js',
module: 'slashCommand',
name: '/play'
+15 -15
View File
@@ -1,12 +1,12 @@
import config from 'config';
import { GuildQueue, useQueue } from 'discord-player';
import { GuildQueue, PlayerTimestamp, Track, useQueue } from 'discord-player';
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { EmbedOptions, PlayerOptions } from '../../../types/configTypes';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
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');
@@ -21,7 +21,7 @@ const command: CustomSlashCommandInteraction = {
.setNSFW(false)
.addNumberOption((option) => option.setName('page').setDescription('Page number of the queue').setMinValue(1)),
execute: async ({ interaction, executionId }) => {
const logger = loggerModule.child({
const logger: Logger = loggerModule.child({
source: 'queue.js',
module: 'slashCommand',
name: '/queue',
@@ -44,11 +44,11 @@ const command: CustomSlashCommandInteraction = {
}
}
const pageIndex = (interaction.options.getNumber('page') || 1) - 1;
let queueString = '';
const pageIndex: number = (interaction.options.getNumber('page') || 1) - 1;
let queueString: string = '';
const queueLength = queue.tracks.data.length;
const totalPages = Math.ceil(queueLength / 10) || 1;
const queueLength: number = queue.tracks.data.length;
const totalPages: number = Math.ceil(queueLength / 10) || 1;
if (pageIndex > totalPages - 1) {
logger.debug('Specified page was higher than total pages.');
@@ -88,7 +88,7 @@ const command: CustomSlashCommandInteraction = {
.join('\n');
}
const currentTrack = queue.currentTrack;
const currentTrack: Track = queue.currentTrack!;
const loopModesFormatted = new Map([
[0, 'disabled'],
@@ -97,9 +97,9 @@ const command: CustomSlashCommandInteraction = {
[3, 'autoplay']
]);
const loopModeUserString = loopModesFormatted.get(queue.repeatMode);
const loopModeUserString: string = loopModesFormatted.get(queue.repeatMode)!;
const repeatModeString = `${
const repeatModeString: string = `${
queue.repeatMode === 0
? ''
: `**${
@@ -129,8 +129,8 @@ const command: CustomSlashCommandInteraction = {
});
} else {
logger.debug('Queue exists with current track, gathering information.');
const timestamp = queue.node.getTimestamp()!;
let bar = `**\`${timestamp.current.label}\`** ${queue.node.createProgressBar({
const timestamp: PlayerTimestamp = queue.node.getTimestamp()!;
let bar: string = `**\`${timestamp.current.label}\`** ${queue.node.createProgressBar({
queue: false,
length: playerOptions.progressBar.length ?? 12,
timecodes: playerOptions.progressBar.timecodes ?? false,
@@ -165,7 +165,7 @@ const command: CustomSlashCommandInteraction = {
`${repeatModeString}` +
`**${embedOptions.icons.queue} Tracks in queue**\n${queueString}`
)
.setThumbnail(queue.currentTrack.thumbnail)
.setThumbnail(currentTrack.thumbnail)
.setFooter({
text: `Page ${pageIndex + 1} of ${totalPages} (${queueLength} tracks)`
})
+6 -6
View File
@@ -1,10 +1,10 @@
import config from 'config';
import { GuildQueue, useQueue } from 'discord-player';
import { GuildQueue, Track, useQueue } from 'discord-player';
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { EmbedOptions } from '../../../types/configTypes';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { queueDoesNotExist } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
@@ -26,7 +26,7 @@ const command: CustomSlashCommandInteraction = {
.setRequired(true)
),
execute: async ({ interaction, executionId }) => {
const logger = loggerModule.child({
const logger: Logger = loggerModule.child({
source: 'remove.js',
module: 'slashCommand',
name: '/remove',
@@ -49,7 +49,7 @@ const command: CustomSlashCommandInteraction = {
}
}
const removeTrackNumber = interaction.options.getNumber('tracknumber')!;
const removeTrackNumber: number = interaction.options.getNumber('tracknumber')!;
if (removeTrackNumber > queue.tracks.data.length) {
logger.debug('Specified track number is higher than total tracks.');
@@ -67,7 +67,7 @@ const command: CustomSlashCommandInteraction = {
}
// Remove specified track number from queue
const removedTrack = queue.node.remove(removeTrackNumber - 1)!;
const removedTrack: Track = queue.node.remove(removeTrackNumber - 1)!;
logger.debug(`Removed track '${removedTrack.url}' from queue.`);
let durationFormat =
Number(removedTrack.raw.duration) === 0 || removedTrack.duration === '0:00'
+10 -10
View File
@@ -1,10 +1,10 @@
import config from 'config';
import { GuildQueue, useQueue } from 'discord-player';
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { EmbedOptions } from '../../../types/configTypes';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
@@ -25,7 +25,7 @@ const command: CustomSlashCommandInteraction = {
.setRequired(true)
),
execute: async ({ interaction, executionId }) => {
const logger = loggerModule.child({
const logger: Logger = loggerModule.child({
source: 'seek.js',
module: 'slashCommand',
name: '/seek',
@@ -49,9 +49,9 @@ const command: CustomSlashCommandInteraction = {
}
}
const durationInput = interaction.options.getString('duration');
const durationInput: string = interaction.options.getString('duration')!;
let durationArray = durationInput!.split(':');
let durationArray: string[] = durationInput!.split(':');
switch (durationArray.length) {
case 1:
@@ -68,7 +68,7 @@ const command: CustomSlashCommandInteraction = {
return value.padStart(2, '0');
});
const durationString = durationArray.join(':');
const durationString: string = durationArray.join(':');
if (durationArray.length === 0 || durationArray.length > 3) {
logger.debug('Invalid duration format input.');
@@ -88,7 +88,7 @@ const command: CustomSlashCommandInteraction = {
});
}
const validElements = durationArray.every((value) => {
const validElements: boolean = durationArray.every((value) => {
return value.length === 2;
});
@@ -112,8 +112,8 @@ const command: CustomSlashCommandInteraction = {
// Now array should only be 3 elements long, all with 2 characters, e.g. ['00', '00', '00'].
// Regex can now validate if this is a valid duration format. E.g. check if the first element is 0-23, second element is 0-59 and third element is 0-59.
const regex = new RegExp('([0-1][0-9]|2[0-3]):?[0-5][0-9]:?[0-5][0-9]');
const isValidDuration = regex.test(durationString);
const regex: RegExp = new RegExp('([0-1][0-9]|2[0-3]):?[0-5][0-9]:?[0-5][0-9]');
const isValidDuration: boolean = regex.test(durationString);
if (!isValidDuration) {
logger.debug('Invalid duration after regex checks.');
@@ -133,7 +133,7 @@ const command: CustomSlashCommandInteraction = {
});
}
const currentTrackMaxDurationInMs = queue.currentTrack!.durationMS;
const currentTrackMaxDurationInMs: number = queue.currentTrack!.durationMS;
const durationInMilliseconds: number =
Number(durationArray[0]) * 3600000 + Number(durationArray[1]) * 60000 + Number(durationArray[2]) * 1000;
+3 -3
View File
@@ -1,10 +1,10 @@
import config from 'config';
import { GuildQueue, useQueue } from 'discord-player';
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { EmbedOptions } from '../../../types/configTypes';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { queueDoesNotExist, queueIsEmpty } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
@@ -19,7 +19,7 @@ const command: CustomSlashCommandInteraction = {
.setDMPermission(false)
.setNSFW(false),
execute: async ({ interaction, executionId }) => {
const logger = loggerModule.child({
const logger: Logger = loggerModule.child({
source: 'shuffle.js',
module: 'slashCommand',
name: '/shuffle',
+9 -9
View File
@@ -1,10 +1,10 @@
import config from 'config';
import { GuildQueue, useQueue } from 'discord-player';
import { GuildQueue, Track, useQueue } from 'discord-player';
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { EmbedOptions } from '../../../types/configTypes';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
@@ -22,7 +22,7 @@ const command: CustomSlashCommandInteraction = {
option.setName('tracknumber').setDescription('Track number to skip to in the queue.').setMinValue(1)
),
execute: async ({ interaction, executionId }) => {
const logger = loggerModule.child({
const logger: Logger = loggerModule.child({
source: 'skip.js',
module: 'slashCommand',
name: '/skip',
@@ -46,7 +46,7 @@ const command: CustomSlashCommandInteraction = {
}
}
const skipToTrack = interaction.options.getNumber('tracknumber');
const skipToTrack: number = interaction.options.getNumber('tracknumber')!;
if (skipToTrack) {
if (skipToTrack > queue.tracks.data.length) {
@@ -63,7 +63,7 @@ const command: CustomSlashCommandInteraction = {
]
});
} else {
const skippedTrack = queue.currentTrack!;
const skippedTrack: Track = queue.currentTrack!;
logger.debug('Responding with warning embed.');
let durationFormat =
@@ -120,7 +120,7 @@ const command: CustomSlashCommandInteraction = {
});
}
const skippedTrack = queue.currentTrack!;
const skippedTrack: Track = queue.currentTrack!;
let durationFormat =
Number(skippedTrack.raw.duration) === 0 || skippedTrack.duration === '0:00'
@@ -133,14 +133,14 @@ const command: CustomSlashCommandInteraction = {
queue.node.skip();
logger.debug('Skipped current track.');
const loopModesFormatted = new Map([
const loopModesFormatted: Map<number, string> = new Map([
[0, 'disabled'],
[1, 'track'],
[2, 'queue'],
[3, 'autoplay']
]);
const loopModeUserString = loopModesFormatted.get(queue.repeatMode);
const loopModeUserString: string = loopModesFormatted.get(queue.repeatMode)!;
let authorName: string;
+4 -4
View File
@@ -1,12 +1,12 @@
import config from 'config';
import { GuildQueue, useQueue } from 'discord-player';
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { EmbedOptions } from '../../../types/configTypes';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { queueDoesNotExist } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
const embedOptions: EmbedOptions = config.get('embedOptions');
@@ -19,7 +19,7 @@ const command: CustomSlashCommandInteraction = {
.setDMPermission(false)
.setNSFW(false),
execute: async ({ interaction, executionId }) => {
const logger = loggerModule.child({
const logger: Logger = loggerModule.child({
source: 'stop.js',
module: 'slashCommand',
name: '/stop',
+5 -5
View File
@@ -1,10 +1,10 @@
import config from 'config';
import { GuildQueue, useQueue } from 'discord-player';
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { EmbedOptions } from '../../../types/configTypes';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { queueDoesNotExist } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
@@ -26,7 +26,7 @@ const command: CustomSlashCommandInteraction = {
.setMaxValue(100)
),
execute: async ({ interaction, executionId }) => {
const logger = loggerModule.child({
const logger: Logger = loggerModule.child({
source: 'volume.js',
module: 'slashCommand',
name: '/volume',
@@ -49,10 +49,10 @@ const command: CustomSlashCommandInteraction = {
}
}
const volume = interaction.options.getNumber('percentage');
const volume: number = interaction.options.getNumber('percentage')!;
if (!volume && volume !== 0) {
const currentVolume = queue.node.volume;
const currentVolume: number = queue.node.volume;
logger.debug('No volume input was provided, showing current volume.');