Files
Yumi/src/discord/Stats.ts
T

59 lines
2.1 KiB
TypeScript
Raw Normal View History

2022-06-06 14:59:53 +07:00
import { Message, CommandInteraction, Interaction } from 'discord.js';
import os from 'os-utils';
2022-03-03 20:56:49 +07:00
2022-06-06 14:59:53 +07:00
import DiscordProvider from '../providers/Discord';
import DiscordModule, { HybridInteractionMessage } from '../utils/DiscordModule';
import { sendHybridInteractionMessageResponse, makeInfoEmbed } from '../utils/DiscordMessage';
2022-02-05 00:46:35 +07:00
const EMBEDS = {
STATS_INFO: (data: Message | Interaction) => {
return makeInfoEmbed({
title: `Stats`,
icon: '📊',
2022-02-07 10:41:55 +07:00
description: 'Stats of the bot',
fields: [
{
name: '🌐 Users',
2022-06-06 14:59:53 +07:00
value: `${
DiscordProvider.client.guilds.cache.size
} servers\n${DiscordProvider.client.guilds.cache
.map((g) => g.memberCount)
.reduce((a, c) => a + c)} users`,
2022-02-07 10:41:55 +07:00
inline: true
},
{
name: '🟢 Uptime since',
2022-06-06 14:59:53 +07:00
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>`,
2022-02-07 10:41:55 +07:00
inline: true
}
],
2022-06-06 14:59:53 +07:00
user: data instanceof Interaction ? data.user : data.author
2022-02-05 00:46:35 +07:00
});
}
2022-06-06 14:59:53 +07:00
};
2022-02-05 00:46:35 +07:00
2022-03-03 20:56:49 +07:00
export default class Stats extends DiscordModule {
2022-06-06 14:59:53 +07:00
public id = 'Discord_Stats';
public commands = ['stats'];
public commandInteractionName = 'stats';
2022-03-03 20:56:49 +07:00
async GuildOnModuleCommand(args: any, message: Message) {
await this.run(new HybridInteractionMessage(message), args);
2022-02-05 00:46:35 +07:00
}
2022-06-06 14:59:53 +07:00
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
2022-03-03 20:56:49 +07:00
await this.run(new HybridInteractionMessage(interaction), interaction.options);
2022-02-05 00:46:35 +07:00
}
2022-03-03 20:56:49 +07:00
async run(data: HybridInteractionMessage, args: any) {
2022-06-06 14:59:53 +07:00
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.STATS_INFO(data.getRaw())]
});
2022-02-05 00:46:35 +07:00
}
2022-06-06 14:59:53 +07:00
}