aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJokler <jokler.contact@gmail.com>2018-03-12 16:53:03 +0100
committerJokler <jokler.contact@gmail.com>2018-03-12 16:53:03 +0100
commit0632cbac85f4beefccc2bcf48d3627acb2897765 (patch)
tree615ef4a2a44204f31a82a767b7590335bdde6e73
parent237f6ebe59c90d4ceddd9af6a8a19e562d304aaa (diff)
downloadfrippy-0632cbac85f4beefccc2bcf48d3627acb2897765.tar.gz
frippy-0632cbac85f4beefccc2bcf48d3627acb2897765.zip
Let tell accept multiple comma-seperated receivers
-rw-r--r--Cargo.lock2
-rw-r--r--src/plugins/tell/mod.rs65
2 files changed, 31 insertions, 36 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 2b6a8fa..7fa418b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -362,7 +362,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "frippy"
-version = "0.3.1"
+version = "0.4.0"
dependencies = [
"chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"clippy 0.0.186 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/src/plugins/tell/mod.rs b/src/plugins/tell/mod.rs
index bdfb55c..7c4af30 100644
--- a/src/plugins/tell/mod.rs
+++ b/src/plugins/tell/mod.rs
@@ -48,49 +48,46 @@ impl<T: Database> Tell<T> {
return Ok(self.invalid_command(client));
}
- let receiver = &command.tokens[0];
+ let receivers = command.tokens[0].split(',');
let sender = command.source;
- if receiver.eq_ignore_ascii_case(client.current_nickname()) {
- return Ok(String::from("I am right here!"));
- }
+ for receiver in receivers {
+ if receiver.eq_ignore_ascii_case(client.current_nickname()) {
+ return Ok(String::from("Sent all tells until my name was found."));
+ }
- if receiver.eq_ignore_ascii_case(&sender) {
- return Ok(String::from("That's your name!"));
- }
+ if receiver.eq_ignore_ascii_case(&sender) {
+ return Ok(String::from("Sent all tells until your name was found."));
+ }
- 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 Ok(format!("{} is currently online.", 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 Ok(format!("Sent all tells until {} was found who is currently online.", receiver));
+ }
}
}
}
- }
- let tm = time::now().to_timespec();
- let message = command.tokens[1..].join(" ");
- let tell = database::NewTellMessage {
- sender: &sender,
- receiver: &receiver.to_lowercase(),
- time: NaiveDateTime::from_timestamp(tm.sec, 0u32),
- message: &message,
- };
-
- try_lock!(self.tells).insert_tell(&tell)?;
+ let tm = time::now().to_timespec();
+ let message = command.tokens[1..].join(" ");
+ let tell = database::NewTellMessage {
+ sender: &sender,
+ receiver: &receiver.to_lowercase(),
+ time: NaiveDateTime::from_timestamp(tm.sec, 0u32),
+ message: &message,
+ };
+ try_lock!(self.tells).insert_tell(&tell)?;
+ }
Ok(String::from("Got it!"))
}
- fn on_namelist(
- &self,
- client: &IrcClient,
- channel: &str,
- ) -> Result<(), FrippyError> {
+ fn on_namelist(&self, client: &IrcClient, channel: &str) -> Result<(), FrippyError> {
let receivers = try_lock!(self.tells)
.get_receivers()
.context(FrippyErrorKind::Tell)?;
@@ -111,6 +108,7 @@ impl<T: Database> Tell<T> {
Ok(())
}
}
+
fn send_tells(&self, client: &IrcClient, receiver: &str) -> Result<(), FrippyError> {
if client.current_nickname() == receiver {
return Ok(());
@@ -184,10 +182,7 @@ impl<T: Database> Plugin for Tell<T> {
if resp == Response::RPL_NAMREPLY {
debug!("NAMREPLY info: {:?}", chan_info);
- self.on_namelist(
- client,
- &chan_info[chan_info.len() - 1],
- )
+ self.on_namelist(client, &chan_info[chan_info.len() - 1])
} else {
Ok(())
}