aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/tell
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/tell')
-rw-r--r--src/plugins/tell/mod.rs34
1 files changed, 18 insertions, 16 deletions
diff --git a/src/plugins/tell/mod.rs b/src/plugins/tell/mod.rs
index 07b2478..eb7a244 100644
--- a/src/plugins/tell/mod.rs
+++ b/src/plugins/tell/mod.rs
@@ -1,3 +1,5 @@
+use std::marker::PhantomData;
+
use antidote::RwLock;
use irc::client::data::User;
use irc::client::prelude::*;
@@ -8,6 +10,7 @@ use std::time::Duration;
use time;
use plugin::*;
+use FrippyClient;
use self::error::*;
use error::ErrorKind as FrippyErrorKind;
@@ -19,22 +22,20 @@ pub mod database;
use self::database::Database;
#[derive(PluginName)]
-pub struct Tell<T: Database> {
+pub struct Tell<T: Database, C> {
tells: RwLock<T>,
+ phantom: PhantomData<C>,
}
-impl<T: Database> Tell<T> {
- pub fn new(db: T) -> Tell<T> {
+impl<T: Database, C: FrippyClient> Tell<T, C> {
+ pub fn new(db: T) -> Self {
Tell {
tells: RwLock::new(db),
+ phantom: PhantomData,
}
}
- fn tell_command(
- &self,
- client: &IrcClient,
- command: PluginCommand,
- ) -> Result<String, TellError> {
+ fn tell_command(&self, client: &C, command: PluginCommand) -> Result<String, TellError> {
if command.tokens.len() < 2 {
return Ok(self.invalid_command().to_owned());
}
@@ -105,7 +106,7 @@ impl<T: Database> Tell<T> {
})
}
- fn on_namelist(&self, client: &IrcClient, channel: &str) -> Result<(), FrippyError> {
+ fn on_namelist(&self, client: &C, channel: &str) -> Result<(), FrippyError> {
let receivers = self.tells
.read()
.get_receivers()
@@ -128,7 +129,7 @@ impl<T: Database> Tell<T> {
}
}
- fn send_tells(&self, client: &IrcClient, receiver: &str) -> Result<(), FrippyError> {
+ fn send_tells(&self, client: &C, receiver: &str) -> Result<(), FrippyError> {
if client.current_nickname() == receiver {
return Ok(());
}
@@ -187,8 +188,9 @@ impl<T: Database> Tell<T> {
}
}
-impl<T: Database> Plugin for Tell<T> {
- fn execute(&self, client: &IrcClient, message: &Message) -> ExecutionStatus {
+impl<T: Database, C: FrippyClient> Plugin for Tell<T, C> {
+ type Client = C;
+ fn execute(&self, client: &Self::Client, message: &Message) -> ExecutionStatus {
let res = match message.command {
Command::JOIN(_, _, _) => self.send_tells(client, message.source_nickname().unwrap()),
Command::NICK(ref nick) => self.send_tells(client, nick),
@@ -211,11 +213,11 @@ impl<T: Database> Plugin for Tell<T> {
}
}
- 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> {
if command.tokens.is_empty() {
client
.send_notice(&command.source, &self.invalid_command())
@@ -242,13 +244,13 @@ impl<T: Database> Plugin for Tell<T> {
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."))
}
}
use std::fmt;
-impl<T: Database> fmt::Debug for Tell<T> {
+impl<T: Database, C: FrippyClient> fmt::Debug for Tell<T, C> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Tell {{ ... }}")
}