Config: Add @searchvalues.

This commit is contained in:
Valentin Lorentz 2020-05-08 20:24:47 +02:00
parent b07376d16f
commit bd1d7c9fa1
2 changed files with 30 additions and 1 deletions

View File

@ -206,6 +206,24 @@ class Config(callbacks.Plugin):
irc.reply(_('There were no matching configuration variables.'))
search = wrap(search, ['lowered']) # XXX compose with withoutSpaces?
@internationalizeDocstring
def searchvalues(self, irc, msg, args, word):
"""<word>
Searches for <word> in the values of current configuration variables.
"""
L = []
for (name, x) in conf.supybot.getValues(getChildren=True):
if (hasattr(x, 'value') # not a group
and word in str(x()).lower()):
last_name_part = registry.split(name)[-1]
L.append(name)
if L:
irc.reply(format('%L', L))
else:
irc.reply(_('There were no matching configuration variables.'))
searchvalues = wrap(searchvalues, ['lowered'])
def _getValue(self, irc, msg, group, network=None, channel=None, addGlobal=False):
global_group = group
global_value = str(group) or ' '

View File

@ -83,10 +83,21 @@ class ConfigTestCase(ChannelPluginTestCase):
self.assertNotError('config help %s' % name)
def testSearch(self):
self.assertNotError('config search chars')
self.assertRegexp(
'config search chars', 'supybot.reply.whenAddressedBy.chars')
self.assertNotError('config channel reply.whenAddressedBy.chars @')
self.assertNotRegexp('config search chars', self.channel)
def testSearchValues(self):
self.assertResponse(
'config searchvalues @@@',
'There were no matching configuration variables.')
self.assertNotError('config channel reply.whenAddressedBy.strings @@@')
self.assertResponse(
'config searchvalues @@@',
r'supybot.reply.whenAddressedBy.strings.#test and '
r'supybot.reply.whenAddressedBy.strings.\:test.#test')
def testDefault(self):
self.assertNotError('config default '
'supybot.replies.genericNoCapability')