forked from blasthavers/blastmud
32 lines
1.2 KiB
Rust
32 lines
1.2 KiB
Rust
use super::{VerbContext, UserVerb, UserVerbRef, UResult};
|
|
use async_trait::async_trait;
|
|
use ansi::{ignore_special_characters, ansi};
|
|
use chrono::Utc;
|
|
|
|
pub struct Verb;
|
|
#[async_trait]
|
|
impl UserVerb for Verb {
|
|
async fn handle(self: &Self, ctx: &mut VerbContext, _verb: &str, _remaining: &str) -> UResult<()> {
|
|
let mut msg = String::new();
|
|
msg.push_str(&format!(ansi!("<bold><bgblue><white>| {:20} | {:15} |<reset>\n"),
|
|
ansi!("Username"),
|
|
ansi!("Idle")));
|
|
for online in ctx.trans.get_online_info().await? {
|
|
if let Some(online_time) = online.time {
|
|
let diff =
|
|
humantime::format_duration(
|
|
std::time::Duration::from_secs(
|
|
(Utc::now() - online_time).num_seconds() as u64));
|
|
msg.push_str(&format!(
|
|
"| {:20} | {:15} |\n", &ignore_special_characters(&online.username),
|
|
&format!("{}", &diff)));
|
|
}
|
|
}
|
|
msg.push_str("\n");
|
|
ctx.trans.queue_for_session(ctx.session, Some(&msg)).await?;
|
|
Ok(())
|
|
}
|
|
}
|
|
static VERB_INT: Verb = Verb;
|
|
pub static VERB: UserVerbRef = &VERB_INT as UserVerbRef;
|