aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/factoids/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/factoids/mod.rs')
-rw-r--r--src/plugins/factoids/mod.rs20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/plugins/factoids/mod.rs b/src/plugins/factoids/mod.rs
index bb83700..fcbbb79 100644
--- a/src/plugins/factoids/mod.rs
+++ b/src/plugins/factoids/mod.rs
@@ -11,7 +11,7 @@ use time;
use chrono::NaiveDateTime;
use plugin::*;
-mod database;
+pub mod database;
use self::database::{Database, DbResponse};
static LUA_SANDBOX: &'static str = include_str!("sandbox.lua");
@@ -63,6 +63,23 @@ impl<T: Database> Factoids<T> {
}
}
+ fn remove(&self, server: &IrcServer, command: &mut PluginCommand) -> Result<(), IrcError> {
+ if command.tokens.len() < 1 {
+ return self.invalid_command(server, command);
+ }
+
+ let name = command.tokens.remove(0);
+ let count = match try_lock!(self.factoids).count(&name) {
+ Ok(c) => c,
+ Err(e) => return server.send_notice(&command.source, e),
+ };
+
+ match try_lock!(self.factoids).delete(&name, count - 1) {
+ DbResponse::Success => server.send_notice(&command.source, "Successfully removed"),
+ DbResponse::Failed(e) => server.send_notice(&command.source, &e),
+ }
+ }
+
fn get(&self, server: &IrcServer, command: &PluginCommand) -> Result<(), IrcError> {
let (name, idx) = match command.tokens.len() {
@@ -257,6 +274,7 @@ impl<T: Database> Plugin for Factoids<T> {
let sub_command = command.tokens.remove(0);
match sub_command.as_ref() {
"add" => self.add(server, &mut command),
+ "remove" => self.remove(server, &mut command),
"get" => self.get(server, &command),
"info" => self.info(server, &command),
"exec" => self.exec(server, command, true),