This commit is contained in:
Ryan Hitchman 2010-03-22 02:16:59 -06:00
commit 0cfd902b41
3 changed files with 49 additions and 53 deletions

View File

@ -63,9 +63,9 @@ def run(func, input):
def do_sieve(sieve, bot, input, func, type, args):
try:
return sieve(bot, input, func, type, args)
except Exception, e:
except Exception:
print 'sieve error',
traceback.print_exc(Exception)
traceback.print_exc()
return None

View File

@ -53,8 +53,8 @@ def reload(init=False):
eval(compile(open(filename, 'U').read(), filename, 'exec'),
globals())
except Exception:
traceback.print_exc(Exception)
if init: # stop if there's a syntax error in a core
traceback.print_exc()
if init: # stop if there's an error (syntax?) in a core
sys.exit() # script on startup
continue
@ -90,7 +90,7 @@ def reload(init=False):
namespace = {}
eval(code, namespace)
except Exception:
traceback.print_exc(Exception)
traceback.print_exc()
continue
# remove plugins already loaded from this filename

View File

@ -6,10 +6,9 @@ from util import hook
def add_quote(db, chan, nick, add_nick, msg):
now = time.time()
db.execute('''insert or fail into quote (chan, nick, add_nick,
msg, time) values(?,?,?,?,?)''',
(chan, nick, add_nick, msg, now))
(chan, nick, add_nick, msg, time.time()))
db.commit()
@ -33,7 +32,7 @@ def format_quote(q, num, n_quotes):
@hook.command('q')
@hook.command
def quote(inp, nick='', chan='', db=None):
".q/.quote <nick/#chan> [#n]/.quote add <nick> <msg> -- gets " \
".q/.quote <nick|#chan> [#n]/.quote add <nick> <msg> -- gets " \
"random or [#n]th quote by <nick> or from <#chan>/adds quote"
db.execute("create table if not exists quote"
@ -41,14 +40,14 @@ def quote(inp, nick='', chan='', db=None):
"primary key (chan, nick, msg))")
db.commit()
try:
add = re.match(r"add\s+<?[^\w]?(\S+?)>?\s+(.*)", inp, re.I)
retrieve = re.match(r"(\S+)(?:\s+#?(-?\d+))?", inp)
add = re.match(r"add\W+(\S+?)>?\s+(.*)", inp, re.I)
retrieve = re.match(r"(\S+)(?:\s+#?(-?\d+))?$", inp)
if add:
quoted_nick, msg = add.groups()
try:
add_quote(db, chan, quoted_nick, nick, msg)
db.commit()
except db.IntegrityError:
return "message already stored, doing nothing."
return "quote added."
@ -86,6 +85,3 @@ def quote(inp, nick='', chan='', db=None):
return format_quote(selected_quote, num, n_quotes)
else:
return quote.__doc__
finally:
db.commit()
db.close()