aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJokler <jokler.contact@gmail.com>2018-02-12 21:34:08 +0100
committerJokler <jokler.contact@gmail.com>2018-02-12 21:34:08 +0100
commitd08eb3db79e702a729324e06ed8f6ab86c8355e3 (patch)
treeddfee4c01aab2a3e1d0ec0aa363b0c6eacefdb04
parentfb2a38846743f4b075b5f3bf9e9130fcf2f7bfec (diff)
downloadfrippy-d08eb3db79e702a729324e06ed8f6ab86c8355e3.tar.gz
frippy-d08eb3db79e702a729324e06ed8f6ab86c8355e3.zip
Save multiple tells per person
-rw-r--r--src/plugins/tell.rs22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/plugins/tell.rs b/src/plugins/tell.rs
index 07df726..3ec9586 100644
--- a/src/plugins/tell.rs
+++ b/src/plugins/tell.rs
@@ -17,7 +17,7 @@ macro_rules! try_lock {
#[derive(PluginName, Default, Debug)]
pub struct Tell {
- tells: Mutex<HashMap<String, TellMessage>>,
+ tells: Mutex<HashMap<String, Vec<TellMessage>>>,
}
#[derive(Default, Debug)]
@@ -60,21 +60,25 @@ impl Tell {
message: message,
};
- try_lock!(self.tells).insert(receiver.clone(), tell);
+ let mut tells = try_lock!(self.tells);
+ let tell_messages = tells.entry(receiver).or_insert(Vec::with_capacity(3));
+ (*tell_messages).push(tell);
Ok("Got it!")
}
fn send_tell(&self, client: &IrcClient, receiver: &str) -> ExecutionStatus {
let mut tells = try_lock!(self.tells);
- if let Some(tell) = tells.get(receiver) {
- if let Err(e) = client.send_notice(
- receiver,
- &format!("Tell from {}: {}", tell.sender, tell.message),
- ) {
- return ExecutionStatus::Err(e);
+ if let Some(tell_messages) = tells.get_mut(receiver) {
+ for tell in tell_messages {
+ if let Err(e) = client.send_notice(
+ receiver,
+ &format!("Tell from {}: {}", tell.sender, tell.message),
+ ) {
+ return ExecutionStatus::Err(e);
+ }
+ debug!("Sent {:?} from {:?} to {:?}", tell.message, tell.sender, receiver);
}
- debug!("Sent {:?} from {:?} to {:?}", tell.message, tell.sender, receiver);
}
tells.remove(receiver);
ExecutionStatus::Done