aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/sed.rs
diff options
context:
space:
mode:
authorJokler <jokler.contact@gmail.com>2018-06-30 19:57:37 +0200
committerJokler <jokler.contact@gmail.com>2018-06-30 19:57:37 +0200
commit3929022952ffbd5be0a9ba4ff074a735dea2aed1 (patch)
tree0f2c3847f358c619059b151ea2c33bd2094063cd /src/plugins/sed.rs
parent82ab100c7e6334dc6fa92e92c8838ecc622118d5 (diff)
downloadfrippy-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/sed.rs')
-rw-r--r--src/plugins/sed.rs27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/plugins/sed.rs b/src/plugins/sed.rs
index 368f5d4..cf7f9d5 100644
--- a/src/plugins/sed.rs
+++ b/src/plugins/sed.rs
@@ -1,11 +1,14 @@
+use std::collections::HashMap;
+use std::marker::PhantomData;
+
use antidote::RwLock;
use circular_queue::CircularQueue;
use regex::{Regex, RegexBuilder};
-use std::collections::HashMap;
use irc::client::prelude::*;
use plugin::*;
+use FrippyClient;
use self::error::*;
use error::ErrorKind as FrippyErrorKind;
@@ -14,20 +17,23 @@ use failure::Fail;
use failure::ResultExt;
lazy_static! {
- static ref RE: Regex = Regex::new(r"^s/((?:\\/|[^/])+)/((?:\\/|[^/])*)/(?:(\w+))?\s*$").unwrap();
+ static ref RE: Regex =
+ Regex::new(r"^s/((?:\\/|[^/])+)/((?:\\/|[^/])*)/(?:(\w+))?\s*$").unwrap();
}
#[derive(PluginName, Debug)]
-pub struct Sed {
+pub struct Sed<C> {
per_channel: usize,
channel_messages: RwLock<HashMap<String, CircularQueue<String>>>,
+ phantom: PhantomData<C>,
}
-impl Sed {
- pub fn new(per_channel: usize) -> Sed {
+impl<C: FrippyClient> Sed<C> {
+ pub fn new(per_channel: usize) -> Self {
Sed {
per_channel,
channel_messages: RwLock::new(HashMap::new()),
+ phantom: PhantomData,
}
}
@@ -108,8 +114,9 @@ impl Sed {
}
}
-impl Plugin for Sed {
- fn execute(&self, client: &IrcClient, message: &Message) -> ExecutionStatus {
+impl<C: FrippyClient> Plugin for Sed<C> {
+ type Client = C;
+ fn execute(&self, client: &Self::Client, message: &Message) -> ExecutionStatus {
match message.command {
Command::PRIVMSG(_, ref content) => {
let channel = message.response_target().unwrap();
@@ -145,11 +152,11 @@ impl Plugin for Sed {
}
}
- fn execute_threaded(&self, _: &IrcClient, _: &Message) -> Result<(), FrippyError> {
+ fn execute_threaded(&self, _: &Self::Client, _: &Message) -> Result<(), FrippyError> {
panic!("Sed 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,
@@ -160,7 +167,7 @@ impl Plugin for Sed {
Ok(())
}
- fn evaluate(&self, _: &IrcClient, _: PluginCommand) -> Result<String, String> {
+ fn evaluate(&self, _: &Self::Client, _: PluginCommand) -> Result<String, String> {
Err(String::from(
"Evaluation of commands is not implemented for sed at this time",
))