Skip to content
This repository was archived by the owner on Feb 14, 2025. It is now read-only.

Commit df3b97d

Browse files
author
bariscodefx
committed
commands: Ping: handle websocket ping
1 parent ed87ae0 commit df3b97d

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/commands/utility/Ping.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@
2727
*/
2828
class Ping extends Command
2929
{
30+
/**
31+
* Latest ping from Discord gateway
32+
*
33+
* @var integer
34+
*/
35+
protected ?int $lastPing = null;
36+
3037
/**
3138
* configure
3239
*
@@ -38,6 +45,10 @@ public function configure(): void
3845
$this->description = "Displays bot's latency.";
3946
$this->aliases = ["latency", "ms"];
4047
$this->category = "utility";
48+
49+
$this->discord->on('heartbeat-ack', function($time) {
50+
$this->lastPing = intval($time);
51+
});
4152
}
4253

4354
/**
@@ -50,7 +61,6 @@ public function configure(): void
5061
public function handle($msg, $args): void
5162
{
5263
global $language;
53-
$diff = intval($msg->timestamp->floatDiffInRealSeconds() * 1000);
54-
$msg->channel->sendMessage(sprintf($language->getTranslator()->trans('commands.ping.reply'), $diff));
64+
$msg->channel->sendMessage(sprintf($language->getTranslator()->trans('commands.ping.reply'), $this->lastPing ?? "..."));
5565
}
5666
}

translations/en_EN.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ commands:
9090
# 4: reciever 5: amount 6: emote
9191
pay_msg: "Money Sent!\n\n%s - %s %s --> %s + %s %s"
9292
ping:
93-
reply: "Your ping took %s ms to arrive."
93+
reply: "My ping is %s ms."
9494
slots:
9595
no_amount: "You have to write a pay amount."
9696
no_numeric_arg: "Pay amount should be numeric."

translations/tr_TR.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ commands:
8989
# 1: sender 2: amount 3: emote
9090
# 4: reciever 5: amount 6: emote
9191
pay_msg: "Para gönderildi!\n\n%s - %s %s --> %s + %s %s"
92-
ping:
93-
reply: "Mesajınız %s milisaniye içinde bota ulaştı."
92+
"ping":
93+
reply: "Botun pingi %s ms."
9494
slots:
9595
no_amount: "Bahis miktarını girmelisin."
9696
no_numeric_arg: "Bahis miktarı sayısal olmalıdır."

0 commit comments

Comments
 (0)