This commit is contained in:
Luke Rogers 2012-08-21 08:32:12 +12:00
parent a1efe30f8f
commit d8d270a076

View file

@ -2,6 +2,7 @@
from util import hook, http from util import hook, http
from util.text import multiword_replace from util.text import multiword_replace
import string import string
import sqlite3
import re import re
re_lineends = re.compile(r'[\r\n]*') re_lineends = re.compile(r'[\r\n]*')
@ -17,6 +18,7 @@ shortcodes = {
def python(data, args, input): def python(data, args, input):
# this is all shit, replacement code is in the works
variables = "input='%s'; nick='%s'; chan='%s'; bot_nick='%s';" % (args, variables = "input='%s'; nick='%s'; chan='%s'; bot_nick='%s';" % (args,
input.nick, input.chan, input.conn.nick) input.nick, input.chan, input.conn.nick)
statement = variables + data statement = variables + data
@ -81,14 +83,14 @@ def remember(inp, nick='', db=None, say=None, input=None, notice=None):
if data: if data:
if append: if append:
notice("Appending %s to %s" % (new, data.replace('"', "''"))) notice("Appending \x02%s\x02 to \x02%s\x02" % (new, data))
else: else:
notice('Forgetting existing data (%s), remembering this instead!' notice('Remembering \x02%s\x02 for \x02%s\x02. Type ?%s to see it.'
% data.replace('"', "''")) % (tail, head, head))
return notice('Previous data was \x02%s\x02' % data)
else: else:
notice('Factoid created!') notice('Remembering \x02%s\x02 for \x02%s\x02. Type ?%s to see it.'
return % (tail, head, head))
@hook.command("f", adminonly=True) @hook.command("f", adminonly=True)
@ -109,7 +111,8 @@ def forget(inp, db=None, input=None, notice=None):
notice("I don't know about that.") notice("I don't know about that.")
return return
@hook.command()
@hook.command
def info(inp, notice=None, db=None): def info(inp, notice=None, db=None):
"info <factoid> -- Shows the source of a factoid." "info <factoid> -- Shows the source of a factoid."
@ -121,7 +124,7 @@ def info(inp, notice=None, db=None):
if data: if data:
notice(data) notice(data)
else: else:
notice("Unknown Factoid") notice("Unknown Factoid.")
@hook.regex(r'^\? ?(.+)') @hook.regex(r'^\? ?(.+)')
@ -133,11 +136,11 @@ def factoid(inp, say=None, db=None, bot=None, me=None, conn=None, input=None):
prefix_on = False prefix_on = False
db_init(db) db_init(db)
# split up the input # split up the input
split = inp.group(1).strip().split(" ") split = inp.group(1).strip().split(" ")
factoid_id = split[0] factoid_id = split[0]
if len(split) >= 1: if len(split) >= 1:
arguments = " ".join(split[1:]) arguments = " ".join(split[1:])
else: else:
@ -146,13 +149,12 @@ def factoid(inp, say=None, db=None, bot=None, me=None, conn=None, input=None):
data = get_memory(db, factoid_id) data = get_memory(db, factoid_id)
if data: if data:
# if the factoid starts with <py>, its a dynamic one # if the factoid starts with <py>, its a dynamic one
if data.startswith("<py>"): if data.startswith("<py>"):
result = python(data[4:].strip(), arguments, input) result = python(data[4:].strip(), arguments, input)
else: else:
result = data result = data
result = multiword_replace(result, shortcodes) result = multiword_replace(result, shortcodes)
if result.startswith("<act>"): if result.startswith("<act>"):