Better ping command
This commit is contained in:
parent
edbe99ac8f
commit
e4ef3d0c66
1 changed files with 24 additions and 1 deletions
|
@ -1,11 +1,34 @@
|
|||
use std::time::{Duration, Instant};
|
||||
|
||||
use crate::{Context, Error};
|
||||
|
||||
use log::trace;
|
||||
use poise::CreateReply;
|
||||
|
||||
const PING_PREFIX: &str = "<:catstareback:1078622789885497414> Pong!";
|
||||
|
||||
/// Replies with pong!
|
||||
#[poise::command(slash_command, prefix_command, track_edits = true, ephemeral)]
|
||||
pub async fn ping(ctx: Context<'_>) -> Result<(), Error> {
|
||||
trace!("Running ping command!");
|
||||
ctx.say("Pong!").await?;
|
||||
|
||||
let start = Instant::now();
|
||||
let response = ctx.say(PING_PREFIX).await?;
|
||||
|
||||
let rtt = start.elapsed().as_millis();
|
||||
let gateway_ping = match ctx.ping().await {
|
||||
Duration::ZERO => "Undetermined".to_string(),
|
||||
duration => format!("{}ms", duration.as_millis()),
|
||||
};
|
||||
|
||||
response
|
||||
.edit(
|
||||
ctx,
|
||||
CreateReply::default().content(format!(
|
||||
"{PING_PREFIX}\n\nRTT: {rtt}ms\nGateway: {gateway_ping}",
|
||||
)),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue