fix: annotations for events

This commit is contained in:
Marius Begby committed 2023-08-27 02:46:50 +02:00
1 parent 39e818283d
commit b118ebdfb0
26 files changed
+170 -112

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
import config from 'config'; import config from 'config';
import { EmbedOptions } from '../../types/configTypes'; import { EmbedOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions'); const embedOptions: EmbedOptions = config.get('embedOptions');
const botOptions = config.get('botOptions'); const botOptions: BotOptions = config.get('botOptions');
import { SlashCommandBuilder, EmbedBuilder } from 'discord.js'; import { SlashCommandBuilder, EmbedBuilder } from 'discord.js';
import loggerModule from '../../services/logger'; import loggerModule from '../../services/logger';
+1 -1
View File
@@ -1,7 +1,7 @@
import config from 'config'; import config from 'config';
import { EmbedOptions } from '../../types/configTypes'; import { EmbedOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions'); const embedOptions: EmbedOptions = config.get('embedOptions');
const ffmpegFilterOptions = config.get('ffmpegFilterOptions'); const ffmpegFilterOptions: FFmpegFilterOptions = config.get('ffmpegFilterOptions');
import { notInVoiceChannel, notInSameVoiceChannel } from '../../utils/validation/voiceChannelValidator'; import { notInVoiceChannel, notInSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { queueDoesNotExist, queueNoCurrentTrack } from '../../utils/validation/queueValidator'; import { queueDoesNotExist, queueNoCurrentTrack } from '../../utils/validation/queueValidator';
import { import {
+1 -1
View File
@@ -1,7 +1,7 @@
import config from 'config'; import config from 'config';
import { EmbedOptions } from '../../types/configTypes'; import { EmbedOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions'); const embedOptions: EmbedOptions = config.get('embedOptions');
const botOptions = config.get('botOptions'); const botOptions: BotOptions = config.get('botOptions');
import { notInVoiceChannel, notInSameVoiceChannel } from '../../utils/validation/voiceChannelValidator'; import { notInVoiceChannel, notInSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { queueDoesNotExist } from '../../utils/validation/queueValidator'; import { queueDoesNotExist } from '../../utils/validation/queueValidator';
import{ SlashCommandBuilder, EmbedBuilder } from 'discord.js'; import{ SlashCommandBuilder, EmbedBuilder } from 'discord.js';
+1 -1
View File
@@ -1,7 +1,7 @@
import config from 'config'; import config from 'config';
import { EmbedOptions } from '../../types/configTypes'; import { EmbedOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions'); const embedOptions: EmbedOptions = config.get('embedOptions');
const playerOptions = config.get('playerOptions'); const playerOptions: PlayerOptions = config.get('playerOptions');
import { notInVoiceChannel, notInSameVoiceChannel } from '../../utils/validation/voiceChannelValidator'; import { notInVoiceChannel, notInSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { queueDoesNotExist, queueNoCurrentTrack } from '../../utils/validation/queueValidator'; import { queueDoesNotExist, queueNoCurrentTrack } from '../../utils/validation/queueValidator';
import { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder } from 'discord.js'; import { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder } from 'discord.js';
+2 -2
View File
@@ -1,7 +1,7 @@
import config from 'config'; import config from 'config';
const embedOptions: EmbedOptions = config.get('embedOptions'); const embedOptions: EmbedOptions = config.get('embedOptions');
const botOptions = config.get('botOptions'); const botOptions: BotOptions = config.get('botOptions');
const playerOptions = config.get('playerOptions'); const playerOptions: PlayerOptions = config.get('playerOptions');
import { notInVoiceChannel, notInSameVoiceChannel } from '../../utils/validation/voiceChannelValidator'; import { notInVoiceChannel, notInSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { cannotJoinVoiceOrTalk } from '../../utils/validation/permissionValidator'; import { cannotJoinVoiceOrTalk } from '../../utils/validation/permissionValidator';
import { transformQuery } from '../../utils/validation/searchQueryValidator'; import { transformQuery } from '../../utils/validation/searchQueryValidator';
+1 -1
View File
@@ -1,7 +1,7 @@
import config from 'config'; import config from 'config';
import { EmbedOptions } from '../../types/configTypes'; import { EmbedOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions'); const embedOptions: EmbedOptions = config.get('embedOptions');
const playerOptions = config.get('playerOptions'); const playerOptions: PlayerOptions = config.get('playerOptions');
import { notInVoiceChannel, notInSameVoiceChannel } from '../../utils/validation/voiceChannelValidator'; import { notInVoiceChannel, notInSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import{ SlashCommandBuilder, EmbedBuilder } from 'discord.js'; import{ SlashCommandBuilder, EmbedBuilder } from 'discord.js';
import { useQueue } from 'discord-player'; import { useQueue } from 'discord-player';
+1 -1
View File
@@ -6,7 +6,7 @@ module.exports = {
name: Events.Debug, name: Events.Debug,
isDebug: true, isDebug: true,
once: false, once: false,
execute: async (message) => { execute: async (message: string) => {
const executionId = uuidv4(); const executionId = uuidv4();
const logger = loggerModule.child({ const logger = loggerModule.child({
source: 'debug.js', source: 'debug.js',
+11 -8
View File
@@ -1,36 +1,39 @@
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import config from 'config'; import config from 'config';
import { EmbedOptions } from '../../types/configTypes'; import { EmbedOptions, SystemOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions'); const embedOptions: EmbedOptions = config.get('embedOptions');
const systemOptions = config.get('systemOptions'); const systemOptions: SystemOptions = config.get('systemOptions');
import { EmbedBuilder } from 'discord.js'; import { BaseGuildTextChannel, EmbedBuilder } from 'discord.js';
import loggerModule from '../../services/logger'; import loggerModule from '../../services/logger';
import { ExtendedClient } from '../../types/clientTypes';
module.exports = { module.exports = {
name: 'disconnect', name: 'disconnect',
isDebug: false, isDebug: false,
once: false, once: false,
execute: async (client) => { execute: async (client: ExtendedClient) => {
const executionId = uuidv4(); const executionId = uuidv4();
const logger = loggerModule.child({ const logger = loggerModule.child({
source: 'disconnect.js', source: 'disconnect.js',
module: 'event', module: 'event',
name: 'clientDisconnect', name: 'clientDisconnect',
executionId: executionId, executionId: executionId,
shardId: client.shard.ids[0] shardId: client.shard?.ids[0]
}); });
logger.warn(`${client.user.tag} lost connection to Discord APIs. Disconnected.`); logger.warn(`${client.user?.tag} lost connection to Discord APIs. Disconnected.`);
// send message to system message channel for event // send message to system message channel for event
if (systemOptions.systemMessageChannelId && systemOptions.systemUserId) { if (systemOptions.systemMessageChannelId && systemOptions.systemUserId) {
const channel = await client.channels.cache.get(systemOptions.systemMessageChannelId); const channel = (await client.channels.cache.get(
systemOptions.systemMessageChannelId
)) as BaseGuildTextChannel;
if (channel) { if (channel) {
await channel.send({ await channel.send({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
.setDescription( .setDescription(
`${embedOptions.icons.warning} **${client.user.tag}** is **\`disconnected\`**!` + `${embedOptions.icons.warning} **${client.user?.tag}** is **\`disconnected\`**!` +
`\n\n<@${systemOptions.systemUserId}>` `\n\n<@${systemOptions.systemUserId}>`
) )
.setColor(embedOptions.colors.warning) .setColor(embedOptions.colors.warning)
+1 -1
View File
@@ -6,7 +6,7 @@ module.exports = {
name: Events.Error, name: Events.Error,
isDebug: false, isDebug: false,
once: false, once: false,
execute: async (error) => { execute: async (error: Error) => {
const executionId = uuidv4(); const executionId = uuidv4();
const logger = loggerModule.child({ const logger = loggerModule.child({
source: 'error.js', source: 'error.js',
+2 -2
View File
@@ -1,4 +1,4 @@
import { Events } from 'discord.js'; import { Events, Guild } from 'discord.js';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import loggerModule from '../../services/logger'; import loggerModule from '../../services/logger';
@@ -6,7 +6,7 @@ module.exports = {
name: Events.GuildCreate, name: Events.GuildCreate,
isDebug: false, isDebug: false,
once: false, once: false,
execute: async (guild) => { execute: async (guild: Guild) => {
const executionId = uuidv4(); const executionId = uuidv4();
const logger = loggerModule.child({ const logger = loggerModule.child({
source: 'guildCreate.js', source: 'guildCreate.js',
+2 -2
View File
@@ -1,4 +1,4 @@
import { Events } from 'discord.js'; import { Events, Guild } from 'discord.js';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import loggerModule from '../../services/logger'; import loggerModule from '../../services/logger';
@@ -6,7 +6,7 @@ module.exports = {
name: Events.GuildDelete, name: Events.GuildDelete,
isDebug: false, isDebug: false,
once: false, once: false,
execute: async (guild) => { execute: async (guild: Guild) => {
const executionId = uuidv4(); const executionId = uuidv4();
const logger = loggerModule.child({ const logger = loggerModule.child({
source: 'guildDelete.js', source: 'guildDelete.js',
+13 -12
View File
@@ -1,42 +1,43 @@
import config from 'config'; import config from 'config';
import { EmbedOptions } from '../../types/configTypes'; import { EmbedOptions, LoadTestOptions, SystemOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions'); const embedOptions: EmbedOptions = config.get('embedOptions');
const systemOptions = config.get('systemOptions'); const systemOptions: SystemOptions = config.get('systemOptions');
const presenceStatusOptions = config.get('presenceStatusOptions'); const presenceStatusOptions: PresenceData = config.get('presenceStatusOptions');
const loadTestOptions = config.get('loadTestOptions'); const loadTestOptions: LoadTestOptions = config.get('loadTestOptions');
import { postBotStats } from '../../utils/other/postBotStats'; import { postBotStats } from '../../utils/other/postBotStats';
import { startLoadTest } from '../../utils/other/startLoadTest'; import { startLoadTest } from '../../utils/other/startLoadTest';
import { Events, EmbedBuilder } from 'discord.js'; import { Events, EmbedBuilder, PresenceData, BaseGuildTextChannel } from 'discord.js';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import loggerModule from '../../services/logger'; import loggerModule from '../../services/logger';
import { ExtendedClient } from '../../types/clientTypes';
module.exports = { module.exports = {
name: Events.ClientReady, name: Events.ClientReady,
isDebug: false, isDebug: false,
once: false, once: false,
execute: async (client) => { execute: async (client: ExtendedClient) => {
const executionId = uuidv4(); const executionId = uuidv4();
const logger = loggerModule.child({ const logger = loggerModule.child({
source: 'ready.js', source: 'ready.js',
module: 'event', module: 'event',
name: 'clientReady', name: 'clientReady',
executionId: executionId, executionId: executionId,
shardId: client.shard.ids[0] shardId: client.shard?.ids[0]
}); });
logger.debug('Client \'ready\' event received after \'allShardsReady\' event.'); logger.debug("Client 'ready' event received after 'allShardsReady' event.");
await client.user.setPresence(presenceStatusOptions); await client.user?.setPresence(presenceStatusOptions);
if (loadTestOptions.enabled) { if (loadTestOptions.enabled) {
// Only call function from shard with id 0 // Only call function from shard with id 0
// The function uses broadcastEval() to call itself on all shards // The function uses broadcastEval() to call itself on all shards
if (client.shard.ids[0] === 0) { if (client.shard?.ids[0] === 0) {
logger.info('Initiating load test for bot client.'); logger.info('Initiating load test for bot client.');
await startLoadTest({ client, executionId }); await startLoadTest({ client, executionId });
} }
} }
const channel = await client.channels.cache.get(systemOptions.systemMessageChannelId); const channel = (await client.channels.cache.get(systemOptions.systemMessageChannelId)) as BaseGuildTextChannel;
// Check if the channel exists in curent shard and send a message // Check if the channel exists in curent shard and send a message
if (channel) { if (channel) {
@@ -45,7 +46,7 @@ module.exports = {
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
.setDescription( .setDescription(
`**${embedOptions.icons.success} All shards ready**\n**${client.user.tag}** is now **\`online\`**!` `**${embedOptions.icons.success} All shards ready**\n**${client.user?.tag}** is now **\`online\`**!`
) )
.setColor(embedOptions.colors.success) .setColor(embedOptions.colors.success)
] ]
+10 -7
View File
@@ -1,23 +1,24 @@
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import config from 'config'; import config from 'config';
import { EmbedOptions } from '../../types/configTypes'; import { EmbedOptions, SystemOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions'); const embedOptions: EmbedOptions = config.get('embedOptions');
const systemOptions = config.get('systemOptions'); const systemOptions: SystemOptions = config.get('systemOptions');
import { EmbedBuilder } from 'discord.js'; import { BaseGuildTextChannel, EmbedBuilder } from 'discord.js';
import loggerModule from '../../services/logger'; import loggerModule from '../../services/logger';
import { ExtendedClient } from '../../types/clientTypes';
module.exports = { module.exports = {
name: 'reconnecting', name: 'reconnecting',
isDebug: false, isDebug: false,
once: false, once: false,
execute: async (client) => { execute: async (client: ExtendedClient) => {
const executionId = uuidv4(); const executionId = uuidv4();
const logger = loggerModule.child({ const logger = loggerModule.child({
source: 'reconnecting.js', source: 'reconnecting.js',
module: 'event', module: 'event',
name: 'clientReconnecting', name: 'clientReconnecting',
executionId: executionId, executionId: executionId,
shardId: client.shard.ids[0] shardId: client.shard?.ids[0]
}); });
logger.warn('Client is reconnecting to Discord APIs.'); logger.warn('Client is reconnecting to Discord APIs.');
@@ -25,13 +26,15 @@ module.exports = {
// send message to system message channel for event // send message to system message channel for event
if (systemOptions.systemMessageChannelId && systemOptions.systemUserId) { if (systemOptions.systemMessageChannelId && systemOptions.systemUserId) {
if (systemOptions.systemMessageChannelId && systemOptions.systemUserId) { if (systemOptions.systemMessageChannelId && systemOptions.systemUserId) {
const channel = await client.channels.cache.get(systemOptions.systemMessageChannelId); const channel = (await client.channels.cache.get(
systemOptions.systemMessageChannelId
)) as BaseGuildTextChannel;
if (channel) { if (channel) {
await channel.send({ await channel.send({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
.setDescription( .setDescription(
`${embedOptions.icons.warning} **${client.user.tag}** is **\`reconnecting\`**!` + `${embedOptions.icons.warning} **${client.user?.tag}** is **\`reconnecting\`**!` +
`\n\n<@${systemOptions.systemUserId}>` `\n\n<@${systemOptions.systemUserId}>`
) )
.setColor(embedOptions.colors.warning) .setColor(embedOptions.colors.warning)
+1 -1
View File
@@ -6,7 +6,7 @@ module.exports = {
name: Events.Warn, name: Events.Warn,
isDebug: false, isDebug: false,
once: false, once: false,
execute: async (warning) => { execute: async (warning: string) => {
const executionId = uuidv4(); const executionId = uuidv4();
const logger = loggerModule.child({ const logger = loggerModule.child({
source: 'warn.js', source: 'warn.js',
+51 -33
View File
@@ -1,60 +1,47 @@
import config from 'config'; import config from 'config';
import { EmbedOptions } from '../../types/configTypes'; import { BotOptions, EmbedOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions'); const embedOptions: EmbedOptions = config.get('embedOptions');
const botOptions = config.get('botOptions'); const botOptions: BotOptions = config.get('botOptions');
import { cannotSendMessageInChannel } from '../../utils/validation/permissionValidator'; import { cannotSendMessageInChannel } from '../../utils/validation/permissionValidator';
import { Events, EmbedBuilder } from 'discord.js'; import { Events, EmbedBuilder, Interaction, StringSelectMenuInteraction } from 'discord.js';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import loggerModule from '../../services/logger'; import loggerModule from '../../services/logger';
import { ExtendedClient, Command } from '../../types/clientTypes';
module.exports = { module.exports = {
name: Events.InteractionCreate, name: Events.InteractionCreate,
isDebug: false, isDebug: false,
execute: async (interaction, { client }) => { execute: async (interaction: Interaction, { client }: { client: ExtendedClient }) => {
const executionId = uuidv4(); const executionId = uuidv4();
const logger = loggerModule.child({ const logger = loggerModule.child({
source: 'interactionCreate.js', source: 'interactionCreate.js',
module: 'event', module: 'event',
name: 'interactionCreate', name: 'interactionCreate',
executionId: executionId, executionId: executionId,
shardId: interaction.guild.shardId, shardId: interaction.guild?.shardId,
guildId: interaction.guild.id guildId: interaction.guild?.id
}); });
if (interaction.isMessageComponent()) { if (interaction.isMessageComponent()) {
if (interaction instanceof StringSelectMenuInteraction) {
logger.debug( logger.debug(
`Message component interaction created for id ${interaction.customId}${ `Message component interaction created for id ${interaction.customId}${
interaction.values ? ' and values ' + interaction.values : '' interaction.values ? ' and values ' + interaction.values : ''
}.` }.`
); );
}
return; return;
} }
const command = client.commands.get(interaction.commandName); if (interaction.isChatInputCommand() || interaction.isAutocomplete()) {
const command = client.commands?.get(interaction.commandName) as Command;
if (interaction.isChatInputCommand()) {
if (!command) { if (!command) {
logger.warn(`Interaction created but command '${interaction.commandName}' was not found.`); logger.warn(`Interaction created but command '${interaction.commandName}' was not found.`);
return; return;
} }
if (interaction.isAutocomplete()) {
logger.debug('Autocomplete interaction created.');
try {
await command.autocomplete({ interaction, executionId });
} catch (error) {
if (
error.message === 'Unknown interaction' ||
error.message === 'Interaction has already been acknowledged.'
) {
logger.debug(
'Autocomplete failed to be responded to, unknown interaction or already acknowledged.'
);
return;
} else {
logger.warn(error, 'Autocomplete failed to execute.');
}
return;
}
} else if (interaction.isChatInputCommand()) {
logger.debug(`Chat input command interaction created for '${interaction.commandName}'.`); logger.debug(`Chat input command interaction created for '${interaction.commandName}'.`);
try { try {
await interaction.deferReply(); await interaction.deferReply();
@@ -63,15 +50,16 @@ module.exports = {
return; return;
} }
const inputTime = new Date(); const inputTime: number = new Date().getTime();
await command.execute({ interaction, client, executionId }); await command.execute({ interaction, client, executionId });
const outputTime = new Date(); const outputTime: number = new Date().getTime();
const executionTime = outputTime - inputTime; const executionTime: number = outputTime - inputTime;
logger.info(`Command '${interaction}' executed in ${executionTime} ms.`); logger.info(`Command '${interaction}' executed in ${executionTime} ms.`);
} catch (error) { } catch (error) {
if (error instanceof Error) {
logger.warn( logger.warn(
error, error,
`Command '${interaction}' throwed an unhandled error and might have failed to execute properly.` `Command '${interaction}' throwed an unhandled error and might have failed to execute properly.`
@@ -81,7 +69,9 @@ module.exports = {
error.message === 'Unknown interaction' || error.message === 'Unknown interaction' ||
error.message === 'Interaction has already been acknowledged.' error.message === 'Interaction has already been acknowledged.'
) { ) {
logger.debug('Command failed to be responded to, unknown interaction or already acknowledged.'); logger.debug(
'Command failed to be responded to, unknown interaction or already acknowledged.'
);
return; return;
} else { } else {
if (!interaction.deferred || !interaction.replied) { if (!interaction.deferred || !interaction.replied) {
@@ -105,7 +95,9 @@ module.exports = {
] ]
}); });
} else { } else {
logger.info('Interaction was not deferred or replied, sending new reply with Uh-oh message.'); logger.info(
'Interaction was not deferred or replied, sending new reply with Uh-oh message.'
);
await interaction.reply({ await interaction.reply({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
@@ -118,8 +110,34 @@ module.exports = {
}); });
} }
} }
}
} else { } else {
throw error;
}
}
} else if (interaction.isAutocomplete()) {
logger.debug('Autocomplete interaction created.');
try {
command?.autocomplete && (await command?.autocomplete({ interaction, executionId }));
} catch (error) {
if (error instanceof Error) {
if (
error.message === 'Unknown interaction' ||
error.message === 'Interaction has already been acknowledged.'
) {
logger.debug(
'Autocomplete failed to be responded to, unknown interaction or already acknowledged.'
);
return;
} else {
logger.warn(error, 'Autocomplete failed to execute.');
}
return;
} else {
throw error;
}
}
}
logger.warn(interaction, 'Interaction created but was not a chat input or autocomplete interaction.'); logger.warn(interaction, 'Interaction created but was not a chat input or autocomplete interaction.');
} }
} }
+1 -1
View File
@@ -5,7 +5,7 @@ module.exports = {
name: 'debug', name: 'debug',
isDebug: true, isDebug: true,
isPlayerEvent: false, isPlayerEvent: false,
execute: async (message) => { execute: async (message: string) => {
const executionId = uuidv4(); const executionId = uuidv4();
const logger = loggerModule.child({ const logger = loggerModule.child({
source: 'generalDebug.js', source: 'generalDebug.js',
+13 -10
View File
@@ -1,31 +1,32 @@
import config from 'config'; import config from 'config';
import { EmbedOptions } from '../../types/configTypes'; import { BotOptions, EmbedOptions, SystemOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions'); const embedOptions: EmbedOptions = config.get('embedOptions');
const botOptions = config.get('botOptions'); const botOptions: BotOptions = config.get('botOptions');
const systemOptions = config.get('systemOptions'); const systemOptions: SystemOptions = config.get('systemOptions');
import { EmbedBuilder } from 'discord.js'; import { BaseGuildTextChannel, EmbedBuilder } from 'discord.js';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import loggerModule from '../../services/logger'; import loggerModule from '../../services/logger';
import { ExtendedGuildQueuePlayerNode } from '../../types/eventTypes';
// Emitted when the player queue encounters error (general error with queue) // Emitted when the player queue encounters error (general error with queue)
module.exports = { module.exports = {
name: 'error', name: 'error',
isDebug: false, isDebug: false,
isPlayerEvent: true, isPlayerEvent: true,
execute: async (queue, error) => { execute: async (queue: ExtendedGuildQueuePlayerNode, error: Error) => {
const executionId = uuidv4(); const executionId = uuidv4();
const logger = loggerModule.child({ const logger = loggerModule.child({
source: 'generalError.js', source: 'generalError.js',
module: 'event', module: 'event',
name: 'playerGeneralError', name: 'playerGeneralError',
executionId: executionId, executionId: executionId,
shardId: queue.metadata.client.shard.ids[0], shardId: queue.metadata?.client.shard?.ids[0],
guildId: queue.metadata.channel.guild.id guildId: queue.metadata?.channel.guild.id
}); });
logger.error(error, 'player.events.on(\'error\'): Player queue encountered error event'); logger.error(error, "player.events.on('error'): Player queue encountered error event");
await queue.metadata.channel.send({ await queue.metadata?.channel.send({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
.setDescription( .setDescription(
@@ -37,7 +38,9 @@ module.exports = {
}); });
if (systemOptions.systemMessageChannelId && systemOptions.systemUserId) { if (systemOptions.systemMessageChannelId && systemOptions.systemUserId) {
const channel = await queue.metadata.client.channels.cache.get(systemOptions.systemMessageChannelId); const channel = (await queue.metadata?.client.channels.cache.get(
systemOptions.systemMessageChannelId
)) as BaseGuildTextChannel;
if (channel) { if (channel) {
await channel.send({ await channel.send({
embeds: [ embeds: [
+1 -1
View File
@@ -5,7 +5,7 @@ module.exports = {
name: 'error', name: 'error',
isDebug: true, isDebug: true,
isPlayerEvent: true, isPlayerEvent: true,
execute: async (message) => { execute: async (message: string) => {
const executionId = uuidv4(); const executionId = uuidv4();
const logger = loggerModule.child({ const logger = loggerModule.child({
source: 'playerDebug.js', source: 'playerDebug.js',
+13 -10
View File
@@ -1,31 +1,32 @@
import config from 'config'; import config from 'config';
import { EmbedOptions } from '../../types/configTypes'; import { BotOptions, EmbedOptions, SystemOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions'); const embedOptions: EmbedOptions = config.get('embedOptions');
const botOptions = config.get('botOptions'); const botOptions: BotOptions = config.get('botOptions');
const systemOptions = config.get('systemOptions'); const systemOptions: SystemOptions = config.get('systemOptions');
import { EmbedBuilder } from 'discord.js'; import { BaseGuildTextChannel, EmbedBuilder } from 'discord.js';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import loggerModule from '../../services/logger'; import loggerModule from '../../services/logger';
import { ExtendedGuildQueuePlayerNode } from '../../types/eventTypes';
// Emitted when the player encounters an error while streaming audio track // Emitted when the player encounters an error while streaming audio track
module.exports = { module.exports = {
name: 'error', name: 'error',
isDebug: false, isDebug: false,
isPlayerEvent: true, isPlayerEvent: true,
execute: async (queue, error) => { execute: async (queue: ExtendedGuildQueuePlayerNode, error: Error) => {
const executionId = uuidv4(); const executionId = uuidv4();
const logger = loggerModule.child({ const logger = loggerModule.child({
source: 'playerError.js', source: 'playerError.js',
module: 'event', module: 'event',
name: 'playerError', name: 'playerError',
executionId: executionId, executionId: executionId,
shardId: queue.metadata.client.shard.ids[0], shardId: queue.metadata?.client.shard?.ids[0],
guildId: queue.metadata.channel.guild.id guildId: queue.metadata?.channel.guild.id
}); });
logger.error(error, 'player.events.on(\'playerError\'): Player error while streaming track'); logger.error(error, "player.events.on('playerError'): Player error while streaming track");
await queue.metadata.channel.send({ await queue.metadata?.channel.send({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
.setDescription( .setDescription(
@@ -37,7 +38,9 @@ module.exports = {
}); });
if (systemOptions.systemMessageChannelId && systemOptions.systemUserId) { if (systemOptions.systemMessageChannelId && systemOptions.systemUserId) {
const channel = await queue.metadata.client.channels.cache.get(systemOptions.systemMessageChannelId); const channel = (await queue.metadata?.client.channels.cache.get(
systemOptions.systemMessageChannelId
)) as BaseGuildTextChannel;
if (channel) { if (channel) {
await channel.send({ await channel.send({
embeds: [ embeds: [
+13 -9
View File
@@ -1,31 +1,33 @@
import config from 'config'; import config from 'config';
import { EmbedOptions } from '../../types/configTypes'; import { BotOptions, EmbedOptions, SystemOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions'); const embedOptions: EmbedOptions = config.get('embedOptions');
const botOptions = config.get('botOptions'); const botOptions: BotOptions = config.get('botOptions');
const systemOptions = config.get('systemOptions'); const systemOptions: SystemOptions = config.get('systemOptions');
import { EmbedBuilder } from 'discord.js'; import { BaseGuildTextChannel, EmbedBuilder } from 'discord.js';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import loggerModule from '../../services/logger'; import loggerModule from '../../services/logger';
import { Track } from 'discord-player';
import { ExtendedGuildQueuePlayerNode } from '../../types/eventTypes';
// Emitted when the audio player fails to load the stream for a track // Emitted when the audio player fails to load the stream for a track
module.exports = { module.exports = {
name: 'playerSkip', name: 'playerSkip',
isDebug: false, isDebug: false,
isPlayerEvent: true, isPlayerEvent: true,
execute: async (queue, track) => { execute: async (queue: ExtendedGuildQueuePlayerNode, track: Track) => {
const executionId = uuidv4(); const executionId = uuidv4();
const logger = loggerModule.child({ const logger = loggerModule.child({
source: 'playerSkip.js', source: 'playerSkip.js',
module: 'event', module: 'event',
name: 'playerSkip', name: 'playerSkip',
executionId: executionId, executionId: executionId,
shardId: queue.metadata.client.shard.ids[0], shardId: queue.metadata?.client.shard?.ids[0],
guildId: queue.metadata.channel.guild.id guildId: queue.metadata?.channel.guild.id
}); });
logger.error(`player.events.on('playerSkip'): Failed to play '${track.url}'.`); logger.error(`player.events.on('playerSkip'): Failed to play '${track.url}'.`);
await queue.metadata.channel.send({ await queue.metadata?.channel.send({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
.setDescription( .setDescription(
@@ -37,7 +39,9 @@ module.exports = {
}); });
if (systemOptions.systemMessageChannelId && systemOptions.systemUserId) { if (systemOptions.systemMessageChannelId && systemOptions.systemUserId) {
const channel = await queue.metadata.client.channels.cache.get(systemOptions.systemMessageChannelId); const channel = (await queue.metadata?.client.channels.cache.get(
systemOptions.systemMessageChannelId
)) as BaseGuildTextChannel;
if (channel) { if (channel) {
await channel.send({ await channel.send({
embeds: [ embeds: [
+5 -3
View File
@@ -1,19 +1,21 @@
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import loggerModule from '../../services/logger'; import loggerModule from '../../services/logger';
import { Track } from 'discord-player';
import { ExtendedGuildQueuePlayerNode } from '../../types/eventTypes';
module.exports = { module.exports = {
name: 'playerStart', name: 'playerStart',
isDebug: false, isDebug: false,
isPlayerEvent: true, isPlayerEvent: true,
execute: async (queue, track) => { execute: async (queue: ExtendedGuildQueuePlayerNode, track: Track) => {
const executionId = uuidv4(); const executionId = uuidv4();
const logger = loggerModule.child({ const logger = loggerModule.child({
source: 'playerStart.js', source: 'playerStart.js',
module: 'event', module: 'event',
name: 'playerStart', name: 'playerStart',
executionId: executionId, executionId: executionId,
shardId: queue.metadata.client.shard.ids[0], shardId: queue.metadata?.client.shard?.ids[0],
guildId: queue.metadata.channel.guild.id guildId: queue.metadata?.channel.guild.id
}); });
logger.debug(`playerStart event: Started playing '${track.url}'.`); logger.debug(`playerStart event: Started playing '${track.url}'.`);
+1 -1
View File
@@ -4,7 +4,7 @@ import loggerModule from '../../services/logger';
module.exports = { module.exports = {
name: 'uncaughtException', name: 'uncaughtException',
isDebug: false, isDebug: false,
execute: async (error) => { execute: async (error: Error) => {
const executionId = uuidv4(); const executionId = uuidv4();
const logger = loggerModule.child({ const logger = loggerModule.child({
source: 'uncaughtException.js', source: 'uncaughtException.js',
+1 -1
View File
@@ -4,7 +4,7 @@ import loggerModule from '../../services/logger';
module.exports = { module.exports = {
name: 'unhandledRejection', name: 'unhandledRejection',
isDebug: false, isDebug: false,
execute: async (error) => { execute: async (error: Error) => {
const executionId = uuidv4(); const executionId = uuidv4();
const logger = loggerModule.child({ const logger = loggerModule.child({
source: 'unhandledRejection.js', source: 'unhandledRejection.js',
+1 -1
View File
@@ -2,7 +2,7 @@ import pino from 'pino';
import config from 'config'; import config from 'config';
// Retrieve logger options from config // Retrieve logger options from config
const loggerOptions = config.get('loggerOptions'); const loggerOptions: LoggerOptions = config.get('loggerOptions');
const targets = [ const targets = [
{ {
+9 -1
View File
@@ -2,7 +2,15 @@ import { Client, Collection } from 'discord.js';
type RegisterClientCommandsFunction = (params: { client: Client; executionId: string }) => void; type RegisterClientCommandsFunction = (params: { client: Client; executionId: string }) => void;
export interface Command {
isNew: boolean;
isBeta: boolean;
data: object;
execute: (params: { interaction: object; client: ExtendedClient | undefined; executionId: string }) => void;
autocomplete?: (params: { interaction: object; executionId: string }) => void;
}
export interface ExtendedClient extends Client { export interface ExtendedClient extends Client {
registerClientCommands?: RegisterClientCommandsFunction; registerClientCommands?: RegisterClientCommandsFunction;
commands?: Collection<string, NodeModule>; commands?: Collection<string, NodeModule | Command>;
} }
+13
View File
@@ -1,3 +1,16 @@
import { GuildQueuePlayerNode } from 'discord-player';
import { ExtendedClient } from './clientTypes';
import { BaseGuildTextChannel } from 'discord.js';
export type ClientEventArguments = unknown[]; export type ClientEventArguments = unknown[];
export type ProcessEventArguments = unknown[]; export type ProcessEventArguments = unknown[];
export type PlayerEventArguments = unknown[]; export type PlayerEventArguments = unknown[];
export interface ExtendedGuildQueuePlayerNode extends GuildQueuePlayerNode<unknown> {
metadata:
| undefined
| {
client: ExtendedClient;
channel: BaseGuildTextChannel;
};
}