From d3429f32974e3b920fa9a1d86d1ce53f289ce8f7 Mon Sep 17 00:00:00 2001 From: cybojenix Date: Wed, 7 Aug 2013 14:29:51 +0100 Subject: [PATCH 1/2] implement a sed style correction method --- plugins/correction.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 plugins/correction.py diff --git a/plugins/correction.py b/plugins/correction.py new file mode 100644 index 0000000..5484bb0 --- /dev/null +++ b/plugins/correction.py @@ -0,0 +1,41 @@ +from util import hook +import re + +db_ready=False + +# from seen.py +def db_init(db): + "check to see that our db has the the correction table and return a connection." + db.execute("create table if not exists correct_user(name, quote, chan, " + "primary key(name, chan))") + db.commit() + db_ready = True + +@hook.singlethread +@hook.event('PRIVMSG') +def message_sieve(paraml, input=None, db=None, bot=None): + if not db_ready: + db_init(db) + if not re.findall('^s/.*/.*/$', input.msg.lower()): + db.execute("insert or replace into correct_user(name, quote, chan)" + "values(?,?,?)", (input.nick.lower(), input.msg, input.chan.lower())) + db.commit() + +@hook.regex(r'^(s|S)/.*/.*/$') +def correction(inp, say=None, input=None, notice=None, db=None): + if not db_ready: + db_init(db) + + last_message = db.execute("select name, quote from correct_user where name" + " like ? and chan = ?", (input.nick.lower(), input.chan.lower())).fetchone() + + if last_message: + splitinput = input.msg.split("/") + find = splitinput[1] + replace = splitinput[2] + if find in last_message[1]: + say("%s meant to say: %s" % (input.nick, last_message[1].replace(find, replace))) + else: + notice("%s can't be found in your last message" % find) + else: + notice("I haven't seen you say anything here yet") From 3204d15bde24724c5ebbb7ad279920ce7357e5b3 Mon Sep 17 00:00:00 2001 From: cybojenix Date: Wed, 7 Aug 2013 15:53:21 +0100 Subject: [PATCH 2/2] correction: update to use the seen_user db --- plugins/correction.py | 24 +----------------------- plugins/seen.py | 2 +- 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/plugins/correction.py b/plugins/correction.py index 5484bb0..f21d20d 100644 --- a/plugins/correction.py +++ b/plugins/correction.py @@ -1,32 +1,10 @@ from util import hook import re -db_ready=False - -# from seen.py -def db_init(db): - "check to see that our db has the the correction table and return a connection." - db.execute("create table if not exists correct_user(name, quote, chan, " - "primary key(name, chan))") - db.commit() - db_ready = True - -@hook.singlethread -@hook.event('PRIVMSG') -def message_sieve(paraml, input=None, db=None, bot=None): - if not db_ready: - db_init(db) - if not re.findall('^s/.*/.*/$', input.msg.lower()): - db.execute("insert or replace into correct_user(name, quote, chan)" - "values(?,?,?)", (input.nick.lower(), input.msg, input.chan.lower())) - db.commit() - @hook.regex(r'^(s|S)/.*/.*/$') def correction(inp, say=None, input=None, notice=None, db=None): - if not db_ready: - db_init(db) - last_message = db.execute("select name, quote from correct_user where name" + last_message = db.execute("select name, quote from seen_user where name" " like ? and chan = ?", (input.nick.lower(), input.chan.lower())).fetchone() if last_message: diff --git a/plugins/seen.py b/plugins/seen.py index 95762f4..aabacad 100755 --- a/plugins/seen.py +++ b/plugins/seen.py @@ -22,7 +22,7 @@ def seen_sieve(paraml, input=None, db=None, bot=None): if not db_ready: db_init(db) # keep private messages private - if input.chan[:1] == "#": + if input.chan[:1] == "#" and not re.findall('^s/.*/.*/$', input.msg.lower()): db.execute("insert or replace into seen_user(name, time, quote, chan, host)" "values(?,?,?,?,?)", (input.nick.lower(), time.time(), input.msg, input.chan, input.mask))