aboutsummaryrefslogtreecommitdiff
path: root/src/commands/moulberry-bush/serverStatus.ts
blob: 1237b3fda87137bcc3a826717f55a9d34801771e (plain)
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
57
58
59
import { BushCommand, clientSendAndPermCheck, colors, emojis, type CommandMessage } from '#lib';
import assert from 'assert/strict';
import { EmbedBuilder, PermissionFlagsBits } from 'discord.js';
import got from 'got';

assert(got);

export default class ServerStatusCommand extends BushCommand {
	public constructor() {
		super('serverStatus', {
			aliases: ['server-status', 'ss'],
			category: "Moulberry's Bush",
			description: "Gives the status of moulberry's server",
			usage: ['server-status'],
			examples: ['server-status', 'ss'],
			clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.EmbedLinks], true),
			userPermissions: [],
			slash: true
		});
	}

	public override async exec(message: CommandMessage) {
		const msgEmbed = new EmbedBuilder()
			.setTitle('Server status')
			.setDescription(`Checking server:\n${emojis.loading}`)
			.setColor(colors.default)
			.setFooter({ text: 'Checking https://moulberry.codes/lowestbin.json' });
		await message.util.reply({ embeds: [msgEmbed] });
		let main;
		try {
			await got.get('https://moulberry.codes/lowestbin.json').json();
			main = emojis.success;
		} catch (e) {
			main = emojis.error;
		}
		await message.util.edit({ embeds: [msgEmbed.setDescription(`Checking server:\n${main}`)] });
		if (main == emojis.success) {
			await message.util.edit({
				embeds: [
					msgEmbed
						.addFields({ name: 'Status', value: 'The server is online, all features related to prices will likely work.' })
						.setColor(colors.success)
				]
			});
		} else {
			await message.util.edit({
				embeds: [
					msgEmbed
						.addFields({
							name: 'Status',
							value:
								"It appears Moulberry's server is offline, this means that everything related to prices will likely not work."
						})
						.setColor(colors.error)
				]
			});
		}
	}
}