fix: annotated system commands

This commit is contained in:
Marius Begby committed 2023-08-27 13:28:29 +02:00
1 parent f4f418292a
commit 0bdc5501be
9 files changed
+96 -40

No files matched your search

+1 -1
View File
@@ -1,5 +1,5 @@
import config from 'config';
import { EmbedOptions } from '../../types/configTypes';
import { EmbedOptions, FFmpegFilterOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions');
const ffmpegFilterOptions: FFmpegFilterOptions = config.get('ffmpegFilterOptions');
import { notInVoiceChannel, notInSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
+7 -7
View File
@@ -138,8 +138,8 @@ module.exports = {
queue.repeatMode === 0
? ''
: `**${
queue.repeatMode === 3 ? embedOptions.icons.autoplay : embedOptions.icons.loop
} Looping**\nLoop mode is set to ${loopModeUserString}. You can change it with **\`/loop\`**.`
queue.repeatMode === 3 ? embedOptions.icons.autoplay : embedOptions.icons.loop
} Looping**\nLoop mode is set to ${loopModeUserString}. You can change it with **\`/loop\`**.`
}`
)
.addFields(
@@ -170,7 +170,7 @@ module.exports = {
components: [nowPlayingActionRow]
});
logger.debug(`User used command '${interaction.commandName}', finished sending response.`);
logger.debug('Finished sending response.');
const collectorFilter = (i) => i.user.id === interaction.user.id;
try {
@@ -249,10 +249,10 @@ module.exports = {
queue.repeatMode === 0
? ''
: `\n\n**${
queue.repeatMode === 3
? embedOptions.icons.autoplaying
: embedOptions.icons.looping
} Looping**\nLoop mode is set to ${repeatModeUserString}. You can change it with **\`/loop\`**.`
queue.repeatMode === 3
? embedOptions.icons.autoplaying
: embedOptions.icons.looping
} Looping**\nLoop mode is set to ${repeatModeUserString}. You can change it with **\`/loop\`**.`
}`
)
.setThumbnail(skippedTrack.thumbnail)
+10 -5
View File
@@ -2,7 +2,7 @@ import config from 'config';
import { EmbedOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions');
import { notValidGuildId } from '../../utils/validation/systemCommandValidator';
import{ SlashCommandBuilder, EmbedBuilder } from 'discord.js';
import { SlashCommandBuilder, EmbedBuilder, Guild } from 'discord.js';
import loggerModule from '../../services/logger';
import { CommandParams } from '../../types/commandTypes';
@@ -21,17 +21,22 @@ module.exports = {
module: 'slashCommand',
name: '/guilds',
executionId: executionId,
shardId: interaction.guild.shardId,
guildId: interaction.guild.id
shardId: interaction.guild?.shardId,
guildId: interaction.guild?.id
});
if (await notValidGuildId({ interaction, executionId })) {
return;
}
let shardGuilds = [];
let shardGuilds: Guild[] = [];
let totalGuildCount = 0;
if (!client || !client.shard) {
logger.error('Client is undefined or does not have shard property.');
return;
}
logger.debug('Fetching guilds from all shards.');
await client.shard
.broadcastEval((c) => {
@@ -40,7 +45,7 @@ module.exports = {
});
})
.then((guilds) => {
shardGuilds = guilds.flat(1);
shardGuilds = guilds.flat(1) as Guild[];
});
totalGuildCount = shardGuilds.length;
+16 -6
View File
@@ -2,9 +2,10 @@ import config from 'config';
import { EmbedOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions');
import { notValidGuildId } from '../../utils/validation/systemCommandValidator';
import{ SlashCommandBuilder, EmbedBuilder } from 'discord.js';
import { SlashCommandBuilder, EmbedBuilder } from 'discord.js';
import loggerModule from '../../services/logger';
import { CommandParams } from '../../types/commandTypes';
import { ExtendedClient } from '../../types/clientTypes';
module.exports = {
isSystemCommand: true,
@@ -21,19 +22,28 @@ module.exports = {
module: 'slashCommand',
name: '/reload',
executionId: executionId,
shardId: interaction.guild.shardId,
guildId: interaction.guild.id
shardId: interaction.guild?.shardId,
guildId: interaction.guild?.id
});
if (await notValidGuildId({ interaction, executionId })) {
return;
}
if (!client || !client.shard) {
logger.error('Client is undefined or does not have shard property.');
return;
}
try {
logger.debug('Reloading commands across all shards.');
await client.shard
.broadcastEval(
async (shardClient, { executionId }) => {
async (shardClient: ExtendedClient, { executionId }) => {
if (!shardClient.registerClientCommands) {
return;
}
shardClient.registerClientCommands({ client: shardClient, executionId });
},
{ context: { executionId: executionId } }
@@ -58,12 +68,12 @@ module.exports = {
});
}
const commands = client.commands.map((command) => {
const commands = client.commands?.map((command) => {
const params = command.data.options[0] ? `**\`${command.data.options[0].name}\`**` + ' ' : '';
return `- **\`/${command.data.name}\`** ${params}- ${command.data.description}`;
});
const embedDescription = `**${embedOptions.icons.bot} Reloaded commands**\n` + commands.join('\n');
const embedDescription = `**${embedOptions.icons.bot} Reloaded commands**\n` + commands?.join('\n');
logger.debug('Responding with success embed.');
return await interaction.editReply({
+22 -9
View File
@@ -2,9 +2,10 @@ import config from 'config';
import { EmbedOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions');
import { notValidGuildId } from '../../utils/validation/systemCommandValidator';
import{ SlashCommandBuilder, EmbedBuilder } from 'discord.js';
import { SlashCommandBuilder, EmbedBuilder } from 'discord.js';
import loggerModule from '../../services/logger';
import { CommandParams } from '../../types/commandTypes';
import { CommandParams, ShardInfo } from '../../types/commandTypes';
import { ExtendedClient } from '../../types/clientTypes';
module.exports = {
isSystemCommand: true,
@@ -38,23 +39,35 @@ module.exports = {
module: 'slashCommand',
name: '/shards',
executionId: executionId,
shardId: interaction.guild.shardId,
guildId: interaction.guild.id
shardId: interaction.guild?.shardId,
guildId: interaction.guild?.id
});
if (await notValidGuildId({ interaction, executionId })) {
return;
}
let shardInfoList = [];
let shardInfoList: ShardInfo[] = [];
if (!client || !client.shard) {
logger.error('Client is undefined or does not have shard property.');
return;
}
logger.debug('Fetching player statistics and client values from each shard.');
try {
await client.shard
.broadcastEval((shardClient) => {
.broadcastEval((shardClient: ExtendedClient) => {
if (!shardClient.shard) {
return;
}
/* eslint-disable no-undef */
const playerStats = player.generateStatistics();
const nodeProcessMemUsageInMb = (process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2);
const nodeProcessMemUsageInMb = parseFloat(
(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2)
);
const shardInfo = {
shardId: shardClient.shard.ids[0],
memUsage: nodeProcessMemUsageInMb,
@@ -70,7 +83,7 @@ module.exports = {
return shardInfo;
})
.then((results) => {
shardInfoList = results;
shardInfoList = results.filter(Boolean) as ShardInfo[];
switch (interaction.options.getString('sort')) {
case 'memory':
@@ -132,7 +145,7 @@ module.exports = {
const evenShardIndexes = currentPageShards.filter((shard, index) => index % 2 === 0);
const oddShardIndexes = currentPageShards.filter((shard, index) => index % 2 !== 0);
function shardInfoToString(shard) {
function shardInfoToString(shard: ShardInfo) {
let string = '';
string += `**Shard ${shard.shardId}** - Guilds: ${shard.guildCount.toLocaleString(
'en-US'
+16 -9
View File
@@ -1,7 +1,7 @@
import config from 'config';
import { notValidGuildId } from '../../utils/validation/systemCommandValidator';
import { getUptimeFormatted } from '../../utils/system/getUptimeFormatted';
import { SlashCommandBuilder, EmbedBuilder } from 'discord.js';
import { SlashCommandBuilder, EmbedBuilder, Guild, Collection } from 'discord.js';
import osu from 'node-os-utils';
// @ts-ignore
import { version, dependencies } from '../../../package.json';
@@ -26,8 +26,8 @@ module.exports = {
module: 'slashCommand',
name: '/systemstatus',
executionId: executionId,
shardId: interaction.guild.shardId,
guildId: interaction.guild.id
shardId: interaction.guild?.shardId,
guildId: interaction.guild?.id
});
if (await notValidGuildId({ interaction, executionId })) {
@@ -59,15 +59,21 @@ module.exports = {
const distubeYtdlVersion = dependencies['@distube/ytdl-core'];
logger.debug('Fetching player statistics from all shards.');
if (!client || !client.shard) {
logger.error('Client is undefined or does not have shard property.');
return;
}
await client.shard
.broadcastEval(() => {
/* eslint-disable no-undef */
return player.generateStatistics();
})
.then((results) => {
const queueCountList = [];
const trackCountList = [];
const listenerCountList = [];
const queueCountList: number[] = [];
const trackCountList: number[] = [];
const listenerCountList: number[] = [];
results.map((result) => {
queueCountList.push(result.queues.length);
if (result.queues.length > 0) {
@@ -89,10 +95,11 @@ module.exports = {
await client.shard
.fetchClientValues('guilds.cache')
.then((results) => {
results.map((guildCache) => {
const guildCaches = results as Collection<string, Guild>[];
guildCaches.map((guildCache) => {
if (guildCache) {
guildCount += guildCache.length;
memberCount += guildCache.reduce((acc, guildCache) => acc + guildCache.memberCount, 0);
guildCount += guildCache.size;
memberCount += guildCache.reduce((acc, guild) => acc + guild.memberCount, 0);
}
});
logger.debug('Successfully fetched client values from shards.');
+7 -3
View File
@@ -1,16 +1,20 @@
import { Client, Collection } from 'discord.js';
import { Client, Collection, SharedNameAndDescription } from 'discord.js';
type RegisterClientCommandsFunction = (params: { client: Client; executionId: string }) => void;
export interface Command {
isNew: boolean;
isBeta: boolean;
data: object;
data: {
name: string;
description: string;
options: SharedNameAndDescription[]
};
execute: (params: { interaction: object; client: ExtendedClient | undefined; executionId: string }) => void;
autocomplete?: (params: { interaction: object; executionId: string }) => void;
}
export interface ExtendedClient extends Client {
registerClientCommands?: RegisterClientCommandsFunction;
commands?: Collection<string, NodeModule | Command>;
commands?: Collection<string, Command>;
}
+12
View File
@@ -12,3 +12,15 @@ export interface CommandAutocompleteParams {
client: ExtendedClient | undefined;
executionId: string;
}
export interface ShardInfo {
shardId: number;
memUsage: number;
guildCount: number;
guildMemberCount: number;
playerStatistics: {
activeVoiceConnections: number;
totalTracks: number;
totalListeners: number;
};
}
+5
View File
@@ -0,0 +1,5 @@
import { Player } from 'discord-player';
declare global {
const player: Player;
}