From dbd12e9c0c749cf7bb2f65f095400b36c4336a5c Mon Sep 17 00:00:00 2001 From: James Lu Date: Sat, 29 Aug 2015 17:18:57 -0700 Subject: [PATCH] Aka: allow filtering 'list' by Aka lock status This adds two mutually incompatible options to Aka list: --locked and --unlocked --- plugins/Aka/plugin.py | 18 ++++++++++++++++-- plugins/Aka/test.py | 15 ++++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/plugins/Aka/plugin.py b/plugins/Aka/plugin.py index 4fb2f1fdf..9b515050b 100644 --- a/plugins/Aka/plugin.py +++ b/plugins/Aka/plugin.py @@ -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 . If 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>] diff --git a/plugins/Aka/test.py b/plugins/Aka/test.py index 3f581e3df..2dac1d8e8 100644 --- a/plugins/Aka/test.py +++ b/plugins/Aka/test.py @@ -103,7 +103,7 @@ class AkaChannelTestCase(ChannelPluginTestCase): self.assertNotError('aka add spam "echo [echo $*]"') self.assertResponse('spam egg', 'egg') self.assertResponse('spam egg bacon', 'egg bacon') - + def testChannel(self): self.assertNotError('aka add channel echo $channel') self.assertResponse('aka channel', self.channel) @@ -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"')