aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/tell/mod.rs
diff options
context:
space:
mode:
authorJokler <jokler.contact@gmail.com>2018-02-26 18:09:57 +0100
committerJokler <jokler.contact@gmail.com>2018-02-26 18:09:57 +0100
commit5c7f882a0ed10153b1bd2dd8c796a168059e2c37 (patch)
treeda43eb87c75762e742e115733b5516a38b4af59d /src/plugins/tell/mod.rs
parent92668ad4c53edcc1a317a16aa5ea30ca502f54ee (diff)
downloadfrippy-5c7f882a0ed10153b1bd2dd8c796a168059e2c37.tar.gz
frippy-5c7f882a0ed10153b1bd2dd8c796a168059e2c37.zip
Add time passed to tells
Diffstat (limited to 'src/plugins/tell/mod.rs')
-rw-r--r--src/plugins/tell/mod.rs18
1 files changed, 14 insertions, 4 deletions
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));
}