Implement utils.OptionsSetting
This commit is contained in:
parent
45565456ae
commit
756396d758
3 changed files with 18 additions and 4 deletions
|
@ -19,8 +19,9 @@ class InvalidTimeoutException(Exception):
|
||||||
@utils.export("channelset", utils.Setting("ban-format",
|
@utils.export("channelset", utils.Setting("ban-format",
|
||||||
"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.Setting("mute-method",
|
@utils.export("serverset", utils.OptionsSetting("mute-method",
|
||||||
"Set this server's method of muting users", example="qmode"))
|
["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"
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,9 @@ REQUIRES_IDENTIFY = "You need to be identified to use that command"
|
||||||
REQUIRES_IDENTIFY_INTERNAL = ("You need to be identified to use that command "
|
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.Setting("identity-mechanism",
|
@utils.export("serverset", utils.OptionsSetting("identity-mechanism",
|
||||||
"Set the identity mechanism for this server", example="ircv3-account"))
|
["internal", "ircv3-account"], "Set the identity mechanism for this server",
|
||||||
|
example="ircv3-account"))
|
||||||
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):
|
||||||
|
|
|
@ -257,3 +257,15 @@ class IntSetting(Setting):
|
||||||
return int(stripped)
|
return int(stripped)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
class OptionsSetting(Setting):
|
||||||
|
def __init__(self, name: str, options: typing.List[str], help: str=None,
|
||||||
|
example: str=None):
|
||||||
|
self._options = options
|
||||||
|
Setting.__init__(name, help, example)
|
||||||
|
|
||||||
|
def parse(self, value: str) -> typing.Any:
|
||||||
|
value_lower = value.lower()
|
||||||
|
for option in self._options:
|
||||||
|
if option.lower() == value_lower:
|
||||||
|
return option
|
||||||
|
return None
|
||||||
|
|
Loading…
Reference in a new issue