diff options
| author | Jokler <jokler.contact@gmail.com> | 2017-10-29 17:09:04 +0100 |
|---|---|---|
| committer | Jokler <jokler.contact@gmail.com> | 2017-12-24 00:21:43 +0100 |
| commit | f3d679da59a64711ef96042668b26dffd1e662d5 (patch) | |
| tree | 1d24afeb7ab6a364b433e30bb23f821d19ccf90d /src/plugins/factoids/mod.rs | |
| parent | aa2e6dc0103c303aac0dd688d90c8547b22f8a47 (diff) | |
| download | frippy-f3d679da59a64711ef96042668b26dffd1e662d5.tar.gz frippy-f3d679da59a64711ef96042668b26dffd1e662d5.zip | |
Add Database trait to be used by the Factoids plugin
Diffstat (limited to 'src/plugins/factoids/mod.rs')
| -rw-r--r-- | src/plugins/factoids/mod.rs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/plugins/factoids/mod.rs b/src/plugins/factoids/mod.rs index c69042f..a13bba6 100644 --- a/src/plugins/factoids/mod.rs +++ b/src/plugins/factoids/mod.rs @@ -4,16 +4,17 @@ use self::rlua::prelude::*; use irc::client::prelude::*; use irc::error::Error as IrcError; -use std::collections::HashMap; use std::sync::Mutex; use plugin::*; +mod database; +use self::database::*; static LUA_SANDBOX: &'static str = include_str!("sandbox.lua"); #[derive(PluginName, Debug)] -pub struct Factoids { - factoids: Mutex<HashMap<String, String>>, +pub struct Factoids<T: Database> { + factoids: Mutex<T>, } macro_rules! try_lock { @@ -25,9 +26,9 @@ macro_rules! try_lock { } } -impl Factoids { - pub fn new() -> Factoids { - Factoids { factoids: Mutex::new(HashMap::new()) } +impl<T: Database> Factoids<T> { + pub fn new(db: T) -> Factoids<T> { + Factoids { factoids: Mutex::new(db) } } fn add(&self, server: &IrcServer, command: &mut PluginCommand) -> Result<(), IrcError> { @@ -128,7 +129,7 @@ impl Factoids { } } -impl Plugin for Factoids { +impl<T: Database> Plugin for Factoids<T> { fn is_allowed(&self, _: &IrcServer, message: &Message) -> bool { match message.command { Command::PRIVMSG(_, ref content) => content.starts_with('!'), |
