summaryrefslogtreecommitdiffstats
path: root/src/plugins/factoids/mod.rs
diff options
context:
space:
mode:
authorJokler <jokler.contact@gmail.com>2017-12-24 02:00:00 +0100
committerJokler <jokler.contact@gmail.com>2017-12-24 02:00:00 +0100
commit5fdb7198bc73035cf5621ded8183000c3fcbbe29 (patch)
tree1979b49951737c521573949f5b16a7963a8ee2d2 /src/plugins/factoids/mod.rs
parent4b5693d3c6781a5ca4ef32f43f3994a65020c933 (diff)
downloadfrippy-5fdb7198bc73035cf5621ded8183000c3fcbbe29.tar.gz
frippy-5fdb7198bc73035cf5621ded8183000c3fcbbe29.zip
Add 'remove' command to Factoids and make the Database trait public
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),