aboutsummaryrefslogtreecommitdiff
path: root/src/commands/info/ping.ts
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-06-01 17:24:16 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-06-01 17:24:16 -0400
commit4c3474c63dc3c5deb5bc1dd9f37cc9d5812b62fd (patch)
tree7ef72c3c3ff9d3a896d8781c5c54b7303d4e5a29 /src/commands/info/ping.ts
parentd7099571b90c4211f90089bb41e90b0a08b86112 (diff)
downloadtanzanite-4c3474c63dc3c5deb5bc1dd9f37cc9d5812b62fd.tar.gz
tanzanite-4c3474c63dc3c5deb5bc1dd9f37cc9d5812b62fd.tar.bz2
tanzanite-4c3474c63dc3c5deb5bc1dd9f37cc9d5812b62fd.zip
chore: fromatting fixes, refactor ping command, hopefully fix duration rounding issues
Diffstat (limited to 'src/commands/info/ping.ts')
-rw-r--r--src/commands/info/ping.ts41
1 files changed, 16 insertions, 25 deletions
diff --git a/src/commands/info/ping.ts b/src/commands/info/ping.ts
index 086a77a..af0fa98 100644
--- a/src/commands/info/ping.ts
+++ b/src/commands/info/ping.ts
@@ -1,5 +1,5 @@
import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib';
-import { EmbedBuilder, PermissionFlagsBits, type Message } from 'discord.js';
+import { EmbedBuilder, PermissionFlagsBits } from 'discord.js';
export default class PingCommand extends BushCommand {
public constructor() {
@@ -16,41 +16,32 @@ export default class PingCommand extends BushCommand {
}
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]
- });
+ const timestamp1 = message.editedTimestamp ? message.editedTimestamp : message.createdTimestamp;
+ const msg = await message.util.reply('Pong!');
+ const timestamp2 = msg.editedTimestamp ? msg.editedTimestamp : msg.createdTimestamp;
+ void this.command(message, timestamp2 - timestamp1);
}
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 timestamp1 = message.createdTimestamp;
+ const msg = (await message.util.reply({ content: 'Pong!', fetchReply: true })) as BushMessage;
+ const timestamp2 = msg.editedTimestamp ? msg.editedTimestamp : msg.createdTimestamp;
+ void this.command(message, timestamp2 - timestamp1);
+ }
+
+ private command(message: BushMessage | BushSlashMessage, msgLatency: number) {
+ const botLatency = util.format.codeBlock(`${Math.round(msgLatency)}ms`);
+ const apiLatency = util.format.codeBlock(`${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.interaction.user.username, iconURL: message.interaction.user.displayAvatarURL() })
+ .setFooter({ text: message.author.username, iconURL: message.author.displayAvatarURL() })
.setColor(util.colors.default)
.setTimestamp();
- await message.interaction.editReply({
+ return message.util.reply({
content: null,
embeds: [embed]
});