Config: Add @searchhelp, to search in the help string of config vars and groups.

This commit is contained in:
Valentin Lorentz 2020-05-09 21:07:23 +02:00
parent ba0738c540
commit 4f027f2cbf
2 changed files with 27 additions and 0 deletions

View File

@ -206,6 +206,25 @@ class Config(callbacks.Plugin):
irc.reply(_('There were no matching configuration variables.'))
search = wrap(search, ['lowered']) # XXX compose with withoutSpaces?
@internationalizeDocstring
def searchhelp(self, irc, msg, args, phrase):
"""<phrase>
Searches for <phrase> in the help of current configuration variables.
"""
L = []
for (name, x) in conf.supybot.getValues(getChildren=True):
if phrase in x.help().lower():
last_name_part = registry.split(name)[-1]
if not irc.isChannel(last_name_part) \
and not last_name_part.startswith(':'): # network
L.append(name)
if L:
irc.reply(format('%L', L))
else:
irc.reply(_('There were no matching configuration variables.'))
searchhelp = wrap(searchhelp, ['lowered'])
@internationalizeDocstring
def searchvalues(self, irc, msg, args, word):
"""<word>

View File

@ -88,6 +88,14 @@ class ConfigTestCase(ChannelPluginTestCase):
self.assertNotError('config channel reply.whenAddressedBy.chars @')
self.assertNotRegexp('config search chars', self.channel)
def testSearchHelp(self):
self.assertRegexp(
'config searchhelp "what prefix characters"',
'supybot.reply.whenAddressedBy.chars')
self.assertNotError('config channel reply.whenAddressedBy.chars @')
self.assertNotRegexp(
'config searchhelp "what prefix characters"', self.channel)
def testSearchValues(self):
self.assertResponse(
'config searchvalues @@@',