Combine Knub's type helpers with Zeppelin's, continue Utility plugin port
This commit is contained in:
parent
b338351e37
commit
9f059f33af
13 changed files with 533 additions and 13 deletions
53
backend/src/plugins/Utility/commands/PingCmd.ts
Normal file
53
backend/src/plugins/Utility/commands/PingCmd.ts
Normal file
|
@ -0,0 +1,53 @@
|
|||
import { utilityCmd } from "../types";
|
||||
import { noop, trimLines } from "../../../utils";
|
||||
import { Message } from "eris";
|
||||
|
||||
const { performance } = require("perf_hooks");
|
||||
|
||||
export const PingCmd = utilityCmd({
|
||||
trigger: "ping",
|
||||
description: "Test the bot's ping to the Discord API",
|
||||
permission: "can_ping",
|
||||
|
||||
async run({ message: msg, pluginData }) {
|
||||
const times = [];
|
||||
const messages: Message[] = [];
|
||||
let msgToMsgDelay = null;
|
||||
|
||||
for (let i = 0; i < 4; i++) {
|
||||
const start = performance.now();
|
||||
const message = await msg.channel.createMessage(`Calculating ping... ${i + 1}`);
|
||||
times.push(performance.now() - start);
|
||||
messages.push(message);
|
||||
|
||||
if (msgToMsgDelay === null) {
|
||||
msgToMsgDelay = message.timestamp - msg.timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
const highest = Math.round(Math.max(...times));
|
||||
const lowest = Math.round(Math.min(...times));
|
||||
const mean = Math.round(times.reduce((total, ms) => total + ms, 0) / times.length);
|
||||
|
||||
const shard = pluginData.client.shards.get(pluginData.client.guildShardMap[pluginData.guild.id]);
|
||||
|
||||
msg.channel.createMessage(
|
||||
trimLines(`
|
||||
**Ping:**
|
||||
Lowest: **${lowest}ms**
|
||||
Highest: **${highest}ms**
|
||||
Mean: **${mean}ms**
|
||||
Time between ping command and first reply: **${msgToMsgDelay}ms**
|
||||
Shard latency: **${shard.latency}ms**
|
||||
`),
|
||||
);
|
||||
|
||||
// Clean up test messages
|
||||
pluginData.client
|
||||
.deleteMessages(
|
||||
messages[0].channel.id,
|
||||
messages.map(m => m.id),
|
||||
)
|
||||
.catch(noop);
|
||||
},
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue