feat: Added options for load testing to automatically play music in specified channels

This commit is contained in:
Marius Begby committed 2023-07-25 13:17:52 +02:00
1 parent 771429b595
commit 8e04d59a6a
5 files changed
+50 -3

No files matched your search

+7
View File
@@ -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: []
};
+6 -1
View File
@@ -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
+1 -1
View File
@@ -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, () => {
+1 -1
View File
@@ -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) {
+35
View File
@@ -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 } }
);
});
};