mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-03 22:15:37 +00:00
fix: more type annotation
This commit is contained in:
1 parent
3ac692d8eb
commit
2560f0fe9a
65 files changed
+408
-343
No files matched your search
@@ -1,9 +1,9 @@
|
||||
import config from 'config';
|
||||
import { EmbedBuilder, Guild, SlashCommandBuilder } from 'discord.js';
|
||||
|
||||
import { Logger } from 'pino';
|
||||
import loggerModule from '../../../services/logger';
|
||||
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
|
||||
import { EmbedOptions } from '../../../types/configTypes';
|
||||
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
|
||||
import { notValidGuildId } from '../../../utils/validation/systemCommandValidator';
|
||||
|
||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||
@@ -18,7 +18,7 @@ const command: CustomSlashCommandInteraction = {
|
||||
.setDMPermission(false)
|
||||
.setNSFW(false),
|
||||
execute: async ({ interaction, client, executionId }) => {
|
||||
const logger = loggerModule.child({
|
||||
const logger: Logger = loggerModule.child({
|
||||
source: 'guilds.js',
|
||||
module: 'slashCommand',
|
||||
name: '/guilds',
|
||||
@@ -32,7 +32,7 @@ const command: CustomSlashCommandInteraction = {
|
||||
}
|
||||
|
||||
let shardGuilds: Guild[] = [];
|
||||
let totalGuildCount = 0;
|
||||
let totalGuildCount: number = 0;
|
||||
|
||||
logger.debug('Fetching guilds from all shards.');
|
||||
await client!.shard!
|
||||
@@ -49,7 +49,7 @@ const command: CustomSlashCommandInteraction = {
|
||||
|
||||
logger.debug(`Successfully fetched ${totalGuildCount} guilds.`);
|
||||
|
||||
const guildListFormatted = shardGuilds
|
||||
const guildListFormatted: string = shardGuilds
|
||||
.map((guild) => {
|
||||
return {
|
||||
name: guild.name,
|
||||
@@ -61,7 +61,7 @@ const command: CustomSlashCommandInteraction = {
|
||||
.map((guild, index) => `${index + 1}. \`${guild.name} (#${guild.memberCount})\``)
|
||||
.join('\n');
|
||||
|
||||
const totalMemberCount = shardGuilds.reduce((a, b) => a + b.memberCount, 0);
|
||||
const totalMemberCount: number = shardGuilds.reduce((a, b) => a + b.memberCount, 0);
|
||||
|
||||
let embedDescription =
|
||||
`**${embedOptions.icons.bot} ${
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import config from 'config';
|
||||
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||
|
||||
import { Logger } from 'pino';
|
||||
import loggerModule from '../../../services/logger';
|
||||
import { ExtendedClient } from '../../../types/clientTypes';
|
||||
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
|
||||
import { EmbedOptions } from '../../../types/configTypes';
|
||||
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
|
||||
import { notValidGuildId } from '../../../utils/validation/systemCommandValidator';
|
||||
|
||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||
@@ -19,7 +19,7 @@ const command: CustomSlashCommandInteraction = {
|
||||
.setDMPermission(false)
|
||||
.setNSFW(false),
|
||||
execute: async ({ interaction, client, executionId }) => {
|
||||
const logger = loggerModule.child({
|
||||
const logger: Logger = loggerModule.child({
|
||||
source: 'reload.js',
|
||||
module: 'slashCommand',
|
||||
name: '/reload',
|
||||
@@ -61,12 +61,12 @@ const command: CustomSlashCommandInteraction = {
|
||||
});
|
||||
}
|
||||
|
||||
const commands = client!.commands?.map((command) => {
|
||||
const params = command.data.options[0] ? `**\`${command.data.options[0].name}\`**` + ' ' : '';
|
||||
const commands: string[] | undefined = client!.commands?.map((command) => {
|
||||
const params: string = 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: string = `**${embedOptions.icons.bot} Reloaded commands**\n` + commands?.join('\n');
|
||||
|
||||
logger.debug('Responding with success embed.');
|
||||
return await interaction.editReply({
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import config from 'config';
|
||||
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||
|
||||
import { EmbedBuilder, EmbedField, SlashCommandBuilder } from 'discord.js';
|
||||
import { Logger } from 'pino';
|
||||
import loggerModule from '../../../services/logger';
|
||||
import { ExtendedClient } from '../../../types/clientTypes';
|
||||
import { ShardInfo, CustomSlashCommandInteraction } from '../../../types/interactionTypes';
|
||||
import { EmbedOptions } from '../../../types/configTypes';
|
||||
import { CustomSlashCommandInteraction, ShardInfo } from '../../../types/interactionTypes';
|
||||
import { notValidGuildId } from '../../../utils/validation/systemCommandValidator';
|
||||
|
||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||
@@ -36,7 +36,7 @@ const command: CustomSlashCommandInteraction = {
|
||||
|
||||
.addNumberOption((option) => option.setName('page').setDescription('Page number to show').setMinValue(1)),
|
||||
execute: async ({ interaction, client, executionId }) => {
|
||||
const logger = loggerModule.child({
|
||||
const logger: Logger = loggerModule.child({
|
||||
source: 'shards.js',
|
||||
module: 'slashCommand',
|
||||
name: '/shards',
|
||||
@@ -55,12 +55,13 @@ const command: CustomSlashCommandInteraction = {
|
||||
try {
|
||||
await client!
|
||||
.shard!.broadcastEval((shardClient: ExtendedClient) => {
|
||||
/* eslint-disable no-undef */
|
||||
// Type for generateStatistics?
|
||||
const playerStats = player.generateStatistics();
|
||||
const nodeProcessMemUsageInMb = parseFloat(
|
||||
const nodeProcessMemUsageInMb: number = parseFloat(
|
||||
(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2)
|
||||
);
|
||||
|
||||
// TODO: Create shardInfo type
|
||||
const shardInfo = {
|
||||
shardId: shardClient.shard!.ids[0],
|
||||
memUsage: nodeProcessMemUsageInMb,
|
||||
@@ -129,17 +130,17 @@ const command: CustomSlashCommandInteraction = {
|
||||
});
|
||||
}
|
||||
|
||||
const shardCount = shardInfoList.length;
|
||||
const totalPages = Math.ceil(shardCount / 10) || 1;
|
||||
const pageIndex = (interaction.options.getNumber('page') || 1) - 1;
|
||||
const shardCount: number = shardInfoList.length;
|
||||
const totalPages:number = Math.ceil(shardCount / 10) || 1;
|
||||
const pageIndex:number = (interaction.options.getNumber('page') || 1) - 1;
|
||||
|
||||
const currentPageShards = shardInfoList.slice(pageIndex * 10, pageIndex * 10 + 10);
|
||||
const currentPageShards: ShardInfo[] = 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);
|
||||
const evenShardIndexes: ShardInfo[] = currentPageShards.filter((shard, index) => index % 2 === 0);
|
||||
const oddShardIndexes: ShardInfo[] = currentPageShards.filter((shard, index) => index % 2 !== 0);
|
||||
|
||||
function shardInfoToString(shard: ShardInfo) {
|
||||
let string = '';
|
||||
let string: string = '';
|
||||
string += `**Shard ${shard.shardId}** - Guilds: ${shard.guildCount.toLocaleString(
|
||||
'en-US'
|
||||
)} (${shard.guildMemberCount.toLocaleString('en-US')})\n`;
|
||||
@@ -150,10 +151,10 @@ const command: CustomSlashCommandInteraction = {
|
||||
return string;
|
||||
}
|
||||
|
||||
const evenShardIndexesString = evenShardIndexes.map(shardInfoToString).join('\n') + 'ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ';
|
||||
const oddShardIndexesString = oddShardIndexes.map(shardInfoToString).join('\n');
|
||||
const evenShardIndexesString: string = evenShardIndexes.map(shardInfoToString).join('\n') + 'ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ';
|
||||
const oddShardIndexesString: string = oddShardIndexes.map(shardInfoToString).join('\n');
|
||||
|
||||
const embedFields = [];
|
||||
const embedFields: EmbedField[] = [];
|
||||
|
||||
if (currentPageShards.length === 1) {
|
||||
embedFields.push({
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import config from 'config';
|
||||
import { EmbedBuilder, Guild, SlashCommandBuilder } from 'discord.js';
|
||||
import osu from 'node-os-utils';
|
||||
|
||||
// @ts-ignore
|
||||
import { dependencies, version } from '../../../../package.json';
|
||||
import loggerModule from '../../../services/logger';
|
||||
@@ -9,6 +8,7 @@ import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
|
||||
import { EmbedOptions } from '../../../types/configTypes';
|
||||
import { getUptimeFormatted } from '../../../utils/system/getUptimeFormatted';
|
||||
import { notValidGuildId } from '../../../utils/validation/systemCommandValidator';
|
||||
import { Logger } from 'pino';
|
||||
|
||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||
|
||||
@@ -22,7 +22,7 @@ const command: CustomSlashCommandInteraction = {
|
||||
.setDMPermission(false)
|
||||
.setNSFW(false),
|
||||
execute: async ({ interaction, client, executionId }) => {
|
||||
const logger = loggerModule.child({
|
||||
const logger: Logger = loggerModule.child({
|
||||
source: 'systemstatus.js',
|
||||
module: 'slashCommand',
|
||||
name: '/systemstatus',
|
||||
@@ -36,28 +36,28 @@ const command: CustomSlashCommandInteraction = {
|
||||
}
|
||||
|
||||
// from normal /status command
|
||||
const uptimeString = await getUptimeFormatted({ executionId });
|
||||
const usedMemoryInMB = Math.ceil((await osu.mem.info()).usedMemMb).toLocaleString('en-US');
|
||||
const cpuUsage = await osu.cpu.usage();
|
||||
const releaseVersion = version;
|
||||
let guildCount = 0;
|
||||
let memberCount = 0;
|
||||
let activeVoiceConnections = 0;
|
||||
let totalTracks = 0;
|
||||
let totalListeners = 0;
|
||||
const uptimeString: string = await getUptimeFormatted({ executionId });
|
||||
const usedMemoryInMB: string = Math.ceil((await osu.mem.info()).usedMemMb).toLocaleString('en-US');
|
||||
const cpuUsage: number = await osu.cpu.usage();
|
||||
const releaseVersion: string = version;
|
||||
let guildCount: number = 0;
|
||||
let memberCount: number = 0;
|
||||
let activeVoiceConnections: number = 0;
|
||||
let totalTracks: number = 0;
|
||||
let totalListeners: number = 0;
|
||||
|
||||
// specific to /systemstatus command
|
||||
const totalMemoryInMb = Math.ceil((await osu.mem.info()).totalMemMb).toLocaleString('en-US');
|
||||
const cpuCores = await osu.cpu.count();
|
||||
const platform = await osu.os.platform();
|
||||
const discordJsVersion = dependencies['discord.js'];
|
||||
const opusVersion = dependencies['@discord-player/opus'];
|
||||
const restVersion = dependencies['@discordjs/rest'];
|
||||
const voiceVersion = dependencies['discord-voip'];
|
||||
const discordPlayerVersion = dependencies['discord-player'];
|
||||
const extractorVersion = dependencies['@discord-player/extractor'];
|
||||
const mediaplexVersion = dependencies['mediaplex'];
|
||||
const distubeYtdlVersion = dependencies['@distube/ytdl-core'];
|
||||
const totalMemoryInMb: string = Math.ceil((await osu.mem.info()).totalMemMb).toLocaleString('en-US');
|
||||
const cpuCores: number = await osu.cpu.count();
|
||||
const platform: string = await osu.os.platform();
|
||||
const discordJsVersion: string = dependencies['discord.js'];
|
||||
const opusVersion: string = dependencies['@discord-player/opus'];
|
||||
const restVersion: string = dependencies['@discordjs/rest'];
|
||||
const voiceVersion: string = dependencies['discord-voip'];
|
||||
const discordPlayerVersion: string = dependencies['discord-player'];
|
||||
const extractorVersion: string = dependencies['@discord-player/extractor'];
|
||||
const mediaplexVersion: string = dependencies['mediaplex'];
|
||||
const distubeYtdlVersion: string = dependencies['@distube/ytdl-core'];
|
||||
|
||||
logger.debug('Fetching player statistics from all shards.');
|
||||
|
||||
@@ -85,7 +85,7 @@ const command: CustomSlashCommandInteraction = {
|
||||
await client!
|
||||
.shard!.fetchClientValues('guilds.cache')
|
||||
.then((results) => {
|
||||
const guildCaches = results as Guild[][];
|
||||
const guildCaches: Guild[][] = results as Guild[][];
|
||||
guildCaches.map((guildCache: Guild[]) => {
|
||||
if (guildCache) {
|
||||
guildCount += guildCache.length;
|
||||
@@ -124,7 +124,7 @@ const command: CustomSlashCommandInteraction = {
|
||||
`**${mediaplexVersion}** mediaplex\n` +
|
||||
`**${distubeYtdlVersion}** @distube/ytdl-core`;
|
||||
|
||||
const discordStatusString = `**${client!.ws.ping} ms** Discord API latency`;
|
||||
const discordStatusString: string = `**${client!.ws.ping} ms** Discord API latency`;
|
||||
|
||||
logger.debug('Transformed system status into embed description.');
|
||||
|
||||
|
||||
Reference in new issue
Block a user