mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-03 06:28:53 +00:00
Status transcription
This commit is contained in:
5 files changed
+155
-43
No files matched your search
@@ -225,5 +225,39 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"statistics": {
|
||||
"botStatus": {
|
||||
"title": "{{icon}} **Bot status**",
|
||||
"joinedServers": "**{{count}}** Joined servers",
|
||||
"joinedServers_one": "**1** Joined server",
|
||||
"totalMembers": "**{{count}}** Total members",
|
||||
"releaseVersion": "**{{version}}** Release version"
|
||||
},
|
||||
"queueStatus": {
|
||||
"title": "{{icon}} **Queue status**",
|
||||
"voiceConnections": "**{{count}}** Voice connections",
|
||||
"voiceConnections_one": "**1** Voice connection",
|
||||
"tracksInQueues": "**{{count}}** Tracks in queues",
|
||||
"tracksInQueues_one": "**1** Track in queues",
|
||||
"usersListening": "**{{count}}** Users listening",
|
||||
"usersListening_one": "**1** User listening"
|
||||
},
|
||||
"systemStatus": {
|
||||
"title": "{{icon}} **System status**",
|
||||
"uptime": "**{{value}}** Uptime",
|
||||
"cpu": "**{{value, number(minimumFractionDigits: 2)}}%** CPU usage",
|
||||
"cpuDetailed": "**{{usage}}% @ {{cores}} cores** CPU usage",
|
||||
"memory": "**{{value, number}} MB** Memory usage",
|
||||
"memoryDetailed": "**{{used, number}} / {{total, number}} MB** Memory usage",
|
||||
"platform": "**{{value}}** Platform"
|
||||
},
|
||||
"discordStatus": {
|
||||
"title": "{{icon}} **Discord status**",
|
||||
"apiLatency": "**{{value, number}} ms** Discord API latency"
|
||||
},
|
||||
"dependencies": {
|
||||
"title": "{{icon}} **Dependencies**"
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+34
@@ -226,6 +226,40 @@ interface Resources {
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"statistics": {
|
||||
"botStatus": {
|
||||
"title": "{{icon}} **Bot status**",
|
||||
"joinedServers": "**{{count}}** Joined servers",
|
||||
"joinedServers_one": "**1** Joined server",
|
||||
"totalMembers": "**{{count}}** Total members",
|
||||
"releaseVersion": "**{{version}}** Release version"
|
||||
},
|
||||
"queueStatus": {
|
||||
"title": "{{icon}} **Queue status**",
|
||||
"voiceConnections": "**{{count}}** Voice connections",
|
||||
"voiceConnections_one": "**1** Voice connection",
|
||||
"tracksInQueues": "**{{count}}** Tracks in queues",
|
||||
"tracksInQueues_one": "**1** Track in queues",
|
||||
"usersListening": "**{{count}}** Users listening",
|
||||
"usersListening_one": "**1** User listening"
|
||||
},
|
||||
"systemStatus": {
|
||||
"title": "{{icon}} **System status**",
|
||||
"uptime": "**{{value}}** Uptime",
|
||||
"cpu": "**{{value, number(minimumFractionDigits: 2)}}%** CPU usage",
|
||||
"cpuDetailed": "**{{usage}}% @ {{cores}} cores** CPU usage",
|
||||
"memory": "**{{value, number}} MB** Memory usage",
|
||||
"memoryDetailed": "**{{used, number}} / {{total, number}} MB** Memory usage",
|
||||
"platform": "**{{value}}** Platform"
|
||||
},
|
||||
"discordStatus": {
|
||||
"title": "{{icon}} **Discord status**",
|
||||
"apiLatency": "**{{value, number}} ms** Discord API latency"
|
||||
},
|
||||
"dependencies": {
|
||||
"title": "{{icon}} **Dependencies**"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+48
-24
@@ -2,54 +2,78 @@ import osu from 'node-os-utils';
|
||||
import { ExtendedClient } from '../types/clientTypes';
|
||||
import { fetchTotalGuildStatistics, fetchTotalPlayerStatistics } from '../utils/shardUtils';
|
||||
import { getUptimeFormatted } from '../utils/system/getUptimeFormatted';
|
||||
import { TFunction } from 'i18next';
|
||||
|
||||
export async function getBotStatistics(client: ExtendedClient, version: string): Promise<string> {
|
||||
export async function getBotStatistics(
|
||||
client: ExtendedClient,
|
||||
version: string,
|
||||
translator: TFunction
|
||||
): Promise<string> {
|
||||
const releaseVersion: string = version;
|
||||
const { totalGuildCount, totalMemberCount } = await fetchTotalGuildStatistics(client);
|
||||
|
||||
return (
|
||||
`**${totalGuildCount.toLocaleString('en-US')}** Joined servers\n` +
|
||||
`**${totalMemberCount.toLocaleString('en-US')}** Total members\n` +
|
||||
`**v${releaseVersion}** Release version`
|
||||
translator('statistics.botStatus.joinedServers', {
|
||||
count: totalGuildCount
|
||||
}) +
|
||||
'\n' +
|
||||
translator('statistics.botStatus.totalMembers', {
|
||||
count: totalMemberCount
|
||||
}) +
|
||||
'\n' +
|
||||
translator('statistics.botStatus.releaseVersion', {
|
||||
version: `v${releaseVersion}`
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export async function getPlayerStatistics(client: ExtendedClient): Promise<string> {
|
||||
export async function getPlayerStatistics(client: ExtendedClient, translator: TFunction): Promise<string> {
|
||||
const { totalVoiceConnections, totalTracksInQueues, totalListeners } = await fetchTotalPlayerStatistics(client);
|
||||
|
||||
return (
|
||||
`**${totalVoiceConnections.toLocaleString('en-US')}** Voice connections\n` +
|
||||
`**${totalTracksInQueues.toLocaleString('en-US')}** Tracks in queues\n` +
|
||||
`**${totalListeners.toLocaleString('en-US')}** Users listening`
|
||||
translator('statistics.queueStatus.voiceConnections', {
|
||||
count: totalVoiceConnections
|
||||
}) +
|
||||
'\n' +
|
||||
translator('statistics.queueStatus.tracksInQueues', {
|
||||
count: totalTracksInQueues
|
||||
}) +
|
||||
'\n' +
|
||||
translator('statistics.queueStatus.usersListening', {
|
||||
count: totalListeners
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export async function getSystemStatus(executionId: string, extended: boolean): Promise<string> {
|
||||
export async function getSystemStatus(executionId: string, extended: boolean, translator: TFunction): Promise<string> {
|
||||
const uptimeString: string = getUptimeFormatted({ executionId });
|
||||
const usedMemoryInMB: number = Math.ceil((await osu.mem.info()).usedMemMb);
|
||||
const cpuUsage: number = await osu.cpu.usage();
|
||||
if (!extended) {
|
||||
const uptimeString: string = getUptimeFormatted({ executionId });
|
||||
const usedMemoryInMB: string = Math.ceil((await osu.mem.info()).usedMemMb).toLocaleString('en-US');
|
||||
const cpuUsage: number = await osu.cpu.usage();
|
||||
|
||||
return (
|
||||
`**${uptimeString}** Uptime\n` + `**${cpuUsage}%** CPU usage\n` + `**${usedMemoryInMB} MB** Memory usage`
|
||||
translator('statistics.systemStatus.uptime', { value: uptimeString }) +
|
||||
'\n' +
|
||||
translator('statistics.systemStatus.cpu', { value: cpuUsage }) +
|
||||
'\n' +
|
||||
translator('statistics.systemStatus.memory', { value: usedMemoryInMB })
|
||||
);
|
||||
}
|
||||
|
||||
const uptimeString: string = getUptimeFormatted({ executionId });
|
||||
const totalMemoryInMb: string = Math.ceil((await osu.mem.info()).totalMemMb).toLocaleString('en-US');
|
||||
const totalMemoryInMb: number = Math.ceil((await osu.mem.info()).totalMemMb);
|
||||
const cpuCores: number = osu.cpu.count();
|
||||
const platform: string = osu.os.platform();
|
||||
const usedMemoryInMB: string = Math.ceil((await osu.mem.info()).usedMemMb).toLocaleString('en-US');
|
||||
const cpuUsage: number = await osu.cpu.usage();
|
||||
|
||||
return (
|
||||
`**${platform}** Platform\n` +
|
||||
`**${uptimeString}** Uptime\n` +
|
||||
`**${cpuUsage}% @ ${cpuCores} cores** CPU usage\n` +
|
||||
`**${usedMemoryInMB} / ${totalMemoryInMb} MB** Memory usage`
|
||||
translator('statistics.systemStatus.platform', { value: platform }) +
|
||||
'\n' +
|
||||
translator('statistics.systemStatus.uptime', { value: uptimeString }) +
|
||||
'\n' +
|
||||
translator('statistics.systemStatus.cpuDetailed', { usage: cpuUsage, cores: cpuCores }) +
|
||||
'\n' +
|
||||
translator('statistics.systemStatus.memoryDetailed', { used: usedMemoryInMB, total: totalMemoryInMb })
|
||||
);
|
||||
}
|
||||
|
||||
export function getDiscordStatus(client: ExtendedClient): string {
|
||||
return `**${client!.ws.ping} ms** Discord API latency`;
|
||||
export function getDiscordStatus(client: ExtendedClient, translator: TFunction): string {
|
||||
return translator('statistics.discordStatus.apiLatency', { value: client.ws.ping });
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
|
||||
import { getBotStatistics, getDiscordStatus, getPlayerStatistics, getSystemStatus } from '../../../common/statusUtils';
|
||||
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
|
||||
import { localizeCommand } from '../../../common/localeUtil';
|
||||
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
|
||||
|
||||
class StatusCommand extends BaseSlashCommandInteraction {
|
||||
constructor() {
|
||||
@@ -15,31 +15,42 @@ class StatusCommand extends BaseSlashCommandInteraction {
|
||||
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
|
||||
const { executionId, interaction, client } = params;
|
||||
const logger = this.getLogger(this.name, executionId, interaction);
|
||||
const translator = useServerTranslator(interaction);
|
||||
|
||||
const [botStatisticsEmbedString, playerStatisticsEmbedString, systemStatusEmbedString] = await Promise.all([
|
||||
getBotStatistics(client!, version),
|
||||
getPlayerStatistics(client!),
|
||||
getSystemStatus(executionId, false)
|
||||
getBotStatistics(client!, version, translator),
|
||||
getPlayerStatistics(client!, translator),
|
||||
getSystemStatus(executionId, false, translator)
|
||||
]);
|
||||
const discordStatus = getDiscordStatus(client!);
|
||||
const discordStatusEmbedString = getDiscordStatus(client!, translator);
|
||||
|
||||
logger.debug('Responding with info embed.');
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setDescription(`**${this.embedOptions.icons.bot} Bot status**\n` + botStatisticsEmbedString)
|
||||
.setDescription(
|
||||
translator('statistics.botStatus.title', { icon: this.embedOptions.icons.bot }) +
|
||||
'\n' +
|
||||
botStatisticsEmbedString
|
||||
)
|
||||
.addFields(
|
||||
{
|
||||
name: `**${this.embedOptions.icons.queue} Queue status**`,
|
||||
name: translator('statistics.queueStatus.title', {
|
||||
icon: this.embedOptions.icons.queue
|
||||
}),
|
||||
value: playerStatisticsEmbedString
|
||||
},
|
||||
{
|
||||
name: `**${this.embedOptions.icons.server} System status**`,
|
||||
name: translator('statistics.systemStatus.title', {
|
||||
icon: this.embedOptions.icons.server
|
||||
}),
|
||||
value: systemStatusEmbedString
|
||||
},
|
||||
{
|
||||
name: `**${this.embedOptions.icons.discord} Discord status**`,
|
||||
value: discordStatus
|
||||
name: translator('statistics.discordStatus.title', {
|
||||
icon: this.embedOptions.icons.discord
|
||||
}),
|
||||
value: discordStatusEmbedString
|
||||
}
|
||||
)
|
||||
.setColor(this.embedOptions.colors.info)
|
||||
|
||||
@@ -5,7 +5,7 @@ import { BaseSlashCommandInteraction } from '../../../classes/interactions';
|
||||
import { getBotStatistics, getDiscordStatus, getPlayerStatistics, getSystemStatus } from '../../../common/statusUtils';
|
||||
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
|
||||
import { checkValidGuildId } from '../../../utils/validation/systemCommandValidator';
|
||||
import { localizeCommand } from '../../../common/localeUtil';
|
||||
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
|
||||
|
||||
class SystemStatusCommand extends BaseSlashCommandInteraction {
|
||||
constructor() {
|
||||
@@ -17,15 +17,16 @@ class SystemStatusCommand extends BaseSlashCommandInteraction {
|
||||
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
|
||||
const { executionId, interaction, client } = params;
|
||||
const logger = this.getLogger(this.name, executionId, interaction);
|
||||
const translator = useServerTranslator(interaction);
|
||||
|
||||
await this.runValidators({ interaction, executionId }, [checkValidGuildId]);
|
||||
|
||||
const [botStatisticsEmbedString, playerStatisticsEmbedString, systemStatusEmbedString] = await Promise.all([
|
||||
getBotStatistics(client!, version),
|
||||
getPlayerStatistics(client!),
|
||||
getSystemStatus(executionId, false)
|
||||
getBotStatistics(client!, version, translator),
|
||||
getPlayerStatistics(client!, translator),
|
||||
getSystemStatus(executionId, false, translator)
|
||||
]);
|
||||
const discordStatusEmbedString = getDiscordStatus(client!);
|
||||
const discordStatusEmbedString = getDiscordStatus(client!, translator);
|
||||
const dependenciesEmbedString = this.getDependencies();
|
||||
|
||||
logger.debug('Responding with info embed.');
|
||||
@@ -35,19 +36,27 @@ class SystemStatusCommand extends BaseSlashCommandInteraction {
|
||||
.setDescription(`**${this.embedOptions.icons.bot} Bot status**\n` + botStatisticsEmbedString)
|
||||
.addFields(
|
||||
{
|
||||
name: `**${this.embedOptions.icons.queue} Queue status**`,
|
||||
name: translator('statistics.queueStatus.title', {
|
||||
icon: this.embedOptions.icons.queue
|
||||
}),
|
||||
value: playerStatisticsEmbedString
|
||||
},
|
||||
{
|
||||
name: `**${this.embedOptions.icons.server} System status**`,
|
||||
name: translator('statistics.systemStatus.title', {
|
||||
icon: this.embedOptions.icons.server
|
||||
}),
|
||||
value: systemStatusEmbedString
|
||||
},
|
||||
{
|
||||
name: `**${this.embedOptions.icons.discord} Discord status**`,
|
||||
name: translator('statistics.discordStatus.title', {
|
||||
icon: this.embedOptions.icons.discord
|
||||
}),
|
||||
value: discordStatusEmbedString
|
||||
},
|
||||
{
|
||||
name: `**${this.embedOptions.icons.bot} Dependencies**`,
|
||||
name: translator('statistics.dependencies.title', {
|
||||
icon: this.embedOptions.icons.bot
|
||||
}),
|
||||
value: dependenciesEmbedString
|
||||
}
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user