update ping command
This commit is contained in:
+27
-4
@@ -1,4 +1,4 @@
|
|||||||
import {logError, oldSendMessage} from "../util/utils";
|
import {logError, sendMessage} from "../util/utils";
|
||||||
import {Message} from "typescript-telegram-bot-api";
|
import {Message} from "typescript-telegram-bot-api";
|
||||||
import {ChatCommand} from "../base/chat-command";
|
import {ChatCommand} from "../base/chat-command";
|
||||||
|
|
||||||
@@ -7,10 +7,33 @@ export class Ping extends ChatCommand {
|
|||||||
description = "Ping between received and sent message";
|
description = "Ping between received and sent message";
|
||||||
|
|
||||||
async execute(msg: Message) {
|
async execute(msg: Message) {
|
||||||
|
const d = new Date();
|
||||||
|
const u = (n: number): string => n > 9 ? n.toString() : `0${n}`;
|
||||||
|
const date = `${u(d.getDay())}.${u(d.getMonth() + 1)}.${d.getFullYear()}`;
|
||||||
|
const time = `${u(d.getHours())}:${u(d.getMinutes())}:${u(d.getSeconds())}:${u(d.getMilliseconds())}`;
|
||||||
|
|
||||||
|
const msgDate = msg.date;
|
||||||
|
const nowDate = new Date().getTime() / 1000;
|
||||||
|
const diff = nowDate - msgDate;
|
||||||
|
const tgPing = diff.toFixed(2);
|
||||||
|
|
||||||
const then = Date.now();
|
const then = Date.now();
|
||||||
await oldSendMessage(msg, "pong").catch(logError);
|
await sendMessage({message: msg, text: "pong"}).catch(logError);
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const diff = Math.abs(now - then);
|
const msgSendDiff = (now - then).toFixed(2);
|
||||||
await oldSendMessage(msg, `ping: ${diff}ms`).catch(logError);
|
|
||||||
|
await sendMessage(
|
||||||
|
{
|
||||||
|
message: msg,
|
||||||
|
text:
|
||||||
|
"```ping\n" +
|
||||||
|
`TG: ${tgPing}ms\n` +
|
||||||
|
`API ${msgSendDiff}ms\n\n` +
|
||||||
|
`🗓️ Local date : ${date}\n` +
|
||||||
|
`🕒 Local time: ${time}` +
|
||||||
|
"```",
|
||||||
|
parse_mode: "Markdown"
|
||||||
|
}
|
||||||
|
).catch(logError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user