mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-02 22:16:13 +00:00
Merge pull request #120 from mariusbegby/load-test-functionality
Added options for load testing to automatically play music in specified channels
This commit is contained in:
5 files changed
+50
-3
No files matched your search
@@ -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: []
|
||||
};
|
||||
@@ -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
@@ -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, () => {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 } }
|
||||
);
|
||||
});
|
||||
};
|
||||
Reference in new issue
Block a user