From 87120d35c1e2ee7eff52e9fd2d0a8458206a4cb6 Mon Sep 17 00:00:00 2001 From: Jokler Date: Wed, 25 Apr 2018 17:46:33 +0200 Subject: Emoji: Do not send empty messages --- src/plugins/emoji.rs | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/plugins/emoji.rs b/src/plugins/emoji.rs index 4ec7265..b50b782 100644 --- a/src/plugins/emoji.rs +++ b/src/plugins/emoji.rs @@ -39,12 +39,17 @@ impl Emoji { Emoji {} } - fn emoji(&self, content: &str) -> String { - self.return_emojis(content) - .iter() - .map(|e| e.to_string()) - .collect::>() - .join(", ") + fn emoji(&self, content: &str) -> Option { + let emojis = self.return_emojis(content); + if emojis.is_empty() { + None + } else { + Some(emojis + .iter() + .map(|e| e.to_string()) + .collect::>() + .join(", ")) + } } fn return_emojis(&self, string: &str) -> Vec { @@ -100,11 +105,17 @@ impl Emoji { impl Plugin for Emoji { fn execute(&self, client: &IrcClient, message: &Message) -> ExecutionStatus { match message.command { - Command::PRIVMSG(_, ref content) => match client - .send_privmsg(message.response_target().unwrap(), &self.emoji(content)) - { - Ok(_) => ExecutionStatus::Done, - Err(e) => ExecutionStatus::Err(e.context(FrippyErrorKind::Connection).into()), + Command::PRIVMSG(_, ref content) => { + if let Some(emojis) = self.emoji(content) { + match client + .send_privmsg(message.response_target().unwrap(), &emojis) + { + Ok(_) => ExecutionStatus::Done, + Err(e) => ExecutionStatus::Err(e.context(FrippyErrorKind::Connection).into()), + } + } else { + ExecutionStatus::Done + } }, _ => ExecutionStatus::Done, } @@ -124,8 +135,7 @@ impl Plugin for Emoji { } fn evaluate(&self, _: &IrcClient, command: PluginCommand) -> Result { - let emojis = self.emoji(&command.tokens[0]); - if emojis.is_empty() { + if let Some(emojis) = self.emoji(&command.tokens[0]) { Ok(emojis) } else { Err(String::from("No emojis were found.")) -- cgit v1.2.3-70-g09d2