diff --git a/plugins/MessageParser/plugin.py b/plugins/MessageParser/plugin.py index b14d0aad4..b63c1c202 100644 --- a/plugins/MessageParser/plugin.py +++ b/plugins/MessageParser/plugin.py @@ -182,7 +182,7 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler): db.commit() irc.replySuccess() else: - irc.reply('That trigger is locked.') + irc.error('That trigger is locked.') return add = wrap(add, ['channel', 'something', 'something']) @@ -206,11 +206,11 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler): if len(results) != 0: (id, locked) = map(int, results[0]) else: - irc.reply('There is no such regexp trigger.') + irc.error('There is no such regexp trigger.') return if locked: - irc.reply('This regexp trigger is locked.') + irc.error('This regexp trigger is locked.') return cursor.execute("""DELETE FROM triggers WHERE id=?""", (id,)) @@ -232,7 +232,7 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler): cursor.execute("SELECT id FROM triggers WHERE regexp=?", (regexp,)) results = cursor.fetchall() if len(results) == 0: - irc.reply('There is no such regexp trigger.') + irc.error('There is no such regexp trigger.') return cursor.execute("UPDATE triggers SET locked=1 WHERE regexp=?", (regexp,)) db.commit() @@ -251,7 +251,7 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler): cursor.execute("SELECT id FROM triggers WHERE regexp=?", (regexp,)) results = cursor.fetchall() if len(results) == 0: - irc.reply('There is no such regexp trigger.') + irc.error('There is no such regexp trigger.') return cursor.execute("UPDATE triggers SET locked=0 WHERE regexp=?", (regexp,)) db.commit() @@ -278,7 +278,7 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler): if len(results) != 0: (regexp, action) = results[0] else: - irc.reply('There is no such regexp trigger.') + irc.error('There is no such regexp trigger.') return irc.reply("The action for regexp trigger \"%s\" is \"%s\"" % (regexp, action)) @@ -304,12 +304,15 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler): cursor.execute(sql, (regexp,)) results = cursor.fetchall() if len(results) != 0: - (id, regexp, added_by, added_at, usage_count, action, locked) = results[0] + (id, regexp, added_by, added_at, usage_count, + action, locked) = results[0] else: - irc.reply('There is no such regexp trigger.') + irc.error('There is no such regexp trigger.') return - irc.reply("The regexp trigger id is %d, regexp is \"%s\", and action is \"%s\". It was added by user %s on %s, has been triggered %d times, and is %s." % (id, + irc.reply("The regexp id is %d, regexp is \"%s\", and action is" + " \"%s\". It was added by user %s on %s, has been " + "triggered %d times, and is %s." % (id, regexp, action, added_by, @@ -358,6 +361,9 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler): ORDER BY usage_count DESC LIMIT ?""", (numregexps,)) regexps = cursor.fetchall() + if len(regexps) == 0: + irc.reply('There are no regexp triggers in the database.') + return s = [ "#%d \"%s\" (%d)" % (i+1, regexp[0], regexp[1]) for i, regexp in enumerate(regexps) ] irc.reply(", ".join(s)) rank = wrap(rank, ['channel']) diff --git a/plugins/MessageParser/test.py b/plugins/MessageParser/test.py index 310a84e68..b03092f9c 100644 --- a/plugins/MessageParser/test.py +++ b/plugins/MessageParser/test.py @@ -71,5 +71,52 @@ class MessageParserTestCase(ChannelPluginTestCase): self.feedMsg('this message has some stuff in it') m = self.getMsg(' ') self.failUnless(str(m).startswith('PRIVMSG #test :i saw some stuff')) + + def testLock(self): + self.assertNotError('messageparser add "stuff" "echo i saw some stuff"') + self.assertNotError('messageparser lock "stuff"') + self.assertError('messageparser add "stuff" "echo some other stuff"') + self.assertError('messageparser remove "stuff"') + self.assertRegexp('messageparser info "stuff"', 'is locked') + + def testUnlock(self): + self.assertNotError('messageparser add "stuff" "echo i saw some stuff"') + self.assertNotError('messageparser lock "stuff"') + self.assertError('messageparser remove "stuff"') + self.assertNotError('messageparser unlock "stuff"') + self.assertRegexp('messageparser info "stuff"', 'is not locked') + self.assertNotError('messageparser remove "stuff"') + + def testRank(self): + self.assertRegexp('messageparser rank', + 'There are no regexp triggers in the database\.') + self.assertNotError('messageparser add "stuff" "echo i saw some stuff"') + self.assertRegexp('messageparser rank', '#1 "stuff" \(0\)') + self.assertNotError('messageparser add "aoeu" "echo vowels are nice!"') + self.assertRegexp('messageparser rank', '#1 "stuff" \(0\), #2 "aoeu" \(0\)') + self.feedMsg('instead of asdf, dvorak has aoeu') + self.getMsg(' ') + self.assertRegexp('messageparser rank', '#1 "aoeu" \(1\), #2 "stuff" \(0\)') + + def testList(self): + self.assertRegexp('messageparser list', + 'There are no regexp triggers in the database\.') + self.assertNotError('messageparser add "stuff" "echo i saw some stuff"') + self.assertRegexp('messageparser list', '"stuff" \(1\)') + self.assertNotError('messageparser add "aoeu" "echo vowels are nice!"') + self.assertRegexp('messageparser list', '"stuff" \(1\), "aoeu" \(2\)') + + def testRemove(self): + self.assertError('messageparser remove "stuff"') + self.assertNotError('messageparser add "stuff" "echo i saw some stuff"') + self.assertNotError('messageparser lock "stuff"') + self.assertError('messageparser remove "stuff"') + self.assertNotError('messageparser unlock "stuff"') + self.assertNotError('messageparser remove "stuff"') + self.assertNotError('messageparser add "stuff" "echo i saw some stuff"') + self.assertNotError('messageparser remove --id 1') + + def testVacuum(self): + pass # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: