diff --git a/src/commands/ping.ts b/src/commands/ping.ts index 851c4da..33ac7ff 100644 --- a/src/commands/ping.ts +++ b/src/commands/ping.ts @@ -1,4 +1,4 @@ -import {logError, oldSendMessage} from "../util/utils"; +import {logError, sendMessage} from "../util/utils"; import {Message} from "typescript-telegram-bot-api"; import {ChatCommand} from "../base/chat-command"; @@ -7,10 +7,33 @@ export class Ping extends ChatCommand { description = "Ping between received and sent 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(); - await oldSendMessage(msg, "pong").catch(logError); + await sendMessage({message: msg, text: "pong"}).catch(logError); const now = Date.now(); - const diff = Math.abs(now - then); - await oldSendMessage(msg, `ping: ${diff}ms`).catch(logError); + const msgSendDiff = (now - then).toFixed(2); + + 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); } } \ No newline at end of file