aboutsummaryrefslogtreecommitdiff
path: root/src/commands/info/ping.ts
blob: 086a77ae8f1be2ddc7ac8e27e89ecec2e11a44d3 (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
import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib';
import { EmbedBuilder, PermissionFlagsBits, type Message } from 'discord.js';

export default class PingCommand extends BushCommand {
	public constructor() {
		super('ping', {
			aliases: ['ping'],
			category: 'info',
			description: 'Gets the latency of the bot',
			usage: ['ping'],
			examples: ['ping'],
			slash: true,
			clientPermissions: (m) => util.clientSendAndPermCheck(m, [PermissionFlagsBits.EmbedLinks], true),
			userPermissions: []
		});
	}

	public override async exec(message: BushMessage) {
		const sentMessage = (await message.util.send('Pong!')) as Message;
		const timestamp: number = message.editedTimestamp ? message.editedTimestamp : message.createdTimestamp;
		const botLatency = `${'```'}\n ${Math.round(sentMessage.createdTimestamp - timestamp)}ms ${'```'}`;
		const apiLatency = `${'```'}\n ${Math.round(message.client.ws.ping)}ms ${'```'}`;
		const embed = new EmbedBuilder()
			.setTitle('Pong!  🏓')
			.addFields([
				{ name: 'Bot Latency', value: botLatency, inline: true },
				{ name: 'API Latency', value: apiLatency, inline: true }
			])
			.setFooter({ text: message.author.username, iconURL: message.author.displayAvatarURL() })
			.setColor(util.colors.default)
			.setTimestamp();
		await sentMessage.edit({
			content: null,
			embeds: [embed]
		});
	}

	public override async execSlash(message: BushSlashMessage) {
		const timestamp1 = message.interaction.createdTimestamp;
		await message.interaction.reply('Pong!');
		const timestamp2 = await message.interaction.fetchReply().then((m) => (m as Message).createdTimestamp);
		const botLatency = `${'```'}\n ${Math.round(timestamp2 - timestamp1)}ms ${'```'}`;
		const apiLatency = `${'```'}\n ${Math.round(client.ws.ping)}ms ${'```'}`;
		const embed = new EmbedBuilder()
			.setTitle('Pong!  🏓')
			.addFields([
				{ name: 'Bot Latency', value: botLatency, inline: true },
				{ name: 'API Latency', value: apiLatency, inline: true }
			])
			.setFooter({ text: message.interaction.user.username, iconURL: message.interaction.user.displayAvatarURL() })
			.setColor(util.colors.default)
			.setTimestamp();
		await message.interaction.editReply({
			content: null,
			embeds: [embed]
		});
	}
}