Automatically format example
text for OptionsSetting (showing options)
This commit is contained in:
parent
a732bcfc25
commit
b4c762eb4e
4 changed files with 21 additions and 8 deletions
|
@ -20,8 +20,7 @@ class InvalidTimeoutException(Exception):
|
||||||
"Set ban format ($n = nick, $u = username, $h = hostname)",
|
"Set ban format ($n = nick, $u = username, $h = hostname)",
|
||||||
example="*!$u@$h"))
|
example="*!$u@$h"))
|
||||||
@utils.export("serverset", utils.OptionsSetting("mute-method",
|
@utils.export("serverset", utils.OptionsSetting("mute-method",
|
||||||
["qmode", "insp", "unreal"], "Set this server's method of muting users",
|
["qmode", "insp", "unreal"], "Set this server's method of muting users"))
|
||||||
example="qmode"))
|
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
_name = "ChanOp"
|
_name = "ChanOp"
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
if setting_info:
|
if setting_info:
|
||||||
value = target.get_setting(require_setting, None)
|
value = target.get_setting(require_setting, None)
|
||||||
if value == None:
|
if value == None:
|
||||||
example = setting_info.exaple or "<value>"
|
example = setting_info.get_example() or "<value>"
|
||||||
return "Please set %s, e.g.: %sconfig %s %s %s" % (
|
return "Please set %s, e.g.: %sconfig %s %s %s" % (
|
||||||
require_setting, event["command_prefix"], context[0],
|
require_setting, event["command_prefix"], context[0],
|
||||||
require_setting, example)
|
require_setting, example)
|
||||||
|
@ -180,9 +180,9 @@ class Module(ModuleManager.BaseModule):
|
||||||
try:
|
try:
|
||||||
result = self._config(export_settings, target, setting, value)
|
result = self._config(export_settings, target, setting, value)
|
||||||
except ConfigInvalidValue:
|
except ConfigInvalidValue:
|
||||||
example = export_settings[setting].example
|
example = export_settings[setting].get_example()
|
||||||
if not example == None:
|
if not example == None:
|
||||||
raise utils.EventError("Invalid value. Example: %s" %
|
raise utils.EventError("Invalid value. %s" %
|
||||||
example)
|
example)
|
||||||
else:
|
else:
|
||||||
raise utils.EventError("Invalid value")
|
raise utils.EventError("Invalid value")
|
||||||
|
|
|
@ -10,8 +10,8 @@ REQUIRES_IDENTIFY_INTERNAL = ("You need to be identified to use that command "
|
||||||
"(/msg %s register | /msg %s identify)")
|
"(/msg %s register | /msg %s identify)")
|
||||||
|
|
||||||
@utils.export("serverset", utils.OptionsSetting("identity-mechanism",
|
@utils.export("serverset", utils.OptionsSetting("identity-mechanism",
|
||||||
["internal", "ircv3-account"], "Set the identity mechanism for this server",
|
["internal", "ircv3-account"],
|
||||||
example="ircv3-account"))
|
"Set the identity mechanism for this server"))
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
@utils.hook("new.user")
|
@utils.hook("new.user")
|
||||||
def new_user(self, event):
|
def new_user(self, event):
|
||||||
|
|
|
@ -230,13 +230,23 @@ def is_main_thread() -> bool:
|
||||||
return threading.current_thread() is threading.main_thread()
|
return threading.current_thread() is threading.main_thread()
|
||||||
|
|
||||||
class Setting(object):
|
class Setting(object):
|
||||||
|
example: str = None
|
||||||
def __init__(self, name: str, help: str=None, example: str=None):
|
def __init__(self, name: str, help: str=None, example: str=None):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.help = help
|
self.help = help
|
||||||
self.example = example
|
if not example == None:
|
||||||
|
self.example = example
|
||||||
def parse(self, value: str) -> typing.Any:
|
def parse(self, value: str) -> typing.Any:
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
def get_example(self):
|
||||||
|
if not self.example == None:
|
||||||
|
return "Example: %s" % self.example
|
||||||
|
else:
|
||||||
|
return self._format_example()
|
||||||
|
def _format_example(self):
|
||||||
|
return None
|
||||||
|
|
||||||
SETTING_TRUE = ["true", "yes", "on", "y"]
|
SETTING_TRUE = ["true", "yes", "on", "y"]
|
||||||
SETTING_FALSE = ["false", "no", "off", "n"]
|
SETTING_FALSE = ["false", "no", "off", "n"]
|
||||||
class BoolSetting(Setting):
|
class BoolSetting(Setting):
|
||||||
|
@ -269,3 +279,7 @@ class OptionsSetting(Setting):
|
||||||
if option.lower() == value_lower:
|
if option.lower() == value_lower:
|
||||||
return option
|
return option
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def _format_example(self):
|
||||||
|
options = ["'%s'" % option for option in self._options]
|
||||||
|
return "Options: %s" % ", ".join(options)
|
||||||
|
|
Loading…
Reference in a new issue