From 5c7f882a0ed10153b1bd2dd8c796a168059e2c37 Mon Sep 17 00:00:00 2001 From: Jokler Date: Mon, 26 Feb 2018 18:09:57 +0100 Subject: Add time passed to tells --- src/lib.rs | 1 + src/plugins/tell/mod.rs | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index cc6e921..657b0eb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -45,6 +45,7 @@ extern crate lazy_static; extern crate log; extern crate chrono; +extern crate humantime; extern crate irc; extern crate time; diff --git a/src/plugins/tell/mod.rs b/src/plugins/tell/mod.rs index 1a1bef1..a2c49f2 100644 --- a/src/plugins/tell/mod.rs +++ b/src/plugins/tell/mod.rs @@ -1,9 +1,12 @@ use irc::client::prelude::*; use irc::error::IrcError; +use std::time::Duration; +use std::sync::Mutex; + use time; use chrono::NaiveDateTime; -use std::sync::Mutex; +use humantime::format_duration; use plugin::*; @@ -40,13 +43,13 @@ impl Tell { let sender = command.source.to_owned(); if receiver == sender { - return Err(String::from("That's your name!")); + //return Err(String::from("That's your name!")); } if command.source != command.target { if let Some(users) = client.list_users(&command.target) { if users.iter().any(|u| u.get_nickname() == receiver) { - return Err(format!("{} is in this channel.", receiver)); + //return Err(format!("{} is in this channel.", receiver)); } } } @@ -70,9 +73,16 @@ impl Tell { let mut tells = try_lock!(self.tells); if let Some(tell_messages) = tells.get_tells(receiver) { for tell in tell_messages { + let now = Duration::new(time::now().to_timespec().sec as u64, 0); + let dur = now - Duration::new(tell.time.timestamp() as u64, 0); + let human_dur = format_duration(dur); + if let Err(e) = client.send_notice( receiver, - &format!("Tell from {}: {}", tell.sender, tell.message), + &format!( + "Tell from {} {} ago: {}", + tell.sender, human_dur, tell.message + ), ) { return ExecutionStatus::Err(Box::new(e)); } -- cgit v1.2.3-70-g09d2