preserve usage count upon overwriting an existing regexp entry.

This commit is contained in:
Daniel F 2010-03-19 09:55:43 -04:00
parent 910ba732d2
commit adb53a0a35
1 changed files with 5 additions and 4 deletions

View File

@ -159,12 +159,13 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler):
etc. being interpolated from the regexp match groups.""" etc. being interpolated from the regexp match groups."""
db = self.getDb(channel) db = self.getDb(channel)
cursor = db.cursor() cursor = db.cursor()
cursor.execute("SELECT id, locked FROM triggers WHERE regexp=?", (regexp,)) cursor.execute("SELECT id, usage_count, locked FROM triggers WHERE regexp=?", (regexp,))
results = cursor.fetchall() results = cursor.fetchall()
if len(results) != 0: if len(results) != 0:
(id, locked) = map(int, results[0]) (id, usage_count, locked) = map(int, results[0])
else: else:
locked = False locked = 0
usage_count = 0
if not locked: if not locked:
if ircdb.users.hasUser(msg.prefix): if ircdb.users.hasUser(msg.prefix):
name = ircdb.users.getUser(msg.prefix).name name = ircdb.users.getUser(msg.prefix).name
@ -172,7 +173,7 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler):
name = msg.nick name = msg.nick
cursor.execute("""INSERT INTO triggers VALUES cursor.execute("""INSERT INTO triggers VALUES
(NULL, ?, ?, ?, ?, ?, ?)""", (NULL, ?, ?, ?, ?, ?, ?)""",
(regexp, name, int(time.time()), 0, action, 0,)) (regexp, name, int(time.time()), usage_count, action, locked,))
db.commit() db.commit()
irc.replySuccess() irc.replySuccess()
else: else: