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 | |
| parent | 92668ad4c53edcc1a317a16aa5ea30ca502f54ee (diff) | |
| download | frippy-5c7f882a0ed10153b1bd2dd8c796a168059e2c37.tar.gz frippy-5c7f882a0ed10153b1bd2dd8c796a168059e2c37.zip | |
Add time passed to tells
| -rw-r--r-- | Cargo.lock | 16 | ||||
| -rw-r--r-- | Cargo.toml | 1 | ||||
| -rw-r--r-- | src/lib.rs | 1 | ||||
| -rw-r--r-- | src/plugins/tell/mod.rs | 18 |
4 files changed, 32 insertions, 4 deletions
@@ -393,6 +393,7 @@ dependencies = [ "dotenv 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "frippy_derive 0.1.0", "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "humantime 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "irc 0.13.4 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -486,6 +487,14 @@ version = "1.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] +name = "humantime" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "quick-error 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "hyper" version = "0.11.19" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -925,6 +934,11 @@ dependencies = [ ] [[package]] +name = "quick-error" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "quine-mc_cluskey" version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1573,6 +1587,7 @@ dependencies = [ "checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" "checksum html5ever 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a49d5001dd1bddf042ea41ed4e0a671d50b1bf187e66b349d7ec613bdce4ad90" "checksum httparse 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c2f407128745b78abc95c0ffbe4e5d37427fdc0d45470710cfef8c44522a2e37" +"checksum humantime 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5369e01a05e3404c421b5d6dcfea6ecf7d5e65eba8a275948151358cd8282042" "checksum hyper 0.11.19 (registry+https://github.com/rust-lang/crates.io-index)" = "47659bb1cb7ef3cd7b4f9bd2a11349b8d92097d34f9597a3c09e9bcefaf92b61" "checksum hyper-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9c81fa95203e2a6087242c38691a0210f23e9f3f8f944350bd676522132e2985" "checksum idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "014b298351066f1512874135335d62a789ffe78a9974f94b43ed5621951eaf7d" @@ -1621,6 +1636,7 @@ dependencies = [ "checksum pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3a8b4c6b8165cd1a1cd4b9b120978131389f64bdaf456435caa41e630edba903" "checksum precomputed-hash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" "checksum pulldown-cmark 0.0.15 (registry+https://github.com/rust-lang/crates.io-index)" = "378e941dbd392c101f2cb88097fa4d7167bc421d4b88de3ff7dbee503bc3233b" +"checksum quick-error 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eda5fe9b71976e62bc81b781206aaa076401769b2143379d3eb2118388babac4" "checksum quine-mc_cluskey 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "07589615d719a60c8dd8a4622e7946465dfef20d1a428f969e3443e7386d5f45" "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" "checksum r2d2 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f9078ca6a8a5568ed142083bb2f7dc9295b69d16f867ddcc9849e51b17d8db46" @@ -27,6 +27,7 @@ mysql = [ irc = "0.13.4" log = "0.4.1" time = "0.1.39" +humantime = "1.1.0" rlua = "0.12.2" reqwest = "0.8.5" select = "0.4.2" @@ -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)); } |
