implemented delete
del_quote function was defined, but couldn't be called from the command parser
This commit is contained in:
parent
bcc253fcd8
commit
2e44b5212d
|
@ -13,11 +13,17 @@ def add_quote(db, chan, nick, add_nick, msg):
|
||||||
|
|
||||||
|
|
||||||
def del_quote(db, chan, nick, add_nick, msg):
|
def del_quote(db, chan, nick, add_nick, msg):
|
||||||
db.execute('''update quote set deleted = 1 where
|
updated = db.execute('''update quote set deleted = 1 where
|
||||||
chan=? and lower(nick)=lower(?) and msg=msg''')
|
chan=? and lower(nick)=lower(?) and msg=?''',
|
||||||
|
(chan, nick, msg) )
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
|
if updated.rowcount == 0:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
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",
|
||||||
|
@ -38,8 +44,9 @@ 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):
|
||||||
".q/.quote [#chan] [nick] [#n]/.quote add <nick> <msg> -- gets " \
|
".q/.quote [#chan] [nick] [#n]/.quote add <nick> <msg>/.quote 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 quote" \
|
||||||
|
"/deletes 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, "
|
||||||
|
@ -47,6 +54,7 @@ def quote(inp, nick='', chan='', db=None):
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
add = re.match(r"add[^\w@]+(\S+?)>?\s+(.*)", inp, re.I)
|
add = re.match(r"add[^\w@]+(\S+?)>?\s+(.*)", inp, re.I)
|
||||||
|
delete = re.match(r"delete[^\w@]+(\S+?)>?\s+(.*)", inp, re.I)
|
||||||
retrieve = re.match(r"(\S+)(?:\s+#?(-?\d+))?$", inp)
|
retrieve = re.match(r"(\S+)(?:\s+#?(-?\d+))?$", inp)
|
||||||
retrieve_chan = re.match(r"(#\S+)\s+(\S+)(?:\s+#?(-?\d+))?$", inp)
|
retrieve_chan = re.match(r"(#\S+)\s+(\S+)(?:\s+#?(-?\d+))?$", inp)
|
||||||
|
|
||||||
|
@ -58,6 +66,13 @@ def quote(inp, nick='', chan='', db=None):
|
||||||
except db.IntegrityError:
|
except db.IntegrityError:
|
||||||
return "message already stored, doing nothing."
|
return "message already stored, doing nothing."
|
||||||
return "quote added."
|
return "quote added."
|
||||||
|
if delete:
|
||||||
|
quoted_nick, msg = delete.groups()
|
||||||
|
didDelete = del_quote(db, chan, quoted_nick, nick, msg)
|
||||||
|
if didDelete:
|
||||||
|
return "deleted quote '" + str(msg) + "'";
|
||||||
|
else:
|
||||||
|
return "found no matching quotes to delete"
|
||||||
elif retrieve:
|
elif retrieve:
|
||||||
select, num = retrieve.groups()
|
select, num = retrieve.groups()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue