Aka: add a 'search' command.

Closes ProgVal/Limnoria#1081.
This commit is contained in:
James Lu 2015-04-26 22:08:01 -07:00
parent a7b1e65bd9
commit 308eea922e
2 changed files with 28 additions and 1 deletions

View File

@ -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>] <query>
Searches Akas defined for <channel>. If <channel> 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

View File

@ -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: