diff --git a/plugins/Aka/plugin.py b/plugins/Aka/plugin.py index 1f5a572ee..06dc85752 100644 --- a/plugins/Aka/plugin.py +++ b/plugins/Aka/plugin.py @@ -397,7 +397,7 @@ class Aka(callbacks.Plugin): def listCommands(self): commands = ['add', 'remove', 'lock', 'unlock', 'importaliasdatabase', - 'show', 'list', 'set'] + 'show', 'list', 'set', 'search'] return commands def getCommand(self, args, check_other_plugins=True): @@ -738,6 +738,26 @@ class Aka(callbacks.Plugin): irc.error(_("No Akas found.")) list = wrap(list, [getopts({'channel': 'channel', 'keys': ''})]) + def search(self, irc, msg, args, optlist, query): + """[--channel <#channel>] + + Searches Akas defined for . If is not specified, + searches all global Akas.""" + channel = 'global' + for (option, arg) in optlist: + if option == 'channel': + if not ircutils.isChannel(arg): + irc.error(_('%r is not a valid channel.') % arg, + Raise=True) + channel = arg + aka_list = self._db.get_aka_list(channel) + aka_list = [k[0] for k in aka_list] + if aka_list: + matching = [aka for aka in aka_list if query in aka] + irc.replies(matching) + else: + irc.error(_("No matching Akas found.")) + search = wrap(search, [getopts({'channel': 'channel'}), 'text']) Class = Aka diff --git a/plugins/Aka/test.py b/plugins/Aka/test.py index 87bb160aa..f888054f6 100644 --- a/plugins/Aka/test.py +++ b/plugins/Aka/test.py @@ -232,4 +232,11 @@ class AkaTestCase(PluginTestCase): self.assertNotError('aka add "foo bar" baz') self.assertRegexp('aka list', 'foo.*?bar \$\*.*?foo bar.*?baz \$\*') + def testSearch(self): + self.assertNotError('aka add foo bar') + self.assertNotError('aka add "many words" "much command"') + self.assertRegexp('aka search f', 'foo') + self.assertError('aka search abcdefghijklmnop') + self.assertRegexp('aka search many', 'many words') + # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: