mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-04 22:15:29 +00:00
fix: more changes to logging
This commit is contained in:
1 parent
7ef666f03d
commit
9d9087d4c3
39 files changed
+403
-260
No files matched your search
Generated
+10
-1
@@ -21,7 +21,8 @@
|
|||||||
"mediaplex": "^0.0.6",
|
"mediaplex": "^0.0.6",
|
||||||
"node-os-utils": "^1.3.7",
|
"node-os-utils": "^1.3.7",
|
||||||
"pino": "^8.15.0",
|
"pino": "^8.15.0",
|
||||||
"pino-loki": "^2.1.3"
|
"pino-loki": "^2.1.3",
|
||||||
|
"uuid": "^9.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^8.47.0",
|
"eslint": "^8.47.0",
|
||||||
@@ -3643,6 +3644,14 @@
|
|||||||
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
|
||||||
"integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw=="
|
"integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw=="
|
||||||
},
|
},
|
||||||
|
"node_modules/uuid": {
|
||||||
|
"version": "9.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz",
|
||||||
|
"integrity": "sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==",
|
||||||
|
"bin": {
|
||||||
|
"uuid": "dist/bin/uuid"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/vue-eslint-parser": {
|
"node_modules/vue-eslint-parser": {
|
||||||
"version": "8.3.0",
|
"version": "8.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/vue-eslint-parser/-/vue-eslint-parser-8.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/vue-eslint-parser/-/vue-eslint-parser-8.3.0.tgz",
|
||||||
|
|||||||
+4
-3
@@ -20,10 +20,10 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"start": "node ./src/index.js",
|
"start": "node ./src/index.js",
|
||||||
"start-pretty": "node ./src/index.js | pino-pretty --ignore environment,source,module,action,name,context,err,error",
|
"start-pretty": "node ./src/index.js | pino-pretty --ignore environment,source,module,action,name,context,err,error,executionId,shardId,guildId",
|
||||||
"start-pretty-no-ignore": "node ./src/index.js | pino-pretty",
|
"start-pretty-no-ignore": "node ./src/index.js | pino-pretty",
|
||||||
"deploy": "node ./src/utils/deploySlashCommands.js",
|
"deploy": "node ./src/utils/deploySlashCommands.js",
|
||||||
"deploy-pretty": "node ./src/utils/deploySlashCommands.js | pino-pretty --ignore environment,source,module,action,name,context,err,error",
|
"deploy-pretty": "node ./src/utils/deploySlashCommands.js | pino-pretty --ignore environment,source,module,action,name,context,err,error,executionId,shardId,guildId",
|
||||||
"eslint": "eslint ./"
|
"eslint": "eslint ./"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -39,7 +39,8 @@
|
|||||||
"mediaplex": "^0.0.6",
|
"mediaplex": "^0.0.6",
|
||||||
"node-os-utils": "^1.3.7",
|
"node-os-utils": "^1.3.7",
|
||||||
"pino": "^8.15.0",
|
"pino": "^8.15.0",
|
||||||
"pino-loki": "^2.1.3"
|
"pino-loki": "^2.1.3",
|
||||||
|
"uuid": "^9.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^8.47.0",
|
"eslint": "^8.47.0",
|
||||||
|
|||||||
+15
-5
@@ -1,18 +1,28 @@
|
|||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
const logger = require('./services/logger');
|
|
||||||
const { registerEventListeners } = require('./utils/registerEventListeners.js');
|
const { registerEventListeners } = require('./utils/registerEventListeners.js');
|
||||||
const { registerClientCommands } = require('./utils/registerClientCommands.js');
|
const { registerClientCommands } = require('./utils/registerClientCommands.js');
|
||||||
const { createClient } = require('./utils/factory/createClient.js');
|
const { createClient } = require('./utils/factory/createClient.js');
|
||||||
const { createPlayer } = require('./utils/factory/createPlayer.js');
|
const { createPlayer } = require('./utils/factory/createPlayer.js');
|
||||||
|
const { v4: uuidv4 } = require('uuid');
|
||||||
|
|
||||||
|
const executionId = uuidv4();
|
||||||
|
|
||||||
|
const logger = require('./services/logger').child({
|
||||||
|
source: 'bot.js',
|
||||||
|
module: 'shardingClient',
|
||||||
|
name: 'shardingClient',
|
||||||
|
executionId: executionId,
|
||||||
|
shardId: 'client'
|
||||||
|
});
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const client = await createClient();
|
const client = await createClient({ executionId });
|
||||||
const player = await createPlayer(client);
|
const player = await createPlayer({ client, executionId });
|
||||||
|
|
||||||
client.on('allShardsReady', async () => {
|
client.on('allShardsReady', async () => {
|
||||||
client.registerClientCommands = registerClientCommands;
|
client.registerClientCommands = registerClientCommands;
|
||||||
registerEventListeners(client, player);
|
registerEventListeners({ client, player, executionId });
|
||||||
registerClientCommands(client);
|
registerClientCommands({ client, executionId });
|
||||||
client.emit('ready', client);
|
client.emit('ready', client);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
logger.error(error, `[Shard ${client.shard.ids[0]}] Failed to fetch client values from shards.`);
|
logger.error(error, 'Failed to fetch client values from shards.');
|
||||||
});
|
});
|
||||||
|
|
||||||
const botStatusString =
|
const botStatusString =
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ module.exports = {
|
|||||||
components: [filterActionRow, disableFiltersActionRow]
|
components: [filterActionRow, disableFiltersActionRow]
|
||||||
});
|
});
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] Sent embed for command ${interaction.commandName}, awaiting interaction response.`
|
`Sent embed for command ${interaction.commandName}, awaiting interaction response.`
|
||||||
);
|
);
|
||||||
|
|
||||||
const collectorFilter = (i) => i.user.id === interaction.user.id;
|
const collectorFilter = (i) => i.user.id === interaction.user.id;
|
||||||
@@ -99,7 +99,7 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] Received interaction response for command ${interaction.commandName}.`
|
`Received interaction response for command ${interaction.commandName}.`
|
||||||
);
|
);
|
||||||
|
|
||||||
confirmation.deferUpdate();
|
confirmation.deferUpdate();
|
||||||
@@ -150,7 +150,7 @@ module.exports = {
|
|||||||
queue.filters.ffmpeg.toggle(confirmation.values);
|
queue.filters.ffmpeg.toggle(confirmation.values);
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] Enabled filters ${confirmation.values.join(', ')} for command ${
|
`Enabled filters ${confirmation.values.join(', ')} for command ${
|
||||||
interaction.commandName
|
interaction.commandName
|
||||||
}.`
|
}.`
|
||||||
);
|
);
|
||||||
@@ -182,14 +182,14 @@ module.exports = {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.code === 'InteractionCollectorError') {
|
if (error.code === 'InteractionCollectorError') {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] Interaction response timed out for command ${interaction.commandName}.`
|
`Interaction response timed out for command ${interaction.commandName}.`
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
error,
|
error,
|
||||||
`[Shard ${interaction.guild.shardId}] Unhandled error while awaiting interaction response for command ${interaction.commandName}, throwing error.`
|
`Unhandled error while awaiting interaction response for command ${interaction.commandName}, throwing error.`
|
||||||
);
|
);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ module.exports = {
|
|||||||
|
|
||||||
if (!queue) {
|
if (!queue) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but there was no queue.`
|
`User used command ${interaction.commandName} but there was no queue.`
|
||||||
);
|
);
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
@@ -42,7 +42,7 @@ module.exports = {
|
|||||||
if (!queue.deleted) {
|
if (!queue.deleted) {
|
||||||
queue.delete();
|
queue.delete();
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and deleted the queue.`
|
`User used command ${interaction.commandName} and deleted the queue.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ module.exports = {
|
|||||||
|
|
||||||
if (!mode && mode !== 0) {
|
if (!mode && mode !== 0) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but no mode was provided.`
|
`User used command ${interaction.commandName} but no mode was provided.`
|
||||||
);
|
);
|
||||||
|
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
@@ -74,7 +74,7 @@ module.exports = {
|
|||||||
|
|
||||||
if (mode === currentMode) {
|
if (mode === currentMode) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but loop mode was already set to ${modeUserString}.`
|
`User used command ${interaction.commandName} but loop mode was already set to ${modeUserString}.`
|
||||||
);
|
);
|
||||||
|
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
@@ -92,7 +92,7 @@ module.exports = {
|
|||||||
|
|
||||||
if (!queue.repeatMode === mode) {
|
if (!queue.repeatMode === mode) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but failed to change loop mode.`
|
`User used command ${interaction.commandName} but failed to change loop mode.`
|
||||||
);
|
);
|
||||||
|
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
@@ -108,7 +108,7 @@ module.exports = {
|
|||||||
|
|
||||||
if (queue.repeatMode === 0) {
|
if (queue.repeatMode === 0) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and disabled loop mode.`
|
`User used command ${interaction.commandName} and disabled loop mode.`
|
||||||
);
|
);
|
||||||
|
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
@@ -128,7 +128,7 @@ module.exports = {
|
|||||||
|
|
||||||
if (queue.repeatMode === 3) {
|
if (queue.repeatMode === 3) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and enabled autoplay.`
|
`User used command ${interaction.commandName} and enabled autoplay.`
|
||||||
);
|
);
|
||||||
|
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
@@ -147,7 +147,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and enabled loop mode.`
|
`User used command ${interaction.commandName} and enabled loop mode.`
|
||||||
);
|
);
|
||||||
|
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ module.exports = {
|
|||||||
if (lastQuery && (query.startsWith(lastQuery) || lastQuery.startsWith(query)) && Date.now() - timestamp < 500) {
|
if (lastQuery && (query.startsWith(lastQuery) || lastQuery.startsWith(query)) && Date.now() - timestamp < 500) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
{ action: 'autocomplete_responded' },
|
{ action: 'autocomplete_responded' },
|
||||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Autocomplete search responded with results from lastQuery for query: '${query}'`
|
`Autocomplete search responded with results from lastQuery for query: '${query}'`
|
||||||
);
|
);
|
||||||
return interaction.respond(result);
|
return interaction.respond(result);
|
||||||
}
|
}
|
||||||
@@ -42,7 +42,7 @@ module.exports = {
|
|||||||
if (query.length < 3) {
|
if (query.length < 3) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
{ action: 'autocomplete_responded' },
|
{ action: 'autocomplete_responded' },
|
||||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Autocomplete search responded with empty results due to < 3 length for query '${query}'`
|
`Autocomplete search responded with empty results due to < 3 length for query '${query}'`
|
||||||
);
|
);
|
||||||
return interaction.respond([]);
|
return interaction.respond([]);
|
||||||
}
|
}
|
||||||
@@ -82,7 +82,7 @@ module.exports = {
|
|||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
{ action: 'autocomplete_responded' },
|
{ action: 'autocomplete_responded' },
|
||||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Autocomplete search responded for query: '${query}'`
|
`Autocomplete search responded for query: '${query}'`
|
||||||
);
|
);
|
||||||
return interaction.respond(response);
|
return interaction.respond(response);
|
||||||
},
|
},
|
||||||
@@ -119,7 +119,7 @@ module.exports = {
|
|||||||
|
|
||||||
if (searchResults.tracks.length === 0) {
|
if (searchResults.tracks.length === 0) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but there was no search results found.`
|
`User used command ${interaction.commandName} but there was no search results found.`
|
||||||
);
|
);
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
@@ -173,7 +173,7 @@ module.exports = {
|
|||||||
|
|
||||||
if (!lyricsResult || !lyricsResult.lyrics) {
|
if (!lyricsResult || !lyricsResult.lyrics) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but there was no lyrics found.`
|
`User used command ${interaction.commandName} but there was no lyrics found.`
|
||||||
);
|
);
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
@@ -188,11 +188,11 @@ module.exports = {
|
|||||||
|
|
||||||
// If message length is too long, split into multiple messages
|
// If message length is too long, split into multiple messages
|
||||||
if (lyricsResult.lyrics.length > 3800) {
|
if (lyricsResult.lyrics.length > 3800) {
|
||||||
logger.debug(`[Shard ${interaction.guild.shardId}] Lyrics too long, splitting into multiple messages.`);
|
logger.debug('Lyrics too long, splitting into multiple messages.');
|
||||||
const messageCount = Math.ceil(lyricsResult.lyrics.length / 3800);
|
const messageCount = Math.ceil(lyricsResult.lyrics.length / 3800);
|
||||||
for (let i = 0; i < messageCount; i++) {
|
for (let i = 0; i < messageCount; i++) {
|
||||||
logger.debuf(
|
logger.debuf(
|
||||||
`[Shard ${interaction.guild.shardId}] Lyrics, sending message ${i + 1} of ${messageCount}.`
|
`Lyrics, sending message ${i + 1} of ${messageCount}.`
|
||||||
);
|
);
|
||||||
const message = lyricsResult.lyrics.slice(i * 3800, (i + 1) * 3800);
|
const message = lyricsResult.lyrics.slice(i * 3800, (i + 1) * 3800);
|
||||||
if (i === 0) {
|
if (i === 0) {
|
||||||
@@ -224,7 +224,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and retrieved lyrics.`
|
`User used command ${interaction.commandName} and retrieved lyrics.`
|
||||||
);
|
);
|
||||||
|
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ module.exports = {
|
|||||||
const loopModeUserString = loopModesFormatted.get(queue.repeatMode);
|
const loopModeUserString = loopModesFormatted.get(queue.repeatMode);
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName}, finished intializing data.`
|
`User used command ${interaction.commandName}, finished intializing data.`
|
||||||
);
|
);
|
||||||
|
|
||||||
const response = await interaction.editReply({
|
const response = await interaction.editReply({
|
||||||
@@ -159,7 +159,7 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName}, finished sending response.`
|
`User used command ${interaction.commandName}, finished sending response.`
|
||||||
);
|
);
|
||||||
|
|
||||||
const collectorFilter = (i) => i.user.id === interaction.user.id;
|
const collectorFilter = (i) => i.user.id === interaction.user.id;
|
||||||
@@ -173,11 +173,11 @@ module.exports = {
|
|||||||
|
|
||||||
if (confirmation.customId === 'nowplaying-skip') {
|
if (confirmation.customId === 'nowplaying-skip') {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName}, received skip confirmation.`
|
`User used command ${interaction.commandName}, received skip confirmation.`
|
||||||
);
|
);
|
||||||
if (!queue || (queue.tracks.data.length === 0 && !queue.currentTrack)) {
|
if (!queue || (queue.tracks.data.length === 0 && !queue.currentTrack)) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and tried skipping but there was no queue.`
|
`User used command ${interaction.commandName} and tried skipping but there was no queue.`
|
||||||
);
|
);
|
||||||
return await interaction.followUp({
|
return await interaction.followUp({
|
||||||
embeds: [
|
embeds: [
|
||||||
@@ -193,7 +193,7 @@ module.exports = {
|
|||||||
|
|
||||||
if (queue.currentTrack !== currentTrack) {
|
if (queue.currentTrack !== currentTrack) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and tried skipping but the track was already removed.`
|
`User used command ${interaction.commandName} and tried skipping but the track was already removed.`
|
||||||
);
|
);
|
||||||
return await interaction.followUp({
|
return await interaction.followUp({
|
||||||
embeds: [
|
embeds: [
|
||||||
@@ -221,7 +221,7 @@ module.exports = {
|
|||||||
const repeatModeUserString = loopModesFormatted.get(queue.repeatMode);
|
const repeatModeUserString = loopModesFormatted.get(queue.repeatMode);
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and skipped the track.`
|
`User used command ${interaction.commandName} and skipped the track.`
|
||||||
);
|
);
|
||||||
return await interaction.followUp({
|
return await interaction.followUp({
|
||||||
embeds: [
|
embeds: [
|
||||||
@@ -251,14 +251,14 @@ module.exports = {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.code === 'InteractionCollectorError') {
|
if (error.code === 'InteractionCollectorError') {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but did not respond to the skip prompt.`
|
`User used command ${interaction.commandName} but did not respond to the skip prompt.`
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
error,
|
error,
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but there was an unhandled error.`
|
`User used command ${interaction.commandName} but there was an unhandled error.`
|
||||||
);
|
);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ module.exports = {
|
|||||||
// change paused state to opposite of current state
|
// change paused state to opposite of current state
|
||||||
queue.node.setPaused(!queue.node.isPaused());
|
queue.node.setPaused(!queue.node.isPaused());
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${
|
`User used command ${
|
||||||
interaction.commandName
|
interaction.commandName
|
||||||
} and set paused state to ${queue.node.isPaused()}.`
|
} and set paused state to ${queue.node.isPaused()}.`
|
||||||
);
|
);
|
||||||
|
|||||||
+49
-56
@@ -9,12 +9,6 @@ const { transformQuery } = require('../../utils/validation/searchQueryValidator'
|
|||||||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
||||||
const { useMainPlayer, useQueue } = require('discord-player');
|
const { useMainPlayer, useQueue } = require('discord-player');
|
||||||
|
|
||||||
const logger = require('../../services/logger').child({
|
|
||||||
source: 'play.js',
|
|
||||||
module: 'command',
|
|
||||||
name: '/play'
|
|
||||||
});
|
|
||||||
|
|
||||||
const recentQueries = new Map();
|
const recentQueries = new Map();
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@@ -34,25 +28,28 @@ module.exports = {
|
|||||||
.setMaxLength(500)
|
.setMaxLength(500)
|
||||||
.setAutocomplete(true)
|
.setAutocomplete(true)
|
||||||
),
|
),
|
||||||
autocomplete: async ({ interaction }) => {
|
autocomplete: async ({ interaction, executionId }) => {
|
||||||
|
const logger = require('../../services/logger').child({
|
||||||
|
source: 'play.js',
|
||||||
|
module: 'slashCommand',
|
||||||
|
name: '/play',
|
||||||
|
executionId: executionId,
|
||||||
|
shardId: interaction.guild.shardId,
|
||||||
|
guildId: interaction.guild.id
|
||||||
|
});
|
||||||
|
|
||||||
const player = useMainPlayer();
|
const player = useMainPlayer();
|
||||||
const query = interaction.options.getString('query', true);
|
const query = interaction.options.getString('query', true);
|
||||||
|
|
||||||
const { lastQuery, results, timestamp } = recentQueries.get(interaction.user.id) || {};
|
const { lastQuery, results, timestamp } = recentQueries.get(interaction.user.id) || {};
|
||||||
|
|
||||||
if (lastQuery && (query.startsWith(lastQuery) || lastQuery.startsWith(query)) && Date.now() - timestamp < 500) {
|
if (lastQuery && (query.startsWith(lastQuery) || lastQuery.startsWith(query)) && Date.now() - timestamp < 500) {
|
||||||
logger.debug(
|
logger.debug(`Autocomplete search responded with results from lastQuery for query: '${query}'`);
|
||||||
{ action: 'autocomplete_responded' },
|
|
||||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Autocomplete search responded with results from lastQuery for query: '${query}'`
|
|
||||||
);
|
|
||||||
return interaction.respond(results);
|
return interaction.respond(results);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query.length < 3) {
|
if (query.length < 3) {
|
||||||
logger.debug(
|
logger.debug(`Autocomplete search responded with empty results due to < 3 length for query '${query}'`);
|
||||||
{ action: 'autocomplete_responded' },
|
|
||||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Autocomplete search responded with empty results due to < 3 length for query '${query}'`
|
|
||||||
);
|
|
||||||
return interaction.respond([]);
|
return interaction.respond([]);
|
||||||
}
|
}
|
||||||
const searchResults = await player.search(query);
|
const searchResults = await player.search(query);
|
||||||
@@ -82,14 +79,18 @@ module.exports = {
|
|||||||
return interaction.respond([]);
|
return interaction.respond([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(`Autocomplete search responded for query: '${query}'`);
|
||||||
{ action: 'autocomplete_responded' },
|
|
||||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Autocomplete search responded for query: '${query}'`
|
|
||||||
);
|
|
||||||
|
|
||||||
return interaction.respond(response);
|
return interaction.respond(response);
|
||||||
},
|
},
|
||||||
execute: async ({ interaction, client }) => {
|
execute: async ({ interaction, client, executionId }) => {
|
||||||
|
const logger = require('../../services/logger').child({
|
||||||
|
source: 'play.js',
|
||||||
|
module: 'slashCommand',
|
||||||
|
name: '/play',
|
||||||
|
executionId: executionId
|
||||||
|
});
|
||||||
|
|
||||||
if (await notInVoiceChannel(interaction, client)) {
|
if (await notInVoiceChannel(interaction, client)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -123,12 +124,12 @@ module.exports = {
|
|||||||
stack: error.stack
|
stack: error.stack
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Failed to search for track with player.search() with query: ${transformedQuery}.`
|
`Failed to search for track with player.search() with query: ${transformedQuery}.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!searchResult || searchResult.tracks.length === 0) {
|
if (!searchResult || searchResult.tracks.length === 0) {
|
||||||
logger.debug(`[Shard ${interaction.guild.shardId}] No results found for query: ${query}`);
|
logger.debug(`No results found for query: ${query}`);
|
||||||
|
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
@@ -145,9 +146,7 @@ module.exports = {
|
|||||||
let queueSize = queue?.size ?? 0;
|
let queueSize = queue?.size ?? 0;
|
||||||
|
|
||||||
if ((searchResult.playlist && searchResult.tracks.length) > playerOptions.maxQueueSize - queueSize) {
|
if ((searchResult.playlist && searchResult.tracks.length) > playerOptions.maxQueueSize - queueSize) {
|
||||||
logger.debug(
|
logger.debug(`Playlist found but too many tracks. Query: ${query}.`);
|
||||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Playlist found but too many tracks. Query: ${query}.`
|
|
||||||
);
|
|
||||||
|
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
@@ -186,12 +185,10 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
logger.debug(`[Shard ${interaction.guild.shardId}] player.play() successful. Query: ${query}.`);
|
logger.debug(`player.play() successful. Query: ${query}.`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.message.includes('Sign in to confirm your age')) {
|
if (error.message.includes('Sign in to confirm your age')) {
|
||||||
logger.debug(
|
logger.debug('Found track but failed to retrieve audio due to age confirmation warning.');
|
||||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Found track but failed to retrieve audio due to age confirmation warning.`
|
|
||||||
);
|
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
@@ -204,9 +201,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (error.message.includes('The following content may contain')) {
|
if (error.message.includes('The following content may contain')) {
|
||||||
logger.debug(
|
logger.debug('Found track but failed to retrieve audio due to graphic/mature/sensitive topic warning.');
|
||||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Found track but failed to retrieve audio due to graphic/mature/sensitive topic warning.`
|
|
||||||
);
|
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
@@ -224,10 +219,7 @@ module.exports = {
|
|||||||
error.message.includes('Failed to fetch resources for ytdl streaming'))) ||
|
error.message.includes('Failed to fetch resources for ytdl streaming'))) ||
|
||||||
error.message.includes('Could not extract stream for this track')
|
error.message.includes('Could not extract stream for this track')
|
||||||
) {
|
) {
|
||||||
logger.debug(
|
logger.debug(error, `Found track but failed to retrieve audio. Query: ${query}.`);
|
||||||
error,
|
|
||||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Found track but failed to retrieve audio. Query: ${query}.`
|
|
||||||
);
|
|
||||||
|
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
@@ -241,10 +233,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (error.message === 'Cancelled') {
|
if (error.message === 'Cancelled') {
|
||||||
logger.debug(
|
logger.debug(error, `Operation cancelled. Query: ${query}.`);
|
||||||
error,
|
|
||||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Operation cancelled. Query: ${query}.`
|
|
||||||
);
|
|
||||||
|
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
@@ -257,18 +246,28 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.error(
|
if (error.message === 'Cannot read properties of null (reading \'createStream\')') {
|
||||||
error,
|
// Can happen if /play then /leave before track starts playing
|
||||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Failed to play track with player.play(), unhandled error.`
|
logger.warn(error, 'Found track but failed to play back audio. Voice connection might be unavailable.');
|
||||||
);
|
|
||||||
|
return await interaction.editReply({
|
||||||
|
embeds: [
|
||||||
|
new EmbedBuilder()
|
||||||
|
.setDescription(
|
||||||
|
`**${embedOptions.icons.error} Uh-oh... Failed to add track!**\nSomething unexpected happened and it was not possible to start playing the track. This could happen if the voice connection is lost or queue is destroyed while adding the track.\n\nYou can try to perform the command again.\n\n_If you think this message is incorrect, please submit a bug report in the **[support server](${botOptions.serverInviteUrl})**._`
|
||||||
|
)
|
||||||
|
.setColor(embedOptions.colors.error)
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//logger.error(error, 'Failed to play track with player.play(), unhandled error.');
|
||||||
}
|
}
|
||||||
|
|
||||||
queue = useQueue(interaction.guild.id);
|
queue = useQueue(interaction.guild.id);
|
||||||
|
|
||||||
if (!queue) {
|
if (!queue) {
|
||||||
logger.warn(
|
logger.warn(`After player.play(), queue is undefined. Query: ${query}.`);
|
||||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> After player.play(), queue is undefined. Query: ${query}.`
|
|
||||||
);
|
|
||||||
|
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
@@ -299,9 +298,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (searchResult.playlist && searchResult.tracks.length > 1) {
|
if (searchResult.playlist && searchResult.tracks.length > 1) {
|
||||||
logger.debug(
|
logger.debug(`Playlist found and added with player.play(). Query: '${query}'`);
|
||||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Playlist found and added with player.play(). Query: '${query}'`
|
|
||||||
);
|
|
||||||
|
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
@@ -324,9 +321,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (queue.currentTrack === track && queue.tracks.data.length === 0) {
|
if (queue.currentTrack === track && queue.tracks.data.length === 0) {
|
||||||
logger.debug(
|
logger.debug(`Track found and added with player.play(), started playing. Query: ${query}.`);
|
||||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Track found and added with player.play(), started playing. Query: ${query}.`
|
|
||||||
);
|
|
||||||
|
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
@@ -345,9 +340,7 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(`Track found and added with player.play(), added to queue. Query: ${query}.`);
|
||||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Track found and added with player.play(), added to queue. Query: ${query}.`
|
|
||||||
);
|
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ module.exports = {
|
|||||||
if (!queue) {
|
if (!queue) {
|
||||||
if (pageIndex >= 1) {
|
if (pageIndex >= 1) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but there was no queue.`
|
`User used command ${interaction.commandName} but there was no queue.`
|
||||||
);
|
);
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
@@ -48,7 +48,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but there was no queue.`
|
`User used command ${interaction.commandName} but there was no queue.`
|
||||||
);
|
);
|
||||||
queueString = 'The queue is empty, add some tracks with **`/play`**!';
|
queueString = 'The queue is empty, add some tracks with **`/play`**!';
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
@@ -72,7 +72,7 @@ module.exports = {
|
|||||||
|
|
||||||
if (pageIndex > totalPages - 1) {
|
if (pageIndex > totalPages - 1) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but page was higher than total pages.`
|
`User used command ${interaction.commandName} but page was higher than total pages.`
|
||||||
);
|
);
|
||||||
|
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
@@ -127,7 +127,7 @@ module.exports = {
|
|||||||
|
|
||||||
if (!currentTrack) {
|
if (!currentTrack) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but there was no current track.`
|
`User used command ${interaction.commandName} but there was no current track.`
|
||||||
);
|
);
|
||||||
|
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
@@ -166,7 +166,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and got queue in reply with current track.`
|
`User used command ${interaction.commandName} and got queue in reply with current track.`
|
||||||
);
|
);
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ module.exports = {
|
|||||||
|
|
||||||
if (removeTrackNumber > queue.tracks.data.length) {
|
if (removeTrackNumber > queue.tracks.data.length) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but track number was higher than total tracks.`
|
`User used command ${interaction.commandName} but track number was higher than total tracks.`
|
||||||
);
|
);
|
||||||
|
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
@@ -64,7 +64,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and removed track.`
|
`User used command ${interaction.commandName} and removed track.`
|
||||||
);
|
);
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ module.exports = {
|
|||||||
|
|
||||||
if (durationArray.length === 0 || durationArray.length > 3) {
|
if (durationArray.length === 0 || durationArray.length > 3) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but entered an invalid duration.`
|
`User used command ${interaction.commandName} but entered an invalid duration.`
|
||||||
);
|
);
|
||||||
|
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
@@ -84,7 +84,7 @@ module.exports = {
|
|||||||
|
|
||||||
if (!validElements) {
|
if (!validElements) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but entered an invalid duration after parsing duration.`
|
`User used command ${interaction.commandName} but entered an invalid duration after parsing duration.`
|
||||||
);
|
);
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
@@ -107,7 +107,7 @@ module.exports = {
|
|||||||
|
|
||||||
if (!isValidDuration) {
|
if (!isValidDuration) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but entered an invalid duration after regex checks.`
|
`User used command ${interaction.commandName} but entered an invalid duration after regex checks.`
|
||||||
);
|
);
|
||||||
|
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
@@ -129,7 +129,7 @@ module.exports = {
|
|||||||
|
|
||||||
if (durationInMilliseconds > currentTrackMaxDurationInMs - 1000) {
|
if (durationInMilliseconds > currentTrackMaxDurationInMs - 1000) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but entered a duration longer than the track.`
|
`User used command ${interaction.commandName} but entered a duration longer than the track.`
|
||||||
);
|
);
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
@@ -145,7 +145,7 @@ module.exports = {
|
|||||||
queue.node.seek(durationInMilliseconds);
|
queue.node.seek(durationInMilliseconds);
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and seeked to duration.`
|
`User used command ${interaction.commandName} and seeked to duration.`
|
||||||
);
|
);
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ module.exports = {
|
|||||||
queue.tracks.shuffle();
|
queue.tracks.shuffle();
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and shuffled the queue.`
|
`User used command ${interaction.commandName} and shuffled the queue.`
|
||||||
);
|
);
|
||||||
|
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ module.exports = {
|
|||||||
if (skipToTrack) {
|
if (skipToTrack) {
|
||||||
if (skipToTrack > queue.tracks.data.length) {
|
if (skipToTrack > queue.tracks.data.length) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but track number was higher than total tracks.`
|
`User used command ${interaction.commandName} but track number was higher than total tracks.`
|
||||||
);
|
);
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
@@ -66,7 +66,7 @@ module.exports = {
|
|||||||
queue.node.skipTo(skipToTrack - 1);
|
queue.node.skipTo(skipToTrack - 1);
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and skipped to track.`
|
`User used command ${interaction.commandName} and skipped to track.`
|
||||||
);
|
);
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
@@ -86,7 +86,7 @@ module.exports = {
|
|||||||
} else {
|
} else {
|
||||||
if (queue.tracks.data.length === 0 && !queue.currentTrack) {
|
if (queue.tracks.data.length === 0 && !queue.currentTrack) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but there was no tracks in queue or current track.`
|
`User used command ${interaction.commandName} but there was no tracks in queue or current track.`
|
||||||
);
|
);
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
@@ -120,7 +120,7 @@ module.exports = {
|
|||||||
const loopModeUserString = loopModesFormatted.get(queue.repeatMode);
|
const loopModeUserString = loopModesFormatted.get(queue.repeatMode);
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and skipped track.`
|
`User used command ${interaction.commandName} and skipped track.`
|
||||||
);
|
);
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ module.exports = {
|
|||||||
|
|
||||||
if (!queue) {
|
if (!queue) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but there was no queue.`
|
`User used command ${interaction.commandName} but there was no queue.`
|
||||||
);
|
);
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
@@ -44,7 +44,7 @@ module.exports = {
|
|||||||
queue.clear();
|
queue.clear();
|
||||||
queue.node.stop();
|
queue.node.stop();
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and cleared the queue.`
|
`User used command ${interaction.commandName} and cleared the queue.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ module.exports = {
|
|||||||
const currentVolume = queue.node.volume;
|
const currentVolume = queue.node.volume;
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but no volume was provided, providing info of current volume.`
|
`User used command ${interaction.commandName} but no volume was provided, providing info of current volume.`
|
||||||
);
|
);
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
@@ -57,7 +57,7 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
} else if (volume > 100 || volume < 0) {
|
} else if (volume > 100 || volume < 0) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but volume was higher than 100% or lower than 0%.`
|
`User used command ${interaction.commandName} but volume was higher than 100% or lower than 0%.`
|
||||||
);
|
);
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
@@ -73,7 +73,7 @@ module.exports = {
|
|||||||
|
|
||||||
if (volume === 0) {
|
if (volume === 0) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and muted volume.`
|
`User used command ${interaction.commandName} and muted volume.`
|
||||||
);
|
);
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
@@ -91,7 +91,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and changed volume.`
|
`User used command ${interaction.commandName} and changed volume.`
|
||||||
);
|
);
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ module.exports = {
|
|||||||
.setNSFW(false),
|
.setNSFW(false),
|
||||||
execute: async ({ interaction, client }) => {
|
execute: async ({ interaction, client }) => {
|
||||||
if (await notValidGuildId(interaction)) {
|
if (await notValidGuildId(interaction)) {
|
||||||
logger.debug(`[Shard ${client.shard.ids[0]}] Not a valid guild id.`);
|
logger.debug('Not a valid guild id.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ module.exports = {
|
|||||||
.setNSFW(false),
|
.setNSFW(false),
|
||||||
execute: async ({ interaction, client }) => {
|
execute: async ({ interaction, client }) => {
|
||||||
if (await notValidGuildId(interaction)) {
|
if (await notValidGuildId(interaction)) {
|
||||||
logger.debug(`[Shard ${client.shard.ids[0]}] Not a valid guild id.`);
|
logger.debug('Not a valid guild id.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,10 +25,10 @@ module.exports = {
|
|||||||
shardClient.registerClientCommands(shardClient);
|
shardClient.registerClientCommands(shardClient);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
logger.info(`[Shard ${client.shard.ids[0]}] Reloaded commands across all shards.`);
|
logger.info('Reloaded commands across all shards.');
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error, `[Shard ${client.shard.ids[0]}] Failed to reload commands.`);
|
logger.error(error, 'Failed to reload commands.');
|
||||||
}
|
}
|
||||||
|
|
||||||
const commands = client.commands.map((command) => {
|
const commands = client.commands.map((command) => {
|
||||||
|
|||||||
@@ -90,10 +90,10 @@ module.exports = {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(`[Shard ${client.shard.ids[0]}] Fetched shardInfo from each shard.`);
|
logger.debug('Fetched shardInfo from each shard.');
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
logger.error(error, `[Shard ${client.shard.ids[0]}] Failed to fetch client values from shards.`);
|
logger.error(error, 'Failed to fetch client values from shards.');
|
||||||
});
|
});
|
||||||
|
|
||||||
const shardCount = shardInfoList.length;
|
const shardCount = shardInfoList.length;
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
logger.error(error, `[Shard ${client.shard.ids[0]}] Failed to fetch client values from shards.`);
|
logger.error(error, 'Failed to fetch client values from shards.');
|
||||||
});
|
});
|
||||||
|
|
||||||
const botStatusString =
|
const botStatusString =
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ module.exports = {
|
|||||||
isDebug: false,
|
isDebug: false,
|
||||||
once: false,
|
once: false,
|
||||||
execute: async (client) => {
|
execute: async (client) => {
|
||||||
logger.warn(`[Shard ${client.shard.ids[0]}] ${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) {
|
||||||
|
|||||||
@@ -1,11 +1,22 @@
|
|||||||
const logger = require('../../services/logger');
|
|
||||||
const { Events } = require('discord.js');
|
const { Events } = require('discord.js');
|
||||||
|
const { v4: uuidv4 } = require('uuid');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: Events.GuildCreate,
|
name: Events.GuildCreate,
|
||||||
isDebug: false,
|
isDebug: false,
|
||||||
once: false,
|
once: false,
|
||||||
execute: async (guild) => {
|
execute: async (guild) => {
|
||||||
logger.info(`[Shard ${guild.shardId}] Added to guild '${guild.name}' with ${guild.memberCount} members.`);
|
const executionId = uuidv4();
|
||||||
|
|
||||||
|
const logger = require('../../services/logger').child({
|
||||||
|
source: 'guildCreate.js',
|
||||||
|
module: 'event',
|
||||||
|
name: 'guildCreate',
|
||||||
|
executionId: executionId,
|
||||||
|
shardId: guild.shardId,
|
||||||
|
guildId: guild.id
|
||||||
|
});
|
||||||
|
|
||||||
|
logger.info(`Added to guild '${guild.id}' with ${guild.memberCount} members.`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -1,13 +1,22 @@
|
|||||||
const logger = require('../../services/logger');
|
|
||||||
const { Events } = require('discord.js');
|
const { Events } = require('discord.js');
|
||||||
|
const { v4: uuidv4 } = require('uuid');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: Events.GuildDelete,
|
name: Events.GuildDelete,
|
||||||
isDebug: false,
|
isDebug: false,
|
||||||
once: false,
|
once: false,
|
||||||
execute: async (guild) => {
|
execute: async (guild) => {
|
||||||
logger.info(
|
const executionId = uuidv4();
|
||||||
`[Shard ${guild.shardId}] Removed from guild '${guild.name}' with ${guild.memberCount} members.`
|
|
||||||
);
|
const logger = require('../../services/logger').child({
|
||||||
|
source: 'guildDelete.js',
|
||||||
|
module: 'event',
|
||||||
|
name: 'guildDelete',
|
||||||
|
executionId: executionId,
|
||||||
|
shardId: guild.shardId,
|
||||||
|
guildId: guild.id
|
||||||
|
});
|
||||||
|
|
||||||
|
logger.info(`Removed from guild '${guild.id}' with ${guild.memberCount} members.`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
+16
-10
@@ -1,4 +1,3 @@
|
|||||||
const logger = require('../../services/logger');
|
|
||||||
const config = require('config');
|
const config = require('config');
|
||||||
const embedOptions = config.get('embedOptions');
|
const embedOptions = config.get('embedOptions');
|
||||||
const systemOptions = config.get('systemOptions');
|
const systemOptions = config.get('systemOptions');
|
||||||
@@ -7,29 +6,36 @@ const loadTestOptions = config.get('loadTestOptions');
|
|||||||
const { postBotStats } = require('../../utils/other/postBotStats.js');
|
const { postBotStats } = require('../../utils/other/postBotStats.js');
|
||||||
const { startLoadTest } = require('../../utils/other/startLoadTest');
|
const { startLoadTest } = require('../../utils/other/startLoadTest');
|
||||||
const { Events, EmbedBuilder } = require('discord.js');
|
const { Events, EmbedBuilder } = require('discord.js');
|
||||||
|
const { v4: uuidv4 } = require('uuid');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: Events.ClientReady,
|
name: Events.ClientReady,
|
||||||
isDebug: false,
|
isDebug: false,
|
||||||
once: false,
|
once: false,
|
||||||
execute: async (client) => {
|
execute: async (client) => {
|
||||||
logger.debug(`[Shard ${client.shard.ids[0]}] Client 'ready' event emitted after 'allShardsReady'.`);
|
const executionId = uuidv4();
|
||||||
await client.user.setPresence(presenceStatusOptions);
|
|
||||||
|
const logger = require('../../services/logger').child({
|
||||||
|
source: 'ready.js',
|
||||||
|
module: 'event',
|
||||||
|
name: 'clientReady',
|
||||||
|
executionId: executionId,
|
||||||
|
shardId: client.shard.ids[0]
|
||||||
|
});
|
||||||
|
|
||||||
|
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) {
|
||||||
logger.info(`[Shard ${client.shard.ids[0]}] STARTING LOAD TEST.`);
|
logger.info('Initiating load test for bot client.');
|
||||||
await startLoadTest(client);
|
await startLoadTest({ client, executionId });
|
||||||
}
|
}
|
||||||
|
|
||||||
const channel = await client.channels.cache.get(systemOptions.systemMessageChannelId);
|
const channel = await client.channels.cache.get(systemOptions.systemMessageChannelId);
|
||||||
logger.info(`[Shard ${client.shard.ids[0]}] ALL SHARDS READY`);
|
|
||||||
|
|
||||||
// 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) {
|
||||||
logger.info(
|
logger.debug(`Sending system message for 'allShardsReady' to channel id ${channel.id}.`);
|
||||||
`[Shard ${client.shard.ids[0]}] Sending system message for 'allShardsReady' to channel id ${channel.id}.`
|
|
||||||
);
|
|
||||||
channel.send({
|
channel.send({
|
||||||
embeds: [
|
embeds: [
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
@@ -41,6 +47,6 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
process.env.NODE_ENV === 'production' ? await postBotStats(client) : null;
|
process.env.NODE_ENV === 'production' ? await postBotStats({ client, executionId }) : null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -9,7 +9,7 @@ module.exports = {
|
|||||||
isDebug: false,
|
isDebug: false,
|
||||||
once: false,
|
once: false,
|
||||||
execute: async (client) => {
|
execute: async (client) => {
|
||||||
logger.warn(`[Shard ${client.shard.ids[0]}] ${client.user.tag} is reconnecting to Discord APIs.`);
|
logger.warn(`${client.user.tag} is reconnecting to Discord APIs.`);
|
||||||
|
|
||||||
// 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) {
|
||||||
|
|||||||
@@ -1,19 +1,29 @@
|
|||||||
const logger = require('../../services/logger');
|
|
||||||
const config = require('config');
|
const config = require('config');
|
||||||
const embedOptions = config.get('embedOptions');
|
const embedOptions = config.get('embedOptions');
|
||||||
const botOptions = config.get('botOptions');
|
const botOptions = config.get('botOptions');
|
||||||
const { cannotSendMessageInChannel } = require('../../utils/validation/permissionValidator');
|
const { cannotSendMessageInChannel } = require('../../utils/validation/permissionValidator');
|
||||||
const { Events, EmbedBuilder } = require('discord.js');
|
const { Events, EmbedBuilder } = require('discord.js');
|
||||||
|
|
||||||
|
const { v4: uuidv4 } = require('uuid');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: Events.InteractionCreate,
|
name: Events.InteractionCreate,
|
||||||
isDebug: false,
|
isDebug: false,
|
||||||
execute: async (interaction, { client }) => {
|
execute: async (interaction, { client }) => {
|
||||||
|
const executionId = uuidv4();
|
||||||
|
|
||||||
|
const logger = require('../../services/logger').child({
|
||||||
|
source: 'interactionCreate.js',
|
||||||
|
module: 'event',
|
||||||
|
name: 'interactionCreate',
|
||||||
|
executionId: executionId,
|
||||||
|
shardId: interaction.guild.shardId,
|
||||||
|
guildId: interaction.guild.id
|
||||||
|
});
|
||||||
|
|
||||||
if (interaction.isMessageComponent()) {
|
if (interaction.isMessageComponent()) {
|
||||||
logger.info(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] Guild ${
|
`Message component interaction created for id ${interaction.customId}${
|
||||||
interaction.guild.id
|
|
||||||
}> Message component interaction created for id ${interaction.customId}${
|
|
||||||
interaction.values ? ' and values ' + interaction.values : ''
|
interaction.values ? ' and values ' + interaction.values : ''
|
||||||
}.`
|
}.`
|
||||||
);
|
);
|
||||||
@@ -22,32 +32,30 @@ module.exports = {
|
|||||||
|
|
||||||
const command = client.commands.get(interaction.commandName);
|
const command = client.commands.get(interaction.commandName);
|
||||||
if (!command) {
|
if (!command) {
|
||||||
logger.warn(
|
logger.warn(`Interaction created but command '${interaction.commandName}' was not found.`);
|
||||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Interaction created but command '${interaction.commandName}' was not found.`
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (interaction.isAutocomplete()) {
|
if (interaction.isAutocomplete()) {
|
||||||
logger.debug(`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Autocomplete created.`);
|
logger.debug('Autocomplete interaction created.');
|
||||||
try {
|
try {
|
||||||
await command.autocomplete({ interaction, client });
|
await command.autocomplete({ interaction, executionId });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (
|
if (
|
||||||
error.message === 'Unknown interaction' ||
|
error.message === 'Unknown interaction' ||
|
||||||
error.message === 'Interaction has already been acknowledged.'
|
error.message === 'Interaction has already been acknowledged.'
|
||||||
) {
|
) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Autocomplete failed to be responded to, unknown interaction or already acknowledged.`
|
'Autocomplete failed to be responded to, unknown interaction or already acknowledged.'
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
logger.warn(error, `[Shard ${interaction.guild.shardId}] Autocomplete failed to execute.`);
|
logger.warn(error, 'Autocomplete failed to execute.');
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (interaction.isChatInputCommand()) {
|
} else if (interaction.isChatInputCommand()) {
|
||||||
logger.debug(`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Interaction created.`);
|
logger.debug(`Chat input command interaction created for ${interaction.commandName}.`);
|
||||||
try {
|
try {
|
||||||
await interaction.deferReply();
|
await interaction.deferReply();
|
||||||
|
|
||||||
@@ -56,62 +64,70 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const inputTime = new Date();
|
const inputTime = new Date();
|
||||||
await command.execute({ interaction, client });
|
await command.execute({ interaction, client, executionId });
|
||||||
|
|
||||||
const outputTime = new Date();
|
const outputTime = new Date();
|
||||||
const executionTime = outputTime - inputTime;
|
const executionTime = outputTime - inputTime;
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Command '${interaction}' executed in ${executionTime} ms.`
|
`Command '${interaction}' executed in ${executionTime} ms.`
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
error,
|
error,
|
||||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> 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.`
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!interaction.deferred || !interaction.replied) {
|
if (
|
||||||
logger.warn(
|
error.message === 'Unknown interaction' ||
|
||||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Interaction was not deferred or replied to, and an error was thrown.`
|
error.message === 'Interaction has already been acknowledged.'
|
||||||
);
|
) {
|
||||||
|
logger.debug('Command failed to be responded to, unknown interaction or already acknowledged.');
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (interaction.replied) {
|
|
||||||
// If the interaction has already been replied to, most likely command executed successfully or error is already handled.
|
|
||||||
return;
|
|
||||||
} else if (interaction.deferred) {
|
|
||||||
logger.info(
|
|
||||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Interaction was deferred, editing reply and sending Uh-oh message.`
|
|
||||||
);
|
|
||||||
await interaction.editReply({
|
|
||||||
embeds: [
|
|
||||||
new EmbedBuilder()
|
|
||||||
.setDescription(
|
|
||||||
`**${embedOptions.icons.error} Uh-oh... _Something_ went wrong!**\nThere was an unexpected error while trying to execute this command.\n\nYou can try to perform the command again.\n\n_If this problem persists, please submit a bug report in the **[support server](${botOptions.serverInviteUrl})**._`
|
|
||||||
)
|
|
||||||
.setColor(embedOptions.colors.error)
|
|
||||||
]
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
logger.info(
|
if (!interaction.deferred || !interaction.replied) {
|
||||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Interaction was not deferred or replied, sending new reply with Uh-oh message.`
|
logger.warn(
|
||||||
);
|
'Interaction was not deferred or replied to, and an error was thrown.'
|
||||||
await interaction.reply({
|
);
|
||||||
embeds: [
|
return;
|
||||||
new EmbedBuilder()
|
}
|
||||||
.setDescription(
|
|
||||||
`**${embedOptions.icons.error} Uh-oh... _Something_ went wrong!**\nThere was an unexpected error while trying to execute this command.\n\nYou can try to perform the command again.\n\n_If this problem persists, please submit a bug report in the **[support server](${botOptions.serverInviteUrl})**._`
|
if (interaction.replied) {
|
||||||
)
|
// If the interaction has already been replied to, most likely command executed successfully or error is already handled.
|
||||||
.setColor(embedOptions.colors.error)
|
return;
|
||||||
]
|
} else if (interaction.deferred) {
|
||||||
});
|
logger.info(
|
||||||
|
'Interaction was deferred, editing reply and sending Uh-oh message.'
|
||||||
|
);
|
||||||
|
await interaction.editReply({
|
||||||
|
embeds: [
|
||||||
|
new EmbedBuilder()
|
||||||
|
.setDescription(
|
||||||
|
`**${embedOptions.icons.error} Uh-oh... _Something_ went wrong!**\nThere was an unexpected error while trying to execute this command.\n\nYou can try to perform the command again.\n\n_If this problem persists, please submit a bug report in the **[support server](${botOptions.serverInviteUrl})**._`
|
||||||
|
)
|
||||||
|
.setColor(embedOptions.colors.error)
|
||||||
|
]
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
logger.info(
|
||||||
|
'Interaction was not deferred or replied, sending new reply with Uh-oh message.'
|
||||||
|
);
|
||||||
|
await interaction.reply({
|
||||||
|
embeds: [
|
||||||
|
new EmbedBuilder()
|
||||||
|
.setDescription(
|
||||||
|
`**${embedOptions.icons.error} Uh-oh... _Something_ went wrong!**\nThere was an unexpected error while trying to execute this command.\n\nYou can try to perform the command again.\n\n_If this problem persists, please submit a bug report in the **[support server](${botOptions.serverInviteUrl})**._`
|
||||||
|
)
|
||||||
|
.setColor(embedOptions.colors.error)
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
interaction,
|
interaction,
|
||||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Interaction created but was not a chat input or autocomplete interaction.`
|
'Interaction created but was not a chat input or autocomplete interaction.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
const logger = require('../../services/logger');
|
|
||||||
const config = require('config');
|
const config = require('config');
|
||||||
const embedOptions = config.get('embedOptions');
|
const embedOptions = config.get('embedOptions');
|
||||||
const botOptions = config.get('botOptions');
|
const botOptions = config.get('botOptions');
|
||||||
const systemOptions = config.get('systemOptions');
|
const systemOptions = config.get('systemOptions');
|
||||||
const { EmbedBuilder } = require('discord.js');
|
const { EmbedBuilder } = require('discord.js');
|
||||||
|
const { v4: uuidv4 } = require('uuid');
|
||||||
|
|
||||||
// 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 = {
|
||||||
@@ -11,10 +11,18 @@ module.exports = {
|
|||||||
isDebug: false,
|
isDebug: false,
|
||||||
isPlayerEvent: true,
|
isPlayerEvent: true,
|
||||||
execute: async (queue, error) => {
|
execute: async (queue, error) => {
|
||||||
logger.error(
|
const executionId = uuidv4();
|
||||||
error,
|
|
||||||
`[Shard ${queue.metadata.client.shard.ids[0]}] player.events.on('error'): Player queue encountered error event`
|
const logger = require('../../services/logger').child({
|
||||||
);
|
source: 'generalError.js',
|
||||||
|
module: 'event',
|
||||||
|
name: 'generalError',
|
||||||
|
executionId: executionId,
|
||||||
|
shardId: queue.metadata.client.shard.ids[0],
|
||||||
|
guildId: queue.metadata.channel.guild.id
|
||||||
|
});
|
||||||
|
|
||||||
|
logger.error(error, 'player.events.on(\'error\'): Player queue encountered error event');
|
||||||
|
|
||||||
await queue.metadata.channel.send({
|
await queue.metadata.channel.send({
|
||||||
embeds: [
|
embeds: [
|
||||||
@@ -33,7 +41,7 @@ module.exports = {
|
|||||||
embeds: [
|
embeds: [
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setDescription(
|
.setDescription(
|
||||||
`${embedOptions.icons.error} **player.events.on('error')**\n${error.message}` +
|
`${embedOptions.icons.error} **player.events.on('error')**\nExecution id: ${executionId}\n${error.message}` +
|
||||||
`\n\n<@${systemOptions.systemUserId}>`
|
`\n\n<@${systemOptions.systemUserId}>`
|
||||||
)
|
)
|
||||||
.setColor(embedOptions.colors.error)
|
.setColor(embedOptions.colors.error)
|
||||||
@@ -41,7 +49,5 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
process.env.NODE_ENV === 'development' ? logger.trace(queue, 'Queue object') : null;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
const logger = require('../../services/logger');
|
|
||||||
const config = require('config');
|
const config = require('config');
|
||||||
const embedOptions = config.get('embedOptions');
|
const embedOptions = config.get('embedOptions');
|
||||||
const botOptions = config.get('botOptions');
|
const botOptions = config.get('botOptions');
|
||||||
const systemOptions = config.get('systemOptions');
|
const systemOptions = config.get('systemOptions');
|
||||||
const { EmbedBuilder } = require('discord.js');
|
const { EmbedBuilder } = require('discord.js');
|
||||||
|
const { v4: uuidv4 } = require('uuid');
|
||||||
|
|
||||||
// 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 = {
|
||||||
@@ -11,10 +11,18 @@ module.exports = {
|
|||||||
isDebug: false,
|
isDebug: false,
|
||||||
isPlayerEvent: true,
|
isPlayerEvent: true,
|
||||||
execute: async (queue, error) => {
|
execute: async (queue, error) => {
|
||||||
logger.error(
|
const executionId = uuidv4();
|
||||||
error,
|
|
||||||
`[Shard ${queue.metadata.client.shard.ids[0]}] player.events.on('playerError'): Player error while streaming track`
|
const logger = require('../../services/logger').child({
|
||||||
);
|
source: 'playerError.js',
|
||||||
|
module: 'event',
|
||||||
|
name: 'playerError',
|
||||||
|
executionId: executionId,
|
||||||
|
shardId: queue.metadata.client.shard.ids[0],
|
||||||
|
guildId: queue.metadata.channel.guild.id
|
||||||
|
});
|
||||||
|
|
||||||
|
logger.error(error, 'player.events.on(\'playerError\'): Player error while streaming track');
|
||||||
|
|
||||||
await queue.metadata.channel.send({
|
await queue.metadata.channel.send({
|
||||||
embeds: [
|
embeds: [
|
||||||
@@ -33,7 +41,7 @@ module.exports = {
|
|||||||
embeds: [
|
embeds: [
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setDescription(
|
.setDescription(
|
||||||
`${embedOptions.icons.error} **player.events.on('playerError')**\n${error.message}` +
|
`${embedOptions.icons.error} **player.events.on('playerError')**\nExecution id: ${executionId}\n${error.message}` +
|
||||||
`\n\n<@${systemOptions.systemUserId}>`
|
`\n\n<@${systemOptions.systemUserId}>`
|
||||||
)
|
)
|
||||||
.setColor(embedOptions.colors.error)
|
.setColor(embedOptions.colors.error)
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
const logger = require('../../services/logger');
|
|
||||||
const config = require('config');
|
const config = require('config');
|
||||||
const embedOptions = config.get('embedOptions');
|
const embedOptions = config.get('embedOptions');
|
||||||
const botOptions = config.get('botOptions');
|
const botOptions = config.get('botOptions');
|
||||||
const systemOptions = config.get('systemOptions');
|
const systemOptions = config.get('systemOptions');
|
||||||
const { EmbedBuilder } = require('discord.js');
|
const { EmbedBuilder } = require('discord.js');
|
||||||
|
const { v4: uuidv4 } = require('uuid');
|
||||||
|
|
||||||
// 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 = {
|
||||||
@@ -11,9 +11,18 @@ module.exports = {
|
|||||||
isDebug: false,
|
isDebug: false,
|
||||||
isPlayerEvent: true,
|
isPlayerEvent: true,
|
||||||
execute: async (queue, track) => {
|
execute: async (queue, track) => {
|
||||||
logger.error(
|
const executionId = uuidv4();
|
||||||
`[Shard ${queue.metadata.client.shard.ids[0]}] player.events.on('playerSkip'): Failed to play '${track.url}'.`
|
|
||||||
);
|
const logger = require('../../services/logger').child({
|
||||||
|
source: 'playerSkip.js',
|
||||||
|
module: 'event',
|
||||||
|
name: 'playerSkip',
|
||||||
|
executionId: executionId,
|
||||||
|
shardId: queue.metadata.client.shard.ids[0],
|
||||||
|
guildId: queue.metadata.channel.guild.id
|
||||||
|
});
|
||||||
|
|
||||||
|
logger.error(`player.events.on('playerSkip'): Failed to play '${track.url}'.`);
|
||||||
|
|
||||||
await queue.metadata.channel.send({
|
await queue.metadata.channel.send({
|
||||||
embeds: [
|
embeds: [
|
||||||
@@ -32,7 +41,7 @@ module.exports = {
|
|||||||
embeds: [
|
embeds: [
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setDescription(
|
.setDescription(
|
||||||
`${embedOptions.icons.error} **player.events.on('playerSkip')**\n${track.url}` +
|
`${embedOptions.icons.error} **player.events.on('playerSkip')**\nExecution id: ${executionId}\n${track.url}` +
|
||||||
`\n\n<@${systemOptions.systemUserId}>`
|
`\n\n<@${systemOptions.systemUserId}>`
|
||||||
)
|
)
|
||||||
.setColor(embedOptions.colors.error)
|
.setColor(embedOptions.colors.error)
|
||||||
|
|||||||
@@ -1,13 +1,22 @@
|
|||||||
const logger = require('../../services/logger');
|
const { v4: uuidv4 } = require('uuid');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'playerStart',
|
name: 'playerStart',
|
||||||
isDebug: false,
|
isDebug: false,
|
||||||
isPlayerEvent: true,
|
isPlayerEvent: true,
|
||||||
execute: async (queue, track) => {
|
execute: async (queue, track) => {
|
||||||
logger.debug(
|
const executionId = uuidv4();
|
||||||
`[Shard ${queue.metadata.client.shard.ids[0]}] playerStart event: Started playing '${track.raw.url}'.`
|
|
||||||
);
|
const logger = require('../../services/logger').child({
|
||||||
|
source: 'playerStart.js',
|
||||||
|
module: 'event',
|
||||||
|
name: 'playerStart',
|
||||||
|
executionId: executionId,
|
||||||
|
shardId: queue.metadata.client.shard.ids[0],
|
||||||
|
guildId: queue.metadata.channel.guild.id
|
||||||
|
});
|
||||||
|
|
||||||
|
logger.debug(`playerStart event: Started playing '${track.url}'.`);
|
||||||
process.env.NODE_ENV === 'development' ? logger.trace(queue) : null;
|
process.env.NODE_ENV === 'development' ? logger.trace(queue) : null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
+14
-2
@@ -1,7 +1,7 @@
|
|||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
const shardingOptions = require('config').get('shardingOptions');
|
const shardingOptions = require('config').get('shardingOptions');
|
||||||
const logger = require('./services/logger');
|
|
||||||
const { ShardingManager, ShardEvents } = require('discord.js');
|
const { ShardingManager, ShardEvents } = require('discord.js');
|
||||||
|
const { v4: uuidv4 } = require('uuid');
|
||||||
|
|
||||||
const manager = new ShardingManager('./src/bot.js', {
|
const manager = new ShardingManager('./src/bot.js', {
|
||||||
token: process.env.DISCORD_BOT_TOKEN,
|
token: process.env.DISCORD_BOT_TOKEN,
|
||||||
@@ -9,14 +9,26 @@ const manager = new ShardingManager('./src/bot.js', {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const readyShards = new Set();
|
const readyShards = new Set();
|
||||||
|
|
||||||
manager.on('shardCreate', (shard) => {
|
manager.on('shardCreate', (shard) => {
|
||||||
logger.info(`[Shard ${shard.id}] Launched shard with id ${shard.id}.`);
|
const executionId = uuidv4();
|
||||||
|
|
||||||
|
const logger = require('./services/logger').child({
|
||||||
|
source: 'index.js',
|
||||||
|
module: 'shardingManager',
|
||||||
|
name: 'shardingManager',
|
||||||
|
executionId: executionId,
|
||||||
|
shardId: 'manager'
|
||||||
|
});
|
||||||
|
|
||||||
|
logger.info(`Launched shard with id ${shard.id}.`);
|
||||||
|
|
||||||
// When all shards are ready, emit event 'allShardsReady' to all shards
|
// When all shards are ready, emit event 'allShardsReady' to all shards
|
||||||
shard.on(ShardEvents.Ready, () => {
|
shard.on(ShardEvents.Ready, () => {
|
||||||
readyShards.add(shard.id);
|
readyShards.add(shard.id);
|
||||||
if (readyShards.size === manager.totalShards) {
|
if (readyShards.size === manager.totalShards) {
|
||||||
manager.broadcastEval((client) => client.emit('allShardsReady'));
|
manager.broadcastEval((client) => client.emit('allShardsReady'));
|
||||||
|
logger.info('All shards ready, bot is now online.');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,9 +1,16 @@
|
|||||||
const logger = require('../../services/logger');
|
|
||||||
const Discord = require('discord.js');
|
const Discord = require('discord.js');
|
||||||
|
|
||||||
exports.createClient = async () => {
|
exports.createClient = async ({ executionId }) => {
|
||||||
|
const logger = require('../../services/logger').child({
|
||||||
|
source: 'createPlayer.js',
|
||||||
|
module: 'utilFactory',
|
||||||
|
name: 'createPlayer',
|
||||||
|
executionId: executionId,
|
||||||
|
shardId: 'client'
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logger.debug('Creating Discord.js client...');
|
logger.debug('Creating discord.js client...');
|
||||||
|
|
||||||
const client = new Discord.Client({
|
const client = new Discord.Client({
|
||||||
intents: [Discord.GatewayIntentBits.Guilds, Discord.GatewayIntentBits.GuildVoiceStates],
|
intents: [Discord.GatewayIntentBits.Guilds, Discord.GatewayIntentBits.GuildVoiceStates],
|
||||||
@@ -33,7 +40,7 @@ exports.createClient = async () => {
|
|||||||
|
|
||||||
return client;
|
return client;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to create Discord.js client', error);
|
logger.error(error, 'Failed to create discord.js client');
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -1,9 +1,16 @@
|
|||||||
const logger = require('../../services/logger');
|
|
||||||
const { Player } = require('discord-player');
|
const { Player } = require('discord-player');
|
||||||
|
|
||||||
exports.createPlayer = async (client) => {
|
exports.createPlayer = async ({ client, executionId }) => {
|
||||||
|
const logger = require('../../services/logger').child({
|
||||||
|
source: 'createPlayer.js',
|
||||||
|
module: 'utilFactory',
|
||||||
|
name: 'createPlayer',
|
||||||
|
executionId: executionId,
|
||||||
|
shardId: client.shard.ids[0]
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logger.debug(`[Shard ${client.shard.ids[0]}] Creating discord-player player...`);
|
logger.debug('Creating discord-player player...');
|
||||||
|
|
||||||
const player = new Player(client, {
|
const player = new Player(client, {
|
||||||
useLegacyFFmpeg: false,
|
useLegacyFFmpeg: false,
|
||||||
@@ -23,11 +30,11 @@ exports.createPlayer = async (client) => {
|
|||||||
global.player = player;
|
global.player = player;
|
||||||
|
|
||||||
await player.extractors.loadDefault();
|
await player.extractors.loadDefault();
|
||||||
logger.trace(`[Shard ${client.shard.ids[0]}] discord-player loaded dependencies:\n${player.scanDeps()}`);
|
logger.trace(`discord-player loaded dependencies:\n${player.scanDeps()}`);
|
||||||
|
|
||||||
return player;
|
return player;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`[Shard ${client.shard.ids[0]}] Failed to create discord-player player`, error);
|
logger.error(error, 'Failed to create discord-player player');
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -1,22 +1,25 @@
|
|||||||
const logger = require('../../services/logger');
|
|
||||||
const https = require('node:https');
|
const https = require('node:https');
|
||||||
|
|
||||||
exports.postBotStats = async (client) => {
|
exports.postBotStats = async ({ client, executionId }) => {
|
||||||
|
const logger = require('../../services/logger').child({
|
||||||
|
source: 'postBotStats.js',
|
||||||
|
module: 'utilOther',
|
||||||
|
name: 'postBotStats',
|
||||||
|
executionId: executionId,
|
||||||
|
shardId: client.shard.ids[0]
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (client.shard.ids[0] !== 0) {
|
if (client.shard.ids[0] !== 0) {
|
||||||
return logger.debug(`[Shard ${client.shard.ids[0]}] Shard is not the first shard, not posting stats.`);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(
|
|
||||||
client.shard.ids,
|
|
||||||
`[Shard ${client.shard.ids[0]}] Posting stats to bot lists from client with shard id 0.`
|
|
||||||
);
|
|
||||||
|
|
||||||
let guildCount = 0;
|
let guildCount = 0;
|
||||||
let memberCount = 0;
|
let memberCount = 0;
|
||||||
let shardCount = client.shard.count;
|
let shardCount = client.shard.count;
|
||||||
let shardId = client.shard.ids[0];
|
let shardId = client.shard.ids[0];
|
||||||
|
|
||||||
|
logger.debug('Gathering data about guild and member count from shards...');
|
||||||
await client.shard
|
await client.shard
|
||||||
.fetchClientValues('guilds.cache')
|
.fetchClientValues('guilds.cache')
|
||||||
.then((results) => {
|
.then((results) => {
|
||||||
@@ -26,9 +29,11 @@ exports.postBotStats = async (client) => {
|
|||||||
memberCount += guildCache.reduce((acc, guildCache) => acc + guildCache.memberCount, 0);
|
memberCount += guildCache.reduce((acc, guildCache) => acc + guildCache.memberCount, 0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
logger.debug('Successfully fetched client values from shards');
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
logger.error(error, `[Shard ${client.shard.ids[0]}] Failed to fetch client values from shards.`);
|
logger.error(error, 'Failed to fetch client values from shards.');
|
||||||
});
|
});
|
||||||
|
|
||||||
/* eslint-disable camelcase */
|
/* eslint-disable camelcase */
|
||||||
@@ -112,7 +117,10 @@ exports.postBotStats = async (client) => {
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
logger.info(`[Shard ${client.shard.ids[0]}] Posting stats to bot lists with guildCount ${guildCount}...`);
|
logger.info(`Starting to post bot stats with guild count ${guildCount} and member count ${memberCount}...`);
|
||||||
|
|
||||||
|
let statusCodes = [];
|
||||||
|
|
||||||
sites.map((site) => {
|
sites.map((site) => {
|
||||||
if (site.disabled) {
|
if (site.disabled) {
|
||||||
return;
|
return;
|
||||||
@@ -132,14 +140,18 @@ exports.postBotStats = async (client) => {
|
|||||||
|
|
||||||
let request = https.request(options, (res) => {
|
let request = https.request(options, (res) => {
|
||||||
res.statusCode === 200
|
res.statusCode === 200
|
||||||
? logger.info(`Request to ${site.hostname}: statusCode: ${res.statusCode}`)
|
? logger.debug(`Request to ${site.hostname}: statusCode: ${res.statusCode}`)
|
||||||
: logger.warn(`Request to ${site.hostname}: statusCode: ${res.statusCode}`);
|
: logger.warn(`Request to ${site.hostname}: statusCode: ${res.statusCode}`);
|
||||||
|
|
||||||
|
statusCodes.push(res.statusCode);
|
||||||
});
|
});
|
||||||
|
|
||||||
request.write(JSON.stringify(site.body));
|
request.write(JSON.stringify(site.body));
|
||||||
request.end();
|
request.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
logger.info(`Successfully posted bot stats with status codes ${statusCodes.join(', ')}.`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error, `[Shard ${client.shard.ids[0]}] Failed to post stats to bot lists.`);
|
logger.error(error, 'Failed to post bot stats to sites.');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -1,15 +1,23 @@
|
|||||||
const logger = require('../../services/logger');
|
|
||||||
const config = require('config');
|
const config = require('config');
|
||||||
const loadTestOptions = config.get('loadTestOptions');
|
const loadTestOptions = config.get('loadTestOptions');
|
||||||
|
|
||||||
exports.startLoadTest = async (client) => {
|
exports.startLoadTest = async ({ client, executionId }) => {
|
||||||
|
const logger = require('../../services/logger').child({
|
||||||
|
source: 'startLoadTest.js',
|
||||||
|
module: 'utilOther',
|
||||||
|
name: 'loadTest',
|
||||||
|
executionId: executionId,
|
||||||
|
shardId: client.shard.ids[0]
|
||||||
|
});
|
||||||
|
|
||||||
if (!loadTestOptions.enabled) {
|
if (!loadTestOptions.enabled) {
|
||||||
|
logger.debug('Load test is disabled in options, cancelling.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const channelIds = loadTestOptions.channelIdsToJoin;
|
const channelIds = loadTestOptions.channelIdsToJoin;
|
||||||
const track = loadTestOptions.trackUrl;
|
const track = loadTestOptions.trackUrl;
|
||||||
logger.info(`Starting load test in ${channelIds.length} channels.`);
|
logger.info(`Starting load test in ${channelIds.length} specified channels.`);
|
||||||
|
|
||||||
channelIds.forEach((each) => {
|
channelIds.forEach((each) => {
|
||||||
client.shard.broadcastEval(
|
client.shard.broadcastEval(
|
||||||
|
|||||||
@@ -1,15 +1,22 @@
|
|||||||
const logger = require('../services/logger');
|
|
||||||
const fs = require('node:fs');
|
const fs = require('node:fs');
|
||||||
const path = require('node:path');
|
const path = require('node:path');
|
||||||
const { Collection } = require('discord.js');
|
const { Collection } = require('discord.js');
|
||||||
|
|
||||||
exports.registerClientCommands = (client) => {
|
exports.registerClientCommands = ({ client, executionId }) => {
|
||||||
logger.debug(`[Shard ${client.shard.ids[0]}] Registering client commands...`);
|
const logger = require('../services/logger').child({
|
||||||
|
source: 'registerClientCommands.js',
|
||||||
|
module: 'register',
|
||||||
|
name: 'registerClientCommands',
|
||||||
|
executionId: executionId,
|
||||||
|
shardId: client.shard.ids[0]
|
||||||
|
});
|
||||||
|
|
||||||
|
logger.debug('Registering client commands...');
|
||||||
client.commands = new Collection();
|
client.commands = new Collection();
|
||||||
|
|
||||||
const commandFolders = fs.readdirSync(path.resolve('./src/commands'));
|
const commandFolders = fs.readdirSync(path.resolve('./src/commands'));
|
||||||
for (const folder of commandFolders) {
|
for (const folder of commandFolders) {
|
||||||
logger.trace(`[Shard ${client.shard.ids[0]}] Registering client commands for folder '${folder}'...`);
|
logger.trace(`Registering client commands for folder '${folder}'...`);
|
||||||
const commandFiles = fs
|
const commandFiles = fs
|
||||||
.readdirSync(path.resolve(`./src/commands/${folder}`))
|
.readdirSync(path.resolve(`./src/commands/${folder}`))
|
||||||
.filter((file) => file.endsWith('.js'));
|
.filter((file) => file.endsWith('.js'));
|
||||||
@@ -24,12 +31,10 @@ exports.registerClientCommands = (client) => {
|
|||||||
client.commands.delete(command.data.name);
|
client.commands.delete(command.data.name);
|
||||||
client.commands.set(command.data.name, command);
|
client.commands.set(command.data.name, command);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(
|
logger.error(`Error registering command ${folder}/${file}: ${error.message}`);
|
||||||
`[Shard ${client.shard.ids[0]}] Error registering command ${folder}/${file}: ${error.message}`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.trace(`[Shard ${client.shard.ids[0]}] Registering client commands complete.`);
|
logger.trace('Registering client commands complete.');
|
||||||
};
|
};
|
||||||
@@ -1,16 +1,23 @@
|
|||||||
const logger = require('../services/logger');
|
|
||||||
const fs = require('node:fs');
|
const fs = require('node:fs');
|
||||||
const path = require('node:path');
|
const path = require('node:path');
|
||||||
const config = require('config');
|
const config = require('config');
|
||||||
|
|
||||||
const loggerOptions = config.get('loggerOptions');
|
const loggerOptions = config.get('loggerOptions');
|
||||||
|
|
||||||
exports.registerEventListeners = (client, player) => {
|
exports.registerEventListeners = ({ client, player, executionId }) => {
|
||||||
logger.debug(`[Shard ${client.shard.ids[0]}] Registering event listeners...`);
|
const logger = require('../services/logger').child({
|
||||||
|
source: 'registerEventListeners.js',
|
||||||
|
module: 'register',
|
||||||
|
name: 'registerEventListeners',
|
||||||
|
executionId: executionId,
|
||||||
|
shardId: client.shard.ids[0]
|
||||||
|
});
|
||||||
|
|
||||||
|
logger.debug('Registering event listeners...');
|
||||||
|
|
||||||
const eventFolders = fs.readdirSync(path.resolve('./src/events'));
|
const eventFolders = fs.readdirSync(path.resolve('./src/events'));
|
||||||
for (const folder of eventFolders) {
|
for (const folder of eventFolders) {
|
||||||
logger.trace(`[Shard ${client.shard.ids[0]}] Registering event listener for folder '${folder}'...`);
|
logger.trace(`Registering event listener for folder '${folder}'...`);
|
||||||
|
|
||||||
const eventFiles = fs
|
const eventFiles = fs
|
||||||
.readdirSync(path.resolve(`./src/events/${folder}`))
|
.readdirSync(path.resolve(`./src/events/${folder}`))
|
||||||
@@ -52,12 +59,10 @@ exports.registerEventListeners = (client, player) => {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
logger.error(
|
logger.error(`Unknown event folder '${folder}' while trying to register events.`);
|
||||||
`[Shard ${client.shard.ids[0]}] Unknown event folder '${folder}' while trying to register events.`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.trace(`[Shard ${client.shard.ids[0]}] Registering event listeners complete.`);
|
logger.trace('Registering event listeners complete.');
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user