mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
added: ping command
This commit is contained in:
1 parent
34dc71fc69
commit
9742288bf3
7 files changed
+146
No files matched your search
@@ -0,0 +1,104 @@
|
|||||||
|
/**
|
||||||
|
* @module commands/ping
|
||||||
|
* @description Show the bot's latency: REST roundtrip, gateway heartbeat and audio node ping.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { CommandBuilder } from "../src/commands/index.mjs";
|
||||||
|
import { EmbedBuilder } from "@fluxerjs/core";
|
||||||
|
import { getGlobalColor } from "../src/ui/index.mjs";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {CommandBuilder}
|
||||||
|
* @description Command definition for the ping command.
|
||||||
|
*/
|
||||||
|
export const command = new CommandBuilder()
|
||||||
|
.setName("ping")
|
||||||
|
.setDescription("Check the bot's latency and connection health.", "commands.ping")
|
||||||
|
.addAliases("latency", "pong")
|
||||||
|
.setCategory("util");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Safely read the gateway heartbeat latency (`client.ws.ping`).
|
||||||
|
* Returns -1 when unavailable (not logged in yet, or no heartbeat ACK received yet).
|
||||||
|
* @private
|
||||||
|
* @param {object} client - The bot client.
|
||||||
|
* @returns {number} Gateway latency in ms, or -1.
|
||||||
|
*/
|
||||||
|
function readGatewayPing(client) {
|
||||||
|
try {
|
||||||
|
const ping = client?.ws?.ping;
|
||||||
|
return typeof ping === "number" && Number.isFinite(ping) ? ping : -1;
|
||||||
|
} catch (_) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Safely read the audio node latency from the connected NodeLink/Lavalink node.
|
||||||
|
* `node.stats.ping` is the node's own gateway heartbeat latency; it can be -1
|
||||||
|
* or undefined while the node has no playing players.
|
||||||
|
* @private
|
||||||
|
* @param {object} lavalink - The LavalinkManager instance.
|
||||||
|
* @returns {object|null} `{ connected: true, ping: number|null }`, or null when no node is available.
|
||||||
|
*/
|
||||||
|
function readNodePing(lavalink) {
|
||||||
|
try {
|
||||||
|
const node = lavalink?.getNode?.();
|
||||||
|
if (!node) return null;
|
||||||
|
const ping = node?.stats?.ping;
|
||||||
|
return {
|
||||||
|
connected: true,
|
||||||
|
ping: (typeof ping === "number" && Number.isFinite(ping) && ping >= 0) ? ping : null,
|
||||||
|
};
|
||||||
|
} catch (_) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run handler for the ping command.
|
||||||
|
* Replies with a placeholder embed (which measures the REST roundtrip), then
|
||||||
|
* edits it with the roundtrip time, the gateway heartbeat latency and the
|
||||||
|
* audio node ping when available.
|
||||||
|
*
|
||||||
|
* @param {object} message - The command message wrapper.
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
export async function run(message) {
|
||||||
|
const t = (...a) => this.t(message, ...a);
|
||||||
|
|
||||||
|
const waitingEmbed = new EmbedBuilder()
|
||||||
|
.setColor(getGlobalColor())
|
||||||
|
.setDescription(t("responses.ping.measuring"));
|
||||||
|
|
||||||
|
const t0 = Date.now();
|
||||||
|
let sent;
|
||||||
|
try {
|
||||||
|
sent = await message.reply({ embeds: [waitingEmbed] });
|
||||||
|
} catch (e) {
|
||||||
|
return; // couldn't even send the placeholder — nothing to edit
|
||||||
|
}
|
||||||
|
const roundtrip = Date.now() - t0;
|
||||||
|
|
||||||
|
const lines = [
|
||||||
|
`${t("responses.ping.roundtrip")} — \`${roundtrip}ms\``,
|
||||||
|
];
|
||||||
|
|
||||||
|
const gateway = readGatewayPing(this.client);
|
||||||
|
if (gateway >= 0) lines.push(`${t("responses.ping.gateway")} — \`${gateway}ms\``);
|
||||||
|
|
||||||
|
const node = readNodePing(this.lavalink);
|
||||||
|
if (node) {
|
||||||
|
lines.push(`${t("responses.ping.node")} — \`${node.ping !== null ? node.ping + "ms" : "connected"}\``);
|
||||||
|
}
|
||||||
|
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setColor(getGlobalColor())
|
||||||
|
.setAuthor({
|
||||||
|
name: t("responses.ping.title"),
|
||||||
|
iconURL: this.client?.user?.displayAvatarURL?.() || null,
|
||||||
|
})
|
||||||
|
.setDescription(lines.join("\n"));
|
||||||
|
|
||||||
|
sent.edit({ embeds: [embed] }).catch(() => {});
|
||||||
|
}
|
||||||
@@ -355,6 +355,13 @@
|
|||||||
"alreadyPaused": "❌ متوقف بالفعل!",
|
"alreadyPaused": "❌ متوقف بالفعل!",
|
||||||
"paused": "⏸️ تم الإيقاف المؤقت"
|
"paused": "⏸️ تم الإيقاف المؤقت"
|
||||||
},
|
},
|
||||||
|
"ping": {
|
||||||
|
"title": "🏓 **Pong!**",
|
||||||
|
"measuring": "🏓 جارٍ قياس البينغ...",
|
||||||
|
"roundtrip": "📶 **زمن الاستجابة**",
|
||||||
|
"gateway": "🌐 **البوابة**",
|
||||||
|
"node": "🎧 **NodeLink**"
|
||||||
|
},
|
||||||
"play": {
|
"play": {
|
||||||
"searching": "🔍 جارٍ البحث...",
|
"searching": "🔍 جارٍ البحث...",
|
||||||
"loading": "جارٍ التحميل...",
|
"loading": "جارٍ التحميل...",
|
||||||
|
|||||||
@@ -355,6 +355,13 @@
|
|||||||
"alreadyPaused": "❌ پێشتر وەستاوە!",
|
"alreadyPaused": "❌ پێشتر وەستاوە!",
|
||||||
"paused": "⏸️ وەستا"
|
"paused": "⏸️ وەستا"
|
||||||
},
|
},
|
||||||
|
"ping": {
|
||||||
|
"title": "🏓 **Pong!**",
|
||||||
|
"measuring": "🏓 پینگ دەپێورێت...",
|
||||||
|
"roundtrip": "📶 **ماوەی وەڵام**",
|
||||||
|
"gateway": "🌐 **دەروازە**",
|
||||||
|
"node": "🎧 **NodeLink**"
|
||||||
|
},
|
||||||
"play": {
|
"play": {
|
||||||
"searching": "🔍 گەڕان...",
|
"searching": "🔍 گەڕان...",
|
||||||
"loading": "بارکردن...",
|
"loading": "بارکردن...",
|
||||||
|
|||||||
@@ -355,6 +355,13 @@
|
|||||||
"alreadyPaused": "❌ Bereits pausiert!",
|
"alreadyPaused": "❌ Bereits pausiert!",
|
||||||
"paused": "⏸️ Pausiert"
|
"paused": "⏸️ Pausiert"
|
||||||
},
|
},
|
||||||
|
"ping": {
|
||||||
|
"title": "🏓 **Pong!**",
|
||||||
|
"measuring": "🏓 Ping wird gemessen...",
|
||||||
|
"roundtrip": "📶 **Latenz**",
|
||||||
|
"gateway": "🌐 **Gateway**",
|
||||||
|
"node": "🎧 **NodeLink**"
|
||||||
|
},
|
||||||
"play": {
|
"play": {
|
||||||
"searching": "🔍 Suche...",
|
"searching": "🔍 Suche...",
|
||||||
"loading": "Laden...",
|
"loading": "Laden...",
|
||||||
|
|||||||
@@ -472,6 +472,13 @@
|
|||||||
"alreadyPaused": "❌ Already paused!",
|
"alreadyPaused": "❌ Already paused!",
|
||||||
"paused": "⏸️ Paused"
|
"paused": "⏸️ Paused"
|
||||||
},
|
},
|
||||||
|
"ping": {
|
||||||
|
"title": "🏓 **Pong!**",
|
||||||
|
"measuring": "🏓 Pinging...",
|
||||||
|
"roundtrip": "📶 **Roundtrip**",
|
||||||
|
"gateway": "🌐 **Gateway**",
|
||||||
|
"node": "🎧 **NodeLink**"
|
||||||
|
},
|
||||||
"play": {
|
"play": {
|
||||||
"searching": "🔍 Searching...",
|
"searching": "🔍 Searching...",
|
||||||
"loading": "Loading...",
|
"loading": "Loading...",
|
||||||
|
|||||||
@@ -355,6 +355,13 @@
|
|||||||
"alreadyPaused": "❌ Já está pausado!",
|
"alreadyPaused": "❌ Já está pausado!",
|
||||||
"paused": "⏸️ Pausado"
|
"paused": "⏸️ Pausado"
|
||||||
},
|
},
|
||||||
|
"ping": {
|
||||||
|
"title": "🏓 **Pong!**",
|
||||||
|
"measuring": "🏓 Medindo o ping...",
|
||||||
|
"roundtrip": "📶 **Latência**",
|
||||||
|
"gateway": "🌐 **Gateway**",
|
||||||
|
"node": "🎧 **NodeLink**"
|
||||||
|
},
|
||||||
"play": {
|
"play": {
|
||||||
"searching": "🔍 Buscando...",
|
"searching": "🔍 Buscando...",
|
||||||
"loading": "Carregando...",
|
"loading": "Carregando...",
|
||||||
|
|||||||
@@ -461,6 +461,13 @@
|
|||||||
"alreadyPaused": "❌ Zaten duraklatılmış!",
|
"alreadyPaused": "❌ Zaten duraklatılmış!",
|
||||||
"paused": "⏸️ Duraklatıldı"
|
"paused": "⏸️ Duraklatıldı"
|
||||||
},
|
},
|
||||||
|
"ping": {
|
||||||
|
"title": "🏓 **Pong!**",
|
||||||
|
"measuring": "🏓 Ping ölçülüyor...",
|
||||||
|
"roundtrip": "📶 **Gecikme**",
|
||||||
|
"gateway": "🌐 **Gateway**",
|
||||||
|
"node": "🎧 **NodeLink**"
|
||||||
|
},
|
||||||
"play": {
|
"play": {
|
||||||
"searching": "🔍 Aranıyor...",
|
"searching": "🔍 Aranıyor...",
|
||||||
"loading": "Yükleniyor...",
|
"loading": "Yükleniyor...",
|
||||||
|
|||||||
Reference in new issue
Block a user