Last active
December 14, 2015 04:29
-
-
Save alyx/5028733 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "sigyn.h" | |
/*#include "db.h"*/ | |
#include "kclangc.h" | |
DECLARE_MODULE("contrib/factoid", MODULE_UNLOAD_CAPABILITY_OK, _modinit, _moddeinit, | |
"0.1", "Alyx <[email protected]>"); | |
static void cmd_fact(const irc_event_t *event, int parc, char **parv); | |
static KCDB *factdb; | |
void _modinit(UNUSED module_t *m) | |
{ | |
/*ret = db_create(&factdb, NULL, 0);*/ | |
/*ret = factdb->open(factdb, NULL, "facts.db", "",*/ | |
/*DB_BTREE, DB_CREATE, 0644);*/ | |
factdb = kcdbnew(); | |
if (!kcdbopen(factdb, "facts.kch", KCOWRITER | KCOCREATE)) | |
{ | |
fprintf(stderr, "open error: %s\n", kcecodename(kcdbecode(factdb))); | |
} | |
command_add("fact", cmd_fact, 2, AC_NONE, "Handles getting/adding of facts.", "<PUT|GET> <Key> [Value]"); | |
} | |
void _moddeinit(UNUSED module_unload_intent_t intent) | |
{ | |
kcdbclose(factdb); | |
kcdbdel(factdb); | |
command_del("fact", cmd_fact); | |
} | |
static void cmd_fact_get(const irc_event_t *event, int parc, char **parv) | |
{ | |
char *vbuf; | |
size_t vsiz; | |
/*i = factdb->get(factdb, NULL, &key, &data, 0);*/ | |
vbuf = kcdbget(factdb, parv[2], strlen(parv[2]), &vsiz); | |
command_reply(event->target, "%s: %s", parv[2], vbuf); | |
} | |
static void cmd_fact_put(const irc_event_t *event, int parc, char **parv) | |
{ | |
int i; | |
char *key, *tmp; | |
key = parv[2]; | |
printf("%s\n", event->data); | |
tmp = event->data; | |
for (i = 0; i < 3; ++i) | |
{ | |
tmp = strchr(tmp, ' '); | |
tmp++; | |
} | |
/*i = factdb->put(factdb, NULL, &dkey, &dval, 0);*/ | |
kcdbset(factdb, key, strlen(key), tmp, strlen(tmp)); | |
command_reply(event->target, "Key %s added (%d).", key, i); | |
} | |
static void cmd_fact(const irc_event_t *event, int parc, char **parv) | |
{ | |
if (strcasecmp(parv[1], "GET") == 0) | |
cmd_fact_get(event, parc, parv); | |
else if (strcasecmp(parv[1], "PUT") == 0) | |
cmd_fact_put(event, parc, parv); | |
else | |
command_fail(CMD_BADPARAM, event->origin, "FACT"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment