diff options
| author | Jokler <jokler.contact@gmail.com> | 2018-06-30 19:57:37 +0200 |
|---|---|---|
| committer | Jokler <jokler.contact@gmail.com> | 2018-06-30 19:57:37 +0200 |
| commit | 3929022952ffbd5be0a9ba4ff074a735dea2aed1 (patch) | |
| tree | 0f2c3847f358c619059b151ea2c33bd2094063cd /src/plugins/keepnick.rs | |
| parent | 82ab100c7e6334dc6fa92e92c8838ecc622118d5 (diff) | |
| download | frippy-3929022952ffbd5be0a9ba4ff074a735dea2aed1.tar.gz frippy-3929022952ffbd5be0a9ba4ff074a735dea2aed1.zip | |
Plugins: Replace IrcClient with a trait
This is to make it simpler to replace the
client in the future.
Diffstat (limited to 'src/plugins/keepnick.rs')
| -rw-r--r-- | src/plugins/keepnick.rs | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/src/plugins/keepnick.rs b/src/plugins/keepnick.rs index a728c63..6ba16c1 100644 --- a/src/plugins/keepnick.rs +++ b/src/plugins/keepnick.rs @@ -1,20 +1,27 @@ +use std::marker::PhantomData; + use irc::client::prelude::*; use plugin::*; +use FrippyClient; use error::ErrorKind as FrippyErrorKind; use error::FrippyError; use failure::ResultExt; #[derive(PluginName, Default, Debug)] -pub struct KeepNick; +pub struct KeepNick<C> { + phantom: PhantomData<C>, +} -impl KeepNick { - pub fn new() -> KeepNick { - KeepNick {} +impl<C: FrippyClient> KeepNick<C> { + pub fn new() -> Self { + KeepNick { + phantom: PhantomData, + } } - fn check_nick(&self, client: &IrcClient, leaver: &str) -> ExecutionStatus { + fn check_nick(&self, client: &C, leaver: &str) -> ExecutionStatus { let cfg_nick = match client.config().nickname { Some(ref nick) => nick.clone(), None => return ExecutionStatus::Done, @@ -41,8 +48,9 @@ impl KeepNick { } } -impl Plugin for KeepNick { - fn execute(&self, client: &IrcClient, message: &Message) -> ExecutionStatus { +impl<C: FrippyClient> Plugin for KeepNick<C> { + type Client = C; + fn execute(&self, client: &Self::Client, message: &Message) -> ExecutionStatus { match message.command { Command::QUIT(ref nick) => { self.check_nick(client, &nick.clone().unwrap_or_else(String::new)) @@ -51,11 +59,11 @@ impl Plugin for KeepNick { } } - fn execute_threaded(&self, _: &IrcClient, _: &Message) -> Result<(), FrippyError> { + fn execute_threaded(&self, _: &Self::Client, _: &Message) -> Result<(), FrippyError> { panic!("Tell 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, @@ -66,7 +74,7 @@ impl Plugin for KeepNick { Ok(()) } - fn evaluate(&self, _: &IrcClient, _: PluginCommand) -> Result<String, String> { + fn evaluate(&self, _: &Self::Client, _: PluginCommand) -> Result<String, String> { Err(String::from("This Plugin does not implement any commands.")) } } |
