general.ping: add nonce time

This commit is contained in:
Cynthia Foxwell 2024-06-01 21:29:36 -06:00
parent 43e8a33d04
commit 9c77cf9e16

View file

@ -1,6 +1,8 @@
const Command = require("../lib/command.js"); const Command = require("../lib/command.js");
const CATEGORY = "general"; const CATEGORY = "general";
const {snowflakeToTimestamp} = require("../lib/utils.js");
const help = new Command("help"); const help = new Command("help");
help.category = CATEGORY; help.category = CATEGORY;
help.helpText = "Lists all commands"; help.helpText = "Lists all commands";
@ -119,8 +121,18 @@ ping.helpText = "Pong";
ping.description = "Measures response times to Discord."; ping.description = "Measures response times to Discord.";
ping.addAlias("p"); ping.addAlias("p");
ping.callback = async function (msg) { ping.callback = async function (msg) {
const nonceTimestamp = msg.nonce && snowflakeToTimestamp(msg.nonce);
const now = snowflakeToTimestamp(msg.id);
const noncePing = Math.floor(now - nonceTimestamp);
const gateway = hf.bot.shards.get(
hf.bot.guildShardMap[hf.bot.channelGuildMap[msg.channel.id]] || 0
).latency;
const newMsg = await msg.channel.createMessage({ const newMsg = await msg.channel.createMessage({
content: "Pong.", content: `Pong.\n**RTT:** \`...\`\n**Gateway:** \`${gateway}ms\`${
nonceTimestamp ? `\n**Your Message:** \`${noncePing}ms\`` : ""
}`,
allowedMentions: { allowedMentions: {
repliedUser: false, repliedUser: false,
}, },
@ -131,12 +143,11 @@ ping.callback = async function (msg) {
const rtt = Math.floor( const rtt = Math.floor(
newMsg.timestamp - (msg.editedTimestamp || msg.timestamp) newMsg.timestamp - (msg.editedTimestamp || msg.timestamp)
); );
const gateway = hf.bot.shards.get(
hf.bot.guildShardMap[hf.bot.channelGuildMap[msg.channel.id]] || 0
).latency;
newMsg.edit({ newMsg.edit({
content: `Pong. RTT: \`${rtt}ms\`, Gateway: \`${gateway}ms\``, content: `Pong.\n**RTT:** \`${rtt}ms\`\n**Gateway:** \`${gateway}ms\`${
nonceTimestamp ? `\n**Your Message:** \`${noncePing}ms\`` : ""
}`,
allowedMentions: { allowedMentions: {
repliedUser: false, repliedUser: false,
}, },