Support localization

This commit is contained in:
2022-06-06 20:44:39 +07:00
parent 95dae53187
commit f6a80dc578
+30 -16
View File
@@ -1,3 +1,4 @@
import { I18n } from 'i18n';
import { Message, CommandInteraction, Interaction } from 'discord.js';
import os from 'os-utils';
@@ -5,30 +6,35 @@ import DiscordProvider from '../providers/Discord';
import DiscordModule, { HybridInteractionMessage } from '../utils/DiscordModule';
import { sendHybridInteractionMessageResponse, makeInfoEmbed } from '../utils/DiscordMessage';
import Locale from '../providers/Locale';
import Cache from '../providers/Cache';
const EMBEDS = {
STATS_INFO: (data: Message | Interaction) => {
STATS_INFO: (data: Message | Interaction, locale: I18n) => {
const totalServers = DiscordProvider.client.guilds.cache.size;
const totalUsers = DiscordProvider.client.guilds.cache.map((g) => g.memberCount).reduce((a, c) => a + c);
const systemUptime = Math.round(new Date().getTime() / 1000) - Math.round(os.sysUptime());
const processUptime = Math.round(new Date().getTime() / 1000) - Math.round(os.processUptime());
return makeInfoEmbed({
title: `Stats`,
title: locale.__('stats.title'),
icon: '📊',
description: 'Stats of the bot',
description: locale.__('stats.description'),
fields: [
{
name: '🌐 Users',
value: `${
DiscordProvider.client.guilds.cache.size
} servers\n${DiscordProvider.client.guilds.cache
.map((g) => g.memberCount)
.reduce((a, c) => a + c)} users`,
name: `🌐 ${locale.__('stats.users')}`,
value: `${locale.__('stats.x_servers', totalServers.toString())}\n${locale.__(
'stats.x_users',
totalUsers.toString()
)}`,
inline: true
},
{
name: '🟢 Uptime since',
value: `System: <t:${
Math.round(new Date().getTime() / 1000) - Math.round(os.sysUptime())
}:R>\nProcess: <t:${
Math.round(new Date().getTime() / 1000) - Math.round(os.processUptime())
}:R>`,
name: `🟢 ${locale.__('stats.uptime_since')}`,
value: `${locale.__('stats.server_uptime_x', `<t:${systemUptime.toString()}:R>`)}\n${locale.__(
'stats.process_uptime_x',
`<t:${processUptime.toString()}:R>`
)}`,
inline: true
}
],
@@ -51,8 +57,16 @@ export default class Stats extends DiscordModule {
}
async run(data: HybridInteractionMessage, args: any) {
const guild = data.getGuild();
if (!guild) return;
const cachedGuild = await Cache.getCachedGuild(guild.id);
if (!cachedGuild) return;
const LocaleProvider = Locale.getLocaleProvider(cachedGuild.locale);
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.STATS_INFO(data.getRaw())]
embeds: [EMBEDS.STATS_INFO(data.getRaw(), LocaleProvider)]
});
}
}