general.ping: send nonce and use it to calculate rtt

This commit is contained in:
Cynthia Foxwell 2024-06-01 21:39:23 -06:00
parent 9c77cf9e16
commit d166bbe870
1 changed files with 5 additions and 6 deletions

View File

@ -122,8 +122,8 @@ 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 msgTimestamp = snowflakeToTimestamp(msg.id);
const noncePing = Math.floor(msgTimestamp - nonceTimestamp);
const gateway = hf.bot.shards.get(
hf.bot.guildShardMap[hf.bot.channelGuildMap[msg.channel.id]] || 0
@ -133,6 +133,7 @@ ping.callback = async function (msg) {
content: `Pong.\n**RTT:** \`...\`\n**Gateway:** \`${gateway}ms\`${
nonceTimestamp ? `\n**Your Message:** \`${noncePing}ms\`` : ""
}`,
nonce: Date.now(),
allowedMentions: {
repliedUser: false,
},
@ -140,11 +141,9 @@ ping.callback = async function (msg) {
messageID: msg.id,
},
});
const rtt = Math.floor(
newMsg.timestamp - (msg.editedTimestamp || msg.timestamp)
);
const rtt = Math.floor(newMsg.timestamp - newMsg.nonce);
newMsg.edit({
await newMsg.edit({
content: `Pong.\n**RTT:** \`${rtt}ms\`\n**Gateway:** \`${gateway}ms\`${
nonceTimestamp ? `\n**Your Message:** \`${noncePing}ms\`` : ""
}`,