make quote deletion admin-only
This commit is contained in:
parent
18159024c7
commit
08ea88afd2
|
@ -12,18 +12,18 @@ 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:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def get_quotes_by_nick(db, chan, nick):
|
def get_quotes_by_nick(db, chan, nick):
|
||||||
return db.execute("select time, nick, msg from quote where deleted!=1 "
|
return db.execute("select time, nick, msg from quote where deleted!=1 "
|
||||||
"and chan=? and lower(nick)=lower(?) order by time",
|
"and chan=? and lower(nick)=lower(?) order by time",
|
||||||
|
@ -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:
|
||||||
|
|
Loading…
Reference in New Issue