diff options
Diffstat (limited to 'src/plugins')
| -rw-r--r-- | src/plugins/tell/mod.rs | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/src/plugins/tell/mod.rs b/src/plugins/tell/mod.rs index 7052b3e..4f6bfa0 100644 --- a/src/plugins/tell/mod.rs +++ b/src/plugins/tell/mod.rs @@ -38,22 +38,27 @@ impl<T: Database> Tell<T> { } } - fn tell_command(&self, client: &IrcClient, command: &PluginCommand) -> Result<&str, String> { + fn tell_command(&self, client: &IrcClient, command: PluginCommand) -> Result<&str, String> { if command.tokens.len() < 2 { return Err(self.invalid_command(client)); } - let receiver = command.tokens[0].to_string(); - let sender = command.source.to_owned(); + let receiver = &command.tokens[0]; + let sender = command.source; - if receiver == sender { + if receiver.eq_ignore_ascii_case(&sender) { 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)); + if let Some(channels) = client.list_channels() { + for channel in channels { + if let Some(users) = client.list_users(&channel) { + if users + .iter() + .any(|u| u.get_nickname().eq_ignore_ascii_case(&receiver)) + { + return Err(format!("{} is online in another channel.", receiver)); + } } } } @@ -62,7 +67,7 @@ impl<T: Database> Tell<T> { let message = command.tokens[1..].join(" "); let tell = database::NewTellMessage { sender: &sender, - receiver: &receiver, + receiver: &receiver.to_lowercase(), time: NaiveDateTime::from_timestamp(tm.sec, 0u32), message: &message, }; @@ -73,9 +78,9 @@ impl<T: Database> Tell<T> { } } - fn send_tell(&self, client: &IrcClient, receiver: &str) -> ExecutionStatus { + fn send_tells(&self, client: &IrcClient, receiver: &str) -> ExecutionStatus { let mut tells = try_lock!(self.tells); - if let Some(tell_messages) = tells.get_tells(receiver) { + if let Some(tell_messages) = tells.get_tells(&receiver.to_lowercase()) { 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); @@ -96,7 +101,8 @@ impl<T: Database> Tell<T> { ); } } - tells.delete_tells(receiver); + tells.delete_tells(&receiver.to_lowercase()); + ExecutionStatus::Done } @@ -120,9 +126,7 @@ impl<T: Database> Tell<T> { impl<T: Database> Plugin for Tell<T> { fn execute(&self, client: &IrcClient, message: &Message) -> ExecutionStatus { match message.command { - Command::JOIN(_, _, _) | Command::PRIVMSG(_, _) => { - self.send_tell(client, message.source_nickname().unwrap()) - } + Command::JOIN(_, _, _) => self.send_tells(client, message.source_nickname().unwrap()), _ => ExecutionStatus::Done, } } @@ -138,16 +142,18 @@ impl<T: Database> Plugin for Tell<T> { .context(FrippyErrorKind::Connection)?); } + let sender = command.source.to_owned(); + Ok(match command.tokens[0].as_ref() { "help" => client .send_notice(&command.source, &self.help(client)) .context(FrippyErrorKind::Connection), - _ => match self.tell_command(client, &command) { + _ => match self.tell_command(client, command) { Ok(msg) => client - .send_notice(&command.source, msg) + .send_notice(&sender, msg) .context(FrippyErrorKind::Connection), Err(msg) => client - .send_notice(&command.source, &msg) + .send_notice(&sender, &msg) .context(FrippyErrorKind::Connection), }, }?) |
