From 2ba26a37d27a637b7c0e02970419342a6f83462b Mon Sep 17 00:00:00 2001 From: Jokler Date: Sat, 10 Feb 2018 14:13:07 +0100 Subject: Add evaluate function to plugins This allows plugins to be used in combination with each other. --- src/plugins/emoji.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/plugins/emoji.rs') diff --git a/src/plugins/emoji.rs b/src/plugins/emoji.rs index 59e2fdd..512a62e 100644 --- a/src/plugins/emoji.rs +++ b/src/plugins/emoji.rs @@ -36,13 +36,12 @@ impl Emoji { Emoji {} } - fn emoji(&self, server: &IrcServer, content: &str, target: &str) -> Result<(), IrcError> { - let names = self.return_emojis(content) + fn emoji(&self, content: &str) -> String { + self.return_emojis(content) .iter() .map(|e| e.to_string()) - .collect::>(); - - server.send_privmsg(target, &names.join(", ")) + .collect::>() + .join(", ") } fn return_emojis(&self, string: &str) -> Vec { @@ -108,7 +107,8 @@ impl Plugin for Emoji { fn execute(&self, server: &IrcServer, message: &Message) -> Result<(), IrcError> { match message.command { Command::PRIVMSG(_, ref content) => { - self.emoji(server, content, message.response_target().unwrap()) + server.send_privmsg(message.response_target().unwrap(), + &self.emoji(content)) } _ => Ok(()), } @@ -118,6 +118,15 @@ impl Plugin for Emoji { server.send_notice(&command.source, "This Plugin does not implement any commands.") } + + fn evaluate(&self, _: &IrcServer, command: PluginCommand) -> Result { + let emojis = self.emoji(&command.tokens[0]); + if emojis.is_empty() { + Ok(emojis) + } else { + Err(String::from("No emojis were found.")) + } + } } #[cfg(test)] -- cgit v1.2.3-70-g09d2