aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJokler <jokler.contact@gmail.com>2018-04-25 17:46:33 +0200
committerJokler <jokler.contact@gmail.com>2018-04-25 17:46:33 +0200
commit87120d35c1e2ee7eff52e9fd2d0a8458206a4cb6 (patch)
tree28c852a08b2bb878d0ab191f849d856b12ca1261
parentfd2ea42d6702b1d5a2e8a0c8a0072c2b3e376a20 (diff)
downloadfrippy-87120d35c1e2ee7eff52e9fd2d0a8458206a4cb6.tar.gz
frippy-87120d35c1e2ee7eff52e9fd2d0a8458206a4cb6.zip
Emoji: Do not send empty messages
-rw-r--r--src/plugins/emoji.rs36
1 files 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::<Vec<String>>()
- .join(", ")
+ fn emoji(&self, content: &str) -> Option<String> {
+ let emojis = self.return_emojis(content);
+ if emojis.is_empty() {
+ None
+ } else {
+ Some(emojis
+ .iter()
+ .map(|e| e.to_string())
+ .collect::<Vec<String>>()
+ .join(", "))
+ }
}
fn return_emojis(&self, string: &str) -> Vec<EmojiHandle> {
@@ -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<String, String> {
- 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."))