From 3929022952ffbd5be0a9ba4ff074a735dea2aed1 Mon Sep 17 00:00:00 2001 From: Jokler Date: Sat, 30 Jun 2018 19:57:37 +0200 Subject: Plugins: Replace IrcClient with a trait This is to make it simpler to replace the client in the future. --- src/plugins/emoji.rs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'src/plugins/emoji.rs') diff --git a/src/plugins/emoji.rs b/src/plugins/emoji.rs index e4dffdb..01fb39c 100644 --- a/src/plugins/emoji.rs +++ b/src/plugins/emoji.rs @@ -1,10 +1,12 @@ extern crate unicode_names; use std::fmt; +use std::marker::PhantomData; use irc::client::prelude::*; use plugin::*; +use FrippyClient; use error::ErrorKind as FrippyErrorKind; use error::FrippyError; @@ -33,11 +35,15 @@ impl fmt::Display for EmojiHandle { } #[derive(PluginName, Default, Debug)] -pub struct Emoji; +pub struct Emoji { + phantom: PhantomData, +} -impl Emoji { - pub fn new() -> Emoji { - Emoji {} +impl Emoji { + pub fn new() -> Self { + Emoji { + phantom: PhantomData, + } } fn emoji(&self, content: &str) -> Option { @@ -102,8 +108,9 @@ impl Emoji { } } -impl Plugin for Emoji { - fn execute(&self, client: &IrcClient, message: &Message) -> ExecutionStatus { +impl Plugin for Emoji { + type Client = C; + fn execute(&self, client: &Self::Client, message: &Message) -> ExecutionStatus { match message.command { Command::PRIVMSG(_, ref content) => { if let Some(emojis) = self.emoji(content) { @@ -121,11 +128,11 @@ impl Plugin for Emoji { } } - fn execute_threaded(&self, _: &IrcClient, _: &Message) -> Result<(), FrippyError> { + fn execute_threaded(&self, _: &Self::Client, _: &Message) -> Result<(), FrippyError> { panic!("Emoji should not use threading") } - fn command(&self, client: &IrcClient, command: PluginCommand) -> Result<(), FrippyError> { + fn command(&self, client: &Self::Client, command: PluginCommand) -> Result<(), FrippyError> { client .send_notice( &command.source, @@ -136,7 +143,7 @@ impl Plugin for Emoji { Ok(()) } - fn evaluate(&self, _: &IrcClient, command: PluginCommand) -> Result { + fn evaluate(&self, _: &Self::Client, command: PluginCommand) -> Result { if let Some(emojis) = self.emoji(&command.tokens[0]) { Ok(emojis) } else { -- cgit v1.2.3-70-g09d2