general.ping: add nonce time
This commit is contained in:
parent
43e8a33d04
commit
9c77cf9e16
1 changed files with 16 additions and 5 deletions
|
@ -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,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue