Добавить modules/ping.js
This commit is contained in:
parent
7a758802fe
commit
a4196a3d40
39
modules/ping.js
Normal file
39
modules/ping.js
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import net from "net"
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: "ping",
|
||||||
|
description: "Пинг до DC2 Telegram",
|
||||||
|
execute: async (client, message, args) => {
|
||||||
|
const startTime = Date.now()
|
||||||
|
|
||||||
|
try {
|
||||||
|
await new Promise((resolve, reject) => {
|
||||||
|
const socket = new net.Socket()
|
||||||
|
const timeout = setTimeout(() => {
|
||||||
|
socket.destroy()
|
||||||
|
reject(new Error("Timeout"))
|
||||||
|
}, 5000)
|
||||||
|
|
||||||
|
socket.connect(443, "149.154.167.51", () => {
|
||||||
|
clearTimeout(timeout)
|
||||||
|
socket.destroy()
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
|
||||||
|
socket.on("error", (err) => {
|
||||||
|
clearTimeout(timeout)
|
||||||
|
reject(err)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const ping = Date.now() - startTime
|
||||||
|
await client.sendMessage(message.chatId, {
|
||||||
|
message: `Pong! ${ping}ms`,
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
await client.sendMessage(message.chatId, {
|
||||||
|
message: `Ошибка пинга: ${error.message}`,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user