fn ping(ctx: &mut Context, msg: &Message) -> CommandResult {
    let start = chrono::offset::Utc::now().timestamp_millis();
    let mut message = msg.channel_id.say(&ctx.http, "Pong!")?;
    let message_latency = {
        let millis = message.timestamp.timestamp_millis() - start;
        if millis > 0 {
            millis
        } else {
            0
        }
    };

    let latency = {
        let shard_manager = {
            let data = match ctx.data.try_read() {
                Some(v) => v,
                None => {
                    error!("Error getting data lock, trying again...");
                    match ctx.data.try_read() {
                        Some(v) => v,
                        None => {
                            error!("Can't get data lock");

                            return Ok(());
                        }
                    }
                }
            };
            match data.get::<ShardManagerContainer>() {
                Some(v) => std::sync::Arc::clone(v),
                None => {
                    let _ = msg.reply(&ctx, "There was a problem getting the shard manager");

                    return Ok(());
                }
            }
        };

        let manager = shard_manager
            .try_lock()
            .ok_or("Couldn't get a lock on the shard manager")?;
        let runners = manager
            .runners
            .try_lock()
            .ok_or("Couldn't get a lock on the current shard runner")?;

        let shard = match runners.get(&ShardId(ctx.shard_id)) {
            Some(runner) => runner,
            None => {
                let _ = msg.reply(&ctx, "No shard found");

                return Ok(());
            }
        };

        match shard.latency {
            Some(latency) => match Duration::from_std(latency) {
                Ok(milli) => format!("{}ms", milli.num_milliseconds()),
                Err(_error) => "result is to high to calculate.".to_string(),
            },
            None => "TBD".to_string(),
        }
    };

    let string = format!(
        "Pong! \n**```prolog\nMessage Latency: {}ms, \n  Shard Latency: {}\n```**",
        message_latency, latency
    );
    message.edit(&ctx, |m| m.content(string))?;

    Ok(())
}
/// Does a quick test to find out the latancy of Discord Relative to the bot
Does a quick test to find out the latancy of Discord Relative to the bot
Does a quick test to find out the latancy of Discord Relative to the bot
fn ping(ctx: &mut Context, msg: &Message) -> CommandResult {
    let start = chrono::offset::Utc::now().timestamp_millis();
    let mut message = msg.channel_id.say(&ctx.http, "Pong!")?;
    let message_latency = {
        let millis = message.timestamp.timestamp_millis() - start;
        if millis > 0 {
            millis
        } else {
            0
        }
    };
    let latency = {
        let shard_manager = {
            let data = match ctx.data.try_read() {
                Some(v) => v,
                None => {
                    error!("Error getting data lock, trying again...");
                    match ctx.data.try_read() {
                        Some(v) => v,
                        None => {
                            error!("Can't get data lock");
                            return Ok(());
                        }
                    }
                }
            };
            match data.get::<ShardManagerContainer>() {
                Some(v) => std::sync::Arc::clone(v),
                None => {
                    let _ = msg.reply(&ctx, "There was a problem getting the shard manager");
                    return Ok(());
                }
            }
        };
        let manager = shard_manager
            .try_lock()
            .ok_or("Couldn't get a lock on the shard manager")?;
        let runners = manager
            .runners
            .try_lock()
            .ok_or("Couldn't get a lock on the current shard runner")?;
        let shard = match runners.get(&ShardId(ctx.shard_id)) {
            Some(runner) => runner,
            None => {
                let _ = msg.reply(&ctx, "No shard found");
                return Ok(());
            }
        };
        match shard.latency {
            Some(latency) => match Duration::from_std(latency) {
                Ok(milli) => format!("{}ms", milli.num_milliseconds()),
                Err(_error) => "result is to high to calculate.".to_string(),
            },
            None => "TBD".to_string(),
        }
    };
    let string = format!(
        "Pong! \n**```prolog\nMessage Latency: {}ms, \n  Shard Latency: {}\n```**",
        message_latency, latency
    );
    message.edit(&ctx, |m| m.content(string))?;
    Ok(())
}
fn ping ( ctx : & mut Context , msg : & Message ) -> CommandResult { let start = chrono :: offset :: Utc :: now ( ) . timestamp_millis ( ) ; let mut message = msg . channel_id . say ( & ctx . http , " " ) ? ; let message_latency = { let millis = message . timestamp . timestamp_millis ( ) - start ; if millis > 0 { millis } else { 0 } } ; let latency = { let shard_manager = { let data = match ctx . data . try_read ( ) { Some ( v ) => v , None => { error ! ( " " ) ; match ctx . data . try_read ( ) { Some ( v ) => v , None => { error ! ( " " ) ; return Ok ( ( ) ) ; } } } } ; match data . get :: < ShardManagerContainer > ( ) { Some ( v ) => std :: sync :: Arc :: clone ( v ) , None => { let _ = msg . reply ( & ctx , " " ) ; return Ok ( ( ) ) ; } } } ; let manager = shard_manager . try_lock ( ) . ok_or ( " " ) ? ; let runners = manager . runners . try_lock ( ) . ok_or ( " " ) ? ; let shard = match runners . get ( & ShardId ( ctx . shard_id ) ) { Some ( runner ) => runner , None => { let _ = msg . reply ( & ctx , " " ) ; return Ok ( ( ) ) ; } } ; match shard . latency { Some ( latency ) => match Duration :: from_std ( latency ) { Ok ( milli ) => format ! ( " " milli num_milliseconds ( ) ) , Err ( _error ) => " " . to_string ( ) , } , None => " " . to_string ( ) , } } ; let string = format ! ( " \n \n \n \n " message_latency latency ) ; message . edit ( & ctx , | m | m . content ( string ) ) ? ; Ok ( ( ) ) }
Does a quick test to find out the latancy of Discord Relative to the bot
Does a quick test to find out the latancy of Discord Relative to the bot
ctx
&mut Context
msg
&Message
ctx
&mut Context
msg
&Message