From f44f5d7ac2d24ff836c2e1d4b2fa58da04b13052 Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Sun, 25 Sep 2022 18:24:21 +1000 Subject: Refactor to mono-repo + upgrade packages --- src-slowcord/bot/src/commands/instance.ts | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src-slowcord/bot/src/commands/instance.ts (limited to 'src-slowcord/bot/src/commands/instance.ts') diff --git a/src-slowcord/bot/src/commands/instance.ts b/src-slowcord/bot/src/commands/instance.ts new file mode 100644 index 00000000..ac0c9b2d --- /dev/null +++ b/src-slowcord/bot/src/commands/instance.ts @@ -0,0 +1,36 @@ +import { Command } from "./index.js"; +import { User, Guild, Message } from "@fosscord/util"; + +const cache: { [key: string]: number; } = { + users: 0, + guilds: 0, + messages: 0, + lastChecked: 0, +}; + +export default { + name: "instance", + exec: async ({ message }) => { + if (Date.now() > cache.lastChecked + parseInt(process.env.CACHE_TTL as string)) { + cache.users = await User.count(); + cache.guilds = await Guild.count(); + cache.messages = await Message.count(); + cache.lastChecked = Date.now(); + } + + return message.reply({ + embeds: [{ + title: "Instance Stats", + description: "For more indepth information, check out https://grafana.understars.dev", + footer: { + text: `Last checked: ${Math.floor((Date.now() - cache.lastChecked) / (1000 * 60))} minutes ago`, + }, + fields: [ + { inline: true, name: "Total Users", value: cache.users.toString() }, + { inline: true, name: "Total Guilds", value: cache.guilds.toString() }, + { inline: true, name: "Total Messages", value: cache.messages.toString() }, + ] + }] + }); + } +} as Command; \ No newline at end of file -- cgit 1.5.1