Add latency to ping command
This commit is contained in:
parent
306b83a26a
commit
73954044c0
24
src/main.rs
24
src/main.rs
|
@ -6,7 +6,7 @@ extern crate lazy_static;
|
|||
use colored::*;
|
||||
use rand::Rng;
|
||||
use serenity::{
|
||||
client::Client,
|
||||
client::{Client, bridge::gateway::{ShardId, ShardManager}},
|
||||
framework::standard::{
|
||||
macros::{check, command, group},
|
||||
Args, CheckResult, CommandError, CommandOptions, CommandResult, DispatchError, Reason,
|
||||
|
@ -17,10 +17,16 @@ use serenity::{
|
|||
};
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::{env, process};
|
||||
use std::{env, process, sync::Arc};
|
||||
|
||||
struct Handler;
|
||||
|
||||
struct ShardManagerContainer;
|
||||
|
||||
impl TypeMapKey for ShardManagerContainer {
|
||||
type Value = Arc<Mutex<ShardManager>>;
|
||||
}
|
||||
|
||||
impl EventHandler for Handler {
|
||||
fn ready(&self, ctx: Context, ready: Ready) {
|
||||
if let Some(shard) = ready.shard {
|
||||
|
@ -127,7 +133,19 @@ fn init(ctx: &mut Context, message: &Message) -> CommandResult {
|
|||
|
||||
#[command]
|
||||
fn ping(ctx: &mut Context, message: &Message) -> CommandResult {
|
||||
let _ = message.reply(&ctx, "Pong!");
|
||||
// I have no idea if this works but its 5æm and I need to sleep help
|
||||
let data = ctx.data.read();
|
||||
let shards = data.get::<ShardManagerContainer>().unwrap().lock();
|
||||
let runners = shards.runners.lock();
|
||||
|
||||
let runner = match runners.get(&ShardId(ctx.shard_id)) {
|
||||
Some(v) => v,
|
||||
None => {
|
||||
return Err(CommandError("No shard found!".to_string()));
|
||||
}
|
||||
};
|
||||
|
||||
let _ = message.reply(&ctx, format!("Pong! Latency: {:?}", runner.latency));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue