make quote deletion admin-only

This commit is contained in:
Ryan Hitchman 2014-04-30 13:17:39 -07:00
parent 18159024c7
commit 08ea88afd2
1 changed files with 14 additions and 13 deletions

View File

@ -12,10 +12,10 @@ def add_quote(db, chan, nick, add_nick, msg):
db.commit() db.commit()
def del_quote(db, chan, nick, add_nick, msg): def del_quote(db, chan, nick, msg):
updated = db.execute('''update quote set deleted = 1 where updated = db.execute('''update quote set deleted = 1 where
chan=? and lower(nick)=lower(?) and msg=?''', chan=? and lower(nick)=lower(?) and msg=?''',
(chan, nick, msg) ) (chan, nick, msg))
db.commit() db.commit()
if updated.rowcount == 0: if updated.rowcount == 0:
@ -43,10 +43,10 @@ def format_quote(q, num, n_quotes):
@hook.command('q') @hook.command('q')
@hook.command @hook.command
def quote(inp, nick='', chan='', db=None): def quote(inp, nick='', chan='', db=None, admin=False):
".q/.quote [#chan] [nick] [#n]/.quote add <nick> <msg>/.quote delete <nick> <msg> -- gets " \ ".q/.quote [#chan] [nick] [#n]/.quote add|delete <nick> <msg> -- gets " \
"random or [#n]th quote by <nick> or from <#chan>/adds quote" \ "random or [#n]th quote by <nick> or from <#chan>/adds or deletes " \
"/deletes quote" "quote"
db.execute("create table if not exists quote" db.execute("create table if not exists quote"
"(chan, nick, add_nick, msg, time real, deleted default 0, " "(chan, nick, add_nick, msg, time real, deleted default 0, "
@ -67,10 +67,11 @@ def quote(inp, nick='', chan='', db=None):
return "message already stored, doing nothing." return "message already stored, doing nothing."
return "quote added." return "quote added."
if delete: if delete:
if not admin:
return 'only admins can delete quotes'
quoted_nick, msg = delete.groups() quoted_nick, msg = delete.groups()
didDelete = del_quote(db, chan, quoted_nick, nick, msg) if del_quote(db, chan, quoted_nick, msg):
if didDelete: return "deleted quote '%s'" % msg
return "deleted quote '" + str(msg) + "'";
else: else:
return "found no matching quotes to delete" return "found no matching quotes to delete"
elif retrieve: elif retrieve: