aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/emoji.rs
diff options
context:
space:
mode:
authorJokler <jokler.contact@gmail.com>2018-02-10 14:13:07 +0100
committerJokler <jokler.contact@gmail.com>2018-02-10 14:13:07 +0100
commit2ba26a37d27a637b7c0e02970419342a6f83462b (patch)
treec7d2323ddf7a0aa58d1b680200dc0acb9dad8558 /src/plugins/emoji.rs
parent1f69bfef7f2fd5fdc8787485d81461d68aa2d3ba (diff)
downloadfrippy-2ba26a37d27a637b7c0e02970419342a6f83462b.tar.gz
frippy-2ba26a37d27a637b7c0e02970419342a6f83462b.zip
Add evaluate function to plugins
This allows plugins to be used in combination with each other.
Diffstat (limited to 'src/plugins/emoji.rs')
-rw-r--r--src/plugins/emoji.rs21
1 files changed, 15 insertions, 6 deletions
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::<Vec<String>>();
-
- server.send_privmsg(target, &names.join(", "))
+ .collect::<Vec<String>>()
+ .join(", ")
}
fn return_emojis(&self, string: &str) -> Vec<EmojiHandle> {
@@ -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<String, String> {
+ let emojis = self.emoji(&command.tokens[0]);
+ if emojis.is_empty() {
+ Ok(emojis)
+ } else {
+ Err(String::from("No emojis were found."))
+ }
+ }
}
#[cfg(test)]