Add IntRangeSetting, reorder OptionsSetting arg order
This commit is contained in:
parent
2c812ccaaa
commit
4bfb4c3200
5 changed files with 25 additions and 9 deletions
|
@ -13,8 +13,8 @@ KICK_REASON_SETTING = utils.Setting("default-kick-reason",
|
||||||
@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.OptionsSetting("mute-method",
|
@utils.export("serverset", utils.OptionsSetting(
|
||||||
["qmode", "insp", "unreal", "none"],
|
["qmode", "insp", "unreal", "none"], "mute-method",
|
||||||
"Set this server's method of muting users"))
|
"Set this server's method of muting users"))
|
||||||
@utils.export("botset", KICK_REASON_SETTING)
|
@utils.export("botset", KICK_REASON_SETTING)
|
||||||
@utils.export("serverset", KICK_REASON_SETTING)
|
@utils.export("serverset", KICK_REASON_SETTING)
|
||||||
|
|
|
@ -11,8 +11,8 @@ DEFAULT_MIN_MESSAGES = 100
|
||||||
|
|
||||||
@utils.export("channelset", utils.BoolSetting("ducks-enabled",
|
@utils.export("channelset", utils.BoolSetting("ducks-enabled",
|
||||||
"Whether or not to spawn ducks"))
|
"Whether or not to spawn ducks"))
|
||||||
@utils.export("channelset", utils.IntSetting("ducks-min-messages",
|
@utils.export("channelset", utils.IntRangeSetting(50, 200, "ducks-min-messages",
|
||||||
"Minimum messages between ducks spawning", example="50"))
|
"Minimum messages between ducks spawning"))
|
||||||
@utils.export("channelset", utils.BoolSetting("ducks-kick",
|
@utils.export("channelset", utils.BoolSetting("ducks-kick",
|
||||||
"Whether or not to kick someone talking to non-existent ducks"))
|
"Whether or not to kick someone talking to non-existent ducks"))
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
|
|
|
@ -9,9 +9,8 @@ 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.OptionsSetting("identity-mechanism",
|
@utils.export("serverset", utils.OptionsSetting(["internal", "ircv3-account"],
|
||||||
["internal", "ircv3-account"],
|
"identity-mechanism", "Set the identity mechanism for this server"))
|
||||||
"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):
|
||||||
|
|
|
@ -13,7 +13,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
|
|
||||||
self.exports.add("shorturl-s-bitly", self._bitly)
|
self.exports.add("shorturl-s-bitly", self._bitly)
|
||||||
|
|
||||||
setting = utils.OptionsSetting("url-shortener", [],
|
setting = utils.OptionsSetting([], "url-shortener",
|
||||||
"Set URL shortener service",
|
"Set URL shortener service",
|
||||||
options_factory=self._shorturl_options_factory)
|
options_factory=self._shorturl_options_factory)
|
||||||
self.exports.add("channelset", setting)
|
self.exports.add("channelset", setting)
|
||||||
|
|
|
@ -300,8 +300,25 @@ class IntSetting(Setting):
|
||||||
return int(stripped)
|
return int(stripped)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
class IntRangeSetting(IntSetting):
|
||||||
|
example = None
|
||||||
|
def __init__(self, n_min: int, n_max: int, name: str, help: str=None,
|
||||||
|
example: str=None):
|
||||||
|
self._n_min = n_min
|
||||||
|
self._n_max = n_max
|
||||||
|
Setting.__init__(self, name, help, example)
|
||||||
|
|
||||||
|
def parse(self, value: str) -> typing.Any:
|
||||||
|
out = IntSetting.parse(self, value)
|
||||||
|
if not out == None and self._n_min <= out <= self._n_max:
|
||||||
|
return out
|
||||||
|
return None
|
||||||
|
|
||||||
|
def _format_example(self):
|
||||||
|
return "Must be between %d and %d" % (self._n_min, self._n_max)
|
||||||
|
|
||||||
class OptionsSetting(Setting):
|
class OptionsSetting(Setting):
|
||||||
def __init__(self, name: str, options: typing.List[str], help: str=None,
|
def __init__(self, options: typing.List[str], name: str, help: str=None,
|
||||||
example: str=None,
|
example: str=None,
|
||||||
options_factory: typing.Callable[[], typing.List[str]]=None):
|
options_factory: typing.Callable[[], typing.List[str]]=None):
|
||||||
self._options = options
|
self._options = options
|
||||||
|
|
Loading…
Reference in a new issue