diff --git a/src/main.rs b/src/main.rs index 8801188..315215a 100755 --- a/src/main.rs +++ b/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>; +} + 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::().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(()) }