Merge pull request #1097 from GLolol/aka/search

Aka: add a 'search' command.
This commit is contained in:
Valentin Lorentz 2015-04-27 07:37:21 +02:00
commit fee531b5c2
2 changed files with 28 additions and 1 deletions

View File

@ -397,7 +397,7 @@ class Aka(callbacks.Plugin):
def listCommands(self): def listCommands(self):
commands = ['add', 'remove', 'lock', 'unlock', 'importaliasdatabase', commands = ['add', 'remove', 'lock', 'unlock', 'importaliasdatabase',
'show', 'list', 'set'] 'show', 'list', 'set', 'search']
return commands return commands
def getCommand(self, args, check_other_plugins=True): def getCommand(self, args, check_other_plugins=True):
@ -738,6 +738,26 @@ class Aka(callbacks.Plugin):
irc.error(_("No Akas found.")) irc.error(_("No Akas found."))
list = wrap(list, [getopts({'channel': 'channel', 'keys': ''})]) 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 Class = Aka

View File

@ -232,4 +232,11 @@ class AkaTestCase(PluginTestCase):
self.assertNotError('aka add "foo bar" baz') self.assertNotError('aka add "foo bar" baz')
self.assertRegexp('aka list', 'foo.*?bar \$\*.*?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: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: