aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJokler <jokler.contact@gmail.com>2018-03-15 18:06:06 +0100
committerJokler <jokler.contact@gmail.com>2018-03-15 18:06:06 +0100
commit54fc50c782b79c2de32dc2ce50a79ae1b471db63 (patch)
tree37c829d00acfa7fe0c301d64013d6c55b463afe2 /src
parent2c5a29fc9f3746d3e7aa3d7725628a9162af2905 (diff)
downloadfrippy-54fc50c782b79c2de32dc2ce50a79ae1b471db63.tar.gz
frippy-54fc50c782b79c2de32dc2ce50a79ae1b471db63.zip
Improve multitell functionality and responses
Diffstat (limited to 'src')
-rw-r--r--src/plugins/tell/mod.rs41
1 files changed, 25 insertions, 16 deletions
diff --git a/src/plugins/tell/mod.rs b/src/plugins/tell/mod.rs
index 7c4af30..f3ca90c 100644
--- a/src/plugins/tell/mod.rs
+++ b/src/plugins/tell/mod.rs
@@ -48,27 +48,31 @@ impl<T: Database> Tell<T> {
return Ok(self.invalid_command(client));
}
+ let mut online = Vec::new();
+
let receivers = command.tokens[0].split(',');
let sender = command.source;
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("Sent all tells until your name was found."));
+ if receiver.eq_ignore_ascii_case(client.current_nickname())
+ || receiver.eq_ignore_ascii_case(&sender)
+ {
+ online.push(receiver);
+ continue;
}
- 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 channels = client
+ .list_channels()
+ .expect("The irc crate should not be compiled with the \"nochanlists\" feature");
+
+ 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))
+ {
+ online.push(receiver);
+ continue;
}
}
}
@@ -84,7 +88,12 @@ impl<T: Database> Tell<T> {
try_lock!(self.tells).insert_tell(&tell)?;
}
- Ok(String::from("Got it!"))
+
+ Ok(match online.len() {
+ 0 => format!("Got it!"),
+ 1 => format!("{} is currently online.", online[0]),
+ _ => format!("{} are currently online.", online.join(", ")),
+ })
}
fn on_namelist(&self, client: &IrcClient, channel: &str) -> Result<(), FrippyError> {