fix: Ensure promise is returned where applicable

This commit is contained in:
Marius Begby committed 2023-08-28 15:31:54 +02:00
1 parent f231c53fe8
commit 14cb6b4936
23 files changed
+86 -125

No files matched your search

+2 -7
View File
@@ -28,19 +28,14 @@ const command: CustomSlashCommandInteraction = {
});
if (await notValidGuildId({ interaction, executionId })) {
return;
return Promise.resolve();
}
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
await client!.shard!
.broadcastEval((c) => {
return c.guilds.cache.map((guild) => {
return guild;
+5 -14
View File
@@ -29,24 +29,15 @@ const command: CustomSlashCommandInteraction = {
});
if (await notValidGuildId({ interaction, executionId })) {
return;
}
if (!client || !client.shard) {
logger.error('Client is undefined or does not have shard property.');
return;
return Promise.resolve();
}
try {
logger.debug('Reloading commands across all shards.');
await client.shard
.broadcastEval(
await client!
.shard!.broadcastEval(
async (shardClient: ExtendedClient, { executionId }) => {
if (!shardClient.registerClientCommands) {
return;
}
shardClient.registerClientCommands({ client: shardClient, executionId });
shardClient.registerClientCommands!({ client: shardClient, executionId });
},
{ context: { executionId: executionId } }
)
@@ -70,7 +61,7 @@ const command: CustomSlashCommandInteraction = {
});
}
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}`;
});
+5 -14
View File
@@ -46,24 +46,15 @@ const command: CustomSlashCommandInteraction = {
});
if (await notValidGuildId({ interaction, executionId })) {
return;
return Promise.resolve();
}
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: ExtendedClient) => {
if (!shardClient.shard) {
return;
}
await client!
.shard!.broadcastEval((shardClient: ExtendedClient) => {
/* eslint-disable no-undef */
const playerStats = player.generateStatistics();
const nodeProcessMemUsageInMb = parseFloat(
@@ -71,7 +62,7 @@ const command: CustomSlashCommandInteraction = {
);
const shardInfo = {
shardId: shardClient.shard.ids[0],
shardId: shardClient.shard!.ids[0],
memUsage: nodeProcessMemUsageInMb,
guildCount: shardClient.guilds.cache.size,
guildMemberCount: shardClient.guilds.cache.reduce((acc, guild) => acc + guild.memberCount, 0),
@@ -194,7 +185,7 @@ const command: CustomSlashCommandInteraction = {
.setDescription(`**${embedOptions.icons.server} Shard overview - ${shardCount} total shards**\n`)
.addFields(...embedFields)
.setColor(embedOptions.colors.info)
.setFooter({ text: `Shard id: ${client.shard.ids[0]}, page ${pageIndex + 1} of ${totalPages}` })
.setFooter({ text: `Shard id: ${client!.shard!.ids[0]}, page ${pageIndex + 1} of ${totalPages}` })
]
});
}
@@ -32,7 +32,7 @@ const command: CustomSlashCommandInteraction = {
});
if (await notValidGuildId({ interaction, executionId })) {
return;
return Promise.resolve();
}
// from normal /status command
@@ -61,13 +61,8 @@ const command: CustomSlashCommandInteraction = {
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(() => {
await client!
.shard!.broadcastEval(() => {
/* eslint-disable no-undef */
return player.generateStatistics();
})
@@ -93,8 +88,8 @@ const command: CustomSlashCommandInteraction = {
});
logger.debug('Fetching client values from all shards.');
await client.shard
.fetchClientValues('guilds.cache')
await client!
.shard!.fetchClientValues('guilds.cache')
.then((results) => {
const guildCaches = results as Guild[][];
guildCaches.map((guildCache: Guild[]) => {
@@ -135,7 +130,7 @@ const command: CustomSlashCommandInteraction = {
`**${mediaplexVersion}** mediaplex\n` +
`**${distubeYtdlVersion}** @distube/ytdl-core`;
const discordStatusString = `**${client.ws.ping} ms** Discord API latency`;
const discordStatusString = `**${client!.ws.ping} ms** Discord API latency`;
logger.debug('Transformed system status into embed description.');