mirror of
				https://github.com/Mikaela/Limnoria.git
				synced 2025-11-04 01:27:21 +01:00 
			
		
		
		
	Aka: allow filtering 'list' by Aka lock status
This adds two mutually incompatible options to Aka list: --locked and --unlocked
This commit is contained in:
		
							parent
							
								
									b375390bca
								
							
						
					
					
						commit
						dbd12e9c0c
					
				@ -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>
 | 
			
		||||
 | 
			
		||||
@ -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"')
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user