allow remove by id, if --id is specified.

This commit is contained in:
Daniel F 2010-03-19 13:40:36 -04:00
parent 7909015288
commit 4972472764

View File

@ -186,16 +186,22 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler):
return return
add = wrap(add, ['channel', 'something', 'something']) add = wrap(add, ['channel', 'something', 'something'])
def remove(self, irc, msg, args, channel, regexp): def remove(self, irc, msg, args, channel, optlist, regexp):
"""[<channel>] <regexp>] """[<channel>] [--id] <regexp>]
Removes the trigger for <regexp> from the triggers database. Removes the trigger for <regexp> from the triggers database.
<channel> is only necessary if <channel> is only necessary if
the message isn't sent in the channel itself. the message isn't sent in the channel itself.
If option --id specified, will retrieve by regexp id, not content.
""" """
db = self.getDb(channel) db = self.getDb(channel)
cursor = db.cursor() cursor = db.cursor()
cursor.execute("SELECT id, locked FROM triggers WHERE regexp=?", (regexp,)) target = 'regexp'
for (option, arg) in optlist:
if option == 'id':
target = 'id'
sql = "SELECT id, locked FROM triggers WHERE %s=?" % (target,)
cursor.execute(sql, (regexp,))
results = cursor.fetchall() results = cursor.fetchall()
if len(results) != 0: if len(results) != 0:
(id, locked) = map(int, results[0]) (id, locked) = map(int, results[0])
@ -210,7 +216,9 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler):
cursor.execute("""DELETE FROM triggers WHERE id=?""", (id,)) cursor.execute("""DELETE FROM triggers WHERE id=?""", (id,))
db.commit() db.commit()
irc.replySuccess() irc.replySuccess()
remove = wrap(remove, ['channel', 'something']) remove = wrap(remove, ['channel',
getopts({'id': '',}),
'something'])
def lock(self, irc, msg, args, channel, regexp): def lock(self, irc, msg, args, channel, regexp):
"""[<channel>] <regexp> """[<channel>] <regexp>