summary refs log tree commit diff
path: root/src-slowcord/bot/src/commands/instance.ts
blob: 170d8f7671023636e277600c6f76c4133f08ea95 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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;