Skip to content

Commit e6ed020

Browse files
committed
feat(ping): add latency to ping command
1 parent b01987b commit e6ed020

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

src/command/util.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::abstraction::command::{CommandContext, CommandResult};
2+
use poise::CreateReply;
23

34
/// Show this menu
45
#[poise::command(
@@ -26,6 +27,25 @@ Type /help command for more info on a command.",
2627
required_permissions = "SEND_MESSAGES"
2728
)]
2829
pub async fn ping(ctx: CommandContext<'_>) -> CommandResult {
29-
ctx.say("pong!").await?;
30+
let handle = ctx.reply("Calculating....").await?;
31+
32+
let handle_message = handle.message().await?;
33+
34+
let sent_timestamp = handle_message.timestamp.timestamp_millis();
35+
let original_timestamp = ctx.created_at().timestamp_millis();
36+
37+
let rest_latency = sent_timestamp - original_timestamp;
38+
let gateway_latency = ctx.ping().await.as_millis();
39+
40+
handle
41+
.edit(
42+
ctx,
43+
CreateReply::default().content(format!(
44+
"Pong! Rest latency: {}ms, Gateway latency: {}ms",
45+
rest_latency, gateway_latency
46+
)),
47+
)
48+
.await?;
49+
3050
Ok(())
3151
}

0 commit comments

Comments
 (0)