diff --git a/src/config_example.js b/src/config_example.js index 75e190f7..4a2335d1 100644 --- a/src/config_example.js +++ b/src/config_example.js @@ -184,3 +184,10 @@ module.exports.ffmpegFilterOptions = { } ] }; + +// Options for load testing the bot. If enabled, the bot will join the specified channels and play specified track source. +module.exports.loadTestOptions = { + enabled: false, + trackUrl: 'https://www.youtube.com/watch?v=tTR4D9h3zAE', + channelIdsToJoin: [] +}; diff --git a/src/events/client/ready.js b/src/events/client/ready.js index a9712bdd..b3776285 100644 --- a/src/events/client/ready.js +++ b/src/events/client/ready.js @@ -1,6 +1,7 @@ const logger = require('../../services/logger'); -const { embedOptions, systemOptions, presenceStatusOptions } = require('../../config'); +const { embedOptions, systemOptions, presenceStatusOptions, loadTestOptions } = require('../../config'); const { postBotStats } = require('../../utils/other/postBotStats.js'); +const { startLoadTest } = require('../../utils/other/startLoadTest'); const { Events, EmbedBuilder } = require('discord.js'); module.exports = { @@ -12,6 +13,10 @@ module.exports = { await client.user.setPresence(presenceStatusOptions); await client.user.setPresence(presenceStatusOptions); + if (loadTestOptions.enabled) { + await startLoadTest(client); + } + const channel = await client.channels.cache.get(systemOptions.systemMessageChannelId); // Check if the channel exists in curent shard and send a message diff --git a/src/index.js b/src/index.js index f72ad46b..bddd97db 100644 --- a/src/index.js +++ b/src/index.js @@ -10,7 +10,7 @@ const manager = new ShardingManager('./src/bot.js', { const readyShards = new Set(); manager.on('shardCreate', (shard) => { - logger.debug(`[Shard ${shard.id}] Launched shard with id ${shard.id}.`); + logger.info(`[Shard ${shard.id}] Launched shard with id ${shard.id}.`); // When all shards are ready, emit event 'allShardsReady' to all shards shard.on(ShardEvents.Ready, () => { diff --git a/src/utils/factory/createPlayer.js b/src/utils/factory/createPlayer.js index 0c5813c1..bf4881a0 100644 --- a/src/utils/factory/createPlayer.js +++ b/src/utils/factory/createPlayer.js @@ -39,7 +39,7 @@ exports.createPlayer = async (client) => { }); await player.extractors.loadDefault(); - logger.debug(`[Shard ${client.shard.ids[0]}] discord-player loaded dependencies:\n${player.scanDeps()}`); + logger.trace(`[Shard ${client.shard.ids[0]}] discord-player loaded dependencies:\n${player.scanDeps()}`); return player; } catch (error) { diff --git a/src/utils/other/startLoadTest.js b/src/utils/other/startLoadTest.js new file mode 100644 index 00000000..2ddbf744 --- /dev/null +++ b/src/utils/other/startLoadTest.js @@ -0,0 +1,35 @@ +const logger = require('../../services/logger'); +const { loadTestOptions } = require('../../config'); + +exports.startLoadTest = async (client) => { + if (!loadTestOptions.enabled) { + return; + } + + const channelIds = loadTestOptions.channelIdsToJoin; + const track = loadTestOptions.trackUrl; + logger.info(`Starting load test in ${channelIds.length} channels.`); + + channelIds.forEach((each) => { + client.shard.broadcastEval( + async (shardClient, { channelId, track }) => { + const channel = shardClient.channels.cache.get(channelId); + if (channel) { + /* eslint-disable no-undef */ + await player.play(channel.id, track, { + nodeOptions: { + leaveOnEmpty: false, + leaveOnEnd: false, + leaveOnStop: false, + metadata: { + channel: channel, + client: shardClient + } + } + }); + } + }, + { context: { channelId: each, track: track } } + ); + }); +};