mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-02 14:38:49 +00:00
feat: Update shards command
This commit is contained in:
1 parent
173b234b0d
commit
825db5ea5a
1 file changed
+50
-15
@@ -12,7 +12,14 @@ module.exports = {
|
||||
.setName('shards')
|
||||
.setDescription('Show information about the running shards.')
|
||||
.setDMPermission(false)
|
||||
.setNSFW(false),
|
||||
.setNSFW(false)
|
||||
.addBooleanOption((option) =>
|
||||
option
|
||||
.setName('sort')
|
||||
.setDescription('Whether or not to sort by most active voice connections.')
|
||||
.setRequired(false)
|
||||
)
|
||||
.addNumberOption((option) => option.setName('page').setDescription('Page number to show').setMinValue(1)),
|
||||
execute: async ({ interaction, client }) => {
|
||||
if (await notValidGuildId(interaction)) {
|
||||
return;
|
||||
@@ -39,31 +46,59 @@ module.exports = {
|
||||
})
|
||||
.then((results) => {
|
||||
shardInfoList = results;
|
||||
const sortByActiveConnections = interaction.options.getBoolean('sort', false);
|
||||
if (sortByActiveConnections) {
|
||||
shardInfoList = shardInfoList.sort(
|
||||
(a, b) => b.playerStatistics.activeVoiceConnections - a.playerStatistics.activeVoiceConnections
|
||||
);
|
||||
}
|
||||
logger.debug(results, `[Shard ${client.shard.ids[0]}] Fetched shardInfo from each shard.`);
|
||||
})
|
||||
.catch((error) => {
|
||||
logger.error(error, `[Shard ${client.shard.ids[0]}] Failed to fetch client values from shards.`);
|
||||
});
|
||||
|
||||
systemStatusString = shardInfoList
|
||||
.map((shardInfo) => {
|
||||
string = '';
|
||||
string += `**Shard id:** \`${shardInfo.shardId}\`\n`;
|
||||
string += `**Guild count:** \`${shardInfo.guildCount}\`\n`;
|
||||
string += `**Guild member count:** \`${shardInfo.guildMemberCount}\`\n`;
|
||||
string += `**Active voice connections:** \`${shardInfo.playerStatistics.activeVoiceConnections}\`\n`;
|
||||
string += `**Total tracks:** \`${shardInfo.playerStatistics.totalTracks}\`\n`;
|
||||
string += `**Total listeners:** \`${shardInfo.playerStatistics.totalListeners}\`\n`;
|
||||
return string;
|
||||
})
|
||||
.join('\n');
|
||||
const shardCount = shardInfoList.length;
|
||||
const totalPages = Math.ceil(shardCount / 10) || 1;
|
||||
const pageIndex = (interaction.options.getNumber('page') || 1) - 1;
|
||||
|
||||
const currentPageShards = shardInfoList.slice(pageIndex * 10, pageIndex * 10 + 10);
|
||||
|
||||
const evenShardIndexes = currentPageShards.filter((shard, index) => index % 2 === 0);
|
||||
const oddShardIndexes = currentPageShards.filter((shard, index) => index % 2 !== 0);
|
||||
|
||||
function shardInfoToString(shard) {
|
||||
let string = '';
|
||||
string += `**Shard ${shard.shardId}** - Guilds: ${shard.guildCount.toLocaleString(
|
||||
'en-US'
|
||||
)} (${shard.guildMemberCount.toLocaleString('en-US')})\n`;
|
||||
string += `**┗** Connections: ${shard.playerStatistics.activeVoiceConnections.toLocaleString('en-US')}\n`;
|
||||
string += `**┗** Tracks: ${shard.playerStatistics.totalTracks.toLocaleString('en-US')}\n`;
|
||||
string += `**┗** Listeners: ${shard.playerStatistics.totalListeners.toLocaleString('en-US')}\n`;
|
||||
return string;
|
||||
}
|
||||
|
||||
const evenShardIndexesString = evenShardIndexes.map(shardInfoToString).join('\n') + 'ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ';
|
||||
const oddShardIndexesString = oddShardIndexes.map(shardInfoToString).join('\n');
|
||||
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setDescription(`**${embedOptions.icons.server} Shards overview**\n` + systemStatusString)
|
||||
.setDescription(`**${embedOptions.icons.server} Shard overview - ${shardCount} total shards**\n`)
|
||||
.addFields(
|
||||
{
|
||||
name: ' ',
|
||||
value: evenShardIndexesString,
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: ' ',
|
||||
value: oddShardIndexesString,
|
||||
inline: true
|
||||
}
|
||||
)
|
||||
.setColor(embedOptions.colors.info)
|
||||
.setFooter({ text: `Shard id for this guild: ${client.shard.ids[0]}` })
|
||||
.setFooter({ text: `Shard id: ${client.shard.ids[0]}, page ${pageIndex + 1} of ${totalPages}` })
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user