From 9c77cf9e164201b107d608ca98b17e8f41d0a125 Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Sat, 1 Jun 2024 21:29:36 -0600 Subject: [PATCH] general.ping: add nonce time --- src/modules/general.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/modules/general.js b/src/modules/general.js index 17835ac..99a0080 100644 --- a/src/modules/general.js +++ b/src/modules/general.js @@ -1,6 +1,8 @@ const Command = require("../lib/command.js"); const CATEGORY = "general"; +const {snowflakeToTimestamp} = require("../lib/utils.js"); + const help = new Command("help"); help.category = CATEGORY; help.helpText = "Lists all commands"; @@ -119,8 +121,18 @@ ping.helpText = "Pong"; ping.description = "Measures response times to Discord."; ping.addAlias("p"); 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({ - content: "Pong.", + content: `Pong.\n**RTT:** \`...\`\n**Gateway:** \`${gateway}ms\`${ + nonceTimestamp ? `\n**Your Message:** \`${noncePing}ms\`` : "" + }`, allowedMentions: { repliedUser: false, }, @@ -131,12 +143,11 @@ ping.callback = async function (msg) { const rtt = Math.floor( 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({ - 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: { repliedUser: false, },