Merge pull request #1160 from GLolol/aka/list-filter-lock-status

Aka: allow filtering 'list' by Aka lock status
This commit is contained in:
Valentin Lorentz 2015-08-30 09:49:34 +02:00
commit 9fba7668ec
2 changed files with 30 additions and 3 deletions

View File

@ -713,19 +713,32 @@ class Aka(callbacks.Plugin):
importaliasdatabase = wrap(importaliasdatabase, ['owner'])
def list(self, irc, msg, args, optlist):
"""[--channel <#channel>] [--keys]
"""[--channel <#channel>] [--keys] [--unlocked|--locked]
Lists all Akas defined for <channel>. If <channel> is not specified,
lists all global Akas. If --keys is given, lists only the Aka names
and not their commands."""
channel = 'global'
filterlocked = filterunlocked = False
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
if option == 'locked':
filterlocked = True
if option == 'unlocked':
filterunlocked = True
aka_list = self._db.get_aka_list(channel)
if filterlocked and filterunlocked:
irc.error(_('--locked and --unlocked are incompatible options.'), Raise=True)
elif filterlocked:
aka_list = [aka for aka in aka_list if
self._db.get_aka_lock(channel, aka)[0]]
elif filterunlocked:
aka_list = [aka for aka in aka_list if not
self._db.get_aka_lock(channel, aka)[0]]
if aka_list:
if 'keys' in dict(optlist):
# Strange, aka_list is a list of one length tuples
@ -738,7 +751,8 @@ class Aka(callbacks.Plugin):
irc.replies(s)
else:
irc.error(_("No Akas found."))
list = wrap(list, [getopts({'channel': 'channel', 'keys': ''})])
list = wrap(list, [getopts({'channel': 'channel', 'keys': '', 'locked': '',
'unlocked': ''})])
def search(self, irc, msg, args, optlist, query):
"""[--channel <#channel>] <query>

View File

@ -233,6 +233,19 @@ class AkaTestCase(PluginTestCase):
self.assertNotError('aka add "foo bar" baz')
self.assertRegexp('aka list', 'foo.*?bar \$\*.*?foo bar.*?baz \$\*')
def testListLockedUnlocked(self):
self.assertNotError('register tacocat hunter2')
self.assertNotError('aka add foo bar')
self.assertNotError('aka add abcd echo hi')
self.assertNotError('aka lock foo')
self.assertRegexp('aka list --locked', 'foo')
self.assertNotRegexp('aka list --locked', 'abcd')
self.assertNotRegexp('aka list --unlocked', 'foo')
self.assertRegexp('aka list --unlocked', 'abcd')
# Can't look up both.
self.assertError('aka list --locked --unlocked abcd')
def testSearch(self):
self.assertNotError('aka add foo bar')
self.assertNotError('aka add "many words" "much command"')