mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 13:19:24 +01:00
Merge pull request #1160 from GLolol/aka/list-filter-lock-status
Aka: allow filtering 'list' by Aka lock status
This commit is contained in:
commit
9fba7668ec
@ -713,19 +713,32 @@ class Aka(callbacks.Plugin):
|
|||||||
importaliasdatabase = wrap(importaliasdatabase, ['owner'])
|
importaliasdatabase = wrap(importaliasdatabase, ['owner'])
|
||||||
|
|
||||||
def list(self, irc, msg, args, optlist):
|
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 Akas defined for <channel>. If <channel> is not specified,
|
||||||
lists all global Akas. If --keys is given, lists only the Aka names
|
lists all global Akas. If --keys is given, lists only the Aka names
|
||||||
and not their commands."""
|
and not their commands."""
|
||||||
channel = 'global'
|
channel = 'global'
|
||||||
|
filterlocked = filterunlocked = False
|
||||||
for (option, arg) in optlist:
|
for (option, arg) in optlist:
|
||||||
if option == 'channel':
|
if option == 'channel':
|
||||||
if not ircutils.isChannel(arg):
|
if not ircutils.isChannel(arg):
|
||||||
irc.error(_('%r is not a valid channel.') % arg,
|
irc.error(_('%r is not a valid channel.') % arg,
|
||||||
Raise=True)
|
Raise=True)
|
||||||
channel = arg
|
channel = arg
|
||||||
|
if option == 'locked':
|
||||||
|
filterlocked = True
|
||||||
|
if option == 'unlocked':
|
||||||
|
filterunlocked = True
|
||||||
aka_list = self._db.get_aka_list(channel)
|
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 aka_list:
|
||||||
if 'keys' in dict(optlist):
|
if 'keys' in dict(optlist):
|
||||||
# Strange, aka_list is a list of one length tuples
|
# Strange, aka_list is a list of one length tuples
|
||||||
@ -738,7 +751,8 @@ class Aka(callbacks.Plugin):
|
|||||||
irc.replies(s)
|
irc.replies(s)
|
||||||
else:
|
else:
|
||||||
irc.error(_("No Akas found."))
|
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):
|
def search(self, irc, msg, args, optlist, query):
|
||||||
"""[--channel <#channel>] <query>
|
"""[--channel <#channel>] <query>
|
||||||
|
@ -233,6 +233,19 @@ 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 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):
|
def testSearch(self):
|
||||||
self.assertNotError('aka add foo bar')
|
self.assertNotError('aka add foo bar')
|
||||||
self.assertNotError('aka add "many words" "much command"')
|
self.assertNotError('aka add "many words" "much command"')
|
||||||
|
Loading…
Reference in New Issue
Block a user