diff options
| author | Jokler <jokler.contact@gmail.com> | 2018-02-26 18:09:57 +0100 |
|---|---|---|
| committer | Jokler <jokler.contact@gmail.com> | 2018-02-26 18:09:57 +0100 |
| commit | 5c7f882a0ed10153b1bd2dd8c796a168059e2c37 (patch) | |
| tree | da43eb87c75762e742e115733b5516a38b4af59d /src | |
| parent | 92668ad4c53edcc1a317a16aa5ea30ca502f54ee (diff) | |
| download | frippy-5c7f882a0ed10153b1bd2dd8c796a168059e2c37.tar.gz frippy-5c7f882a0ed10153b1bd2dd8c796a168059e2c37.zip | |
Add time passed to tells
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib.rs | 1 | ||||
| -rw-r--r-- | src/plugins/tell/mod.rs | 18 |
2 files changed, 15 insertions, 4 deletions
@@ -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<T: Database> Tell<T> { 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<T: Database> Tell<T> { 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)); } |
