!mute -> !quiet, refactor quiets to be mode,prefix,listnum,endnum

This commit is contained in:
jesopo 2020-01-22 10:49:21 +00:00
parent 10676d70a6
commit 572998c0eb

View file

@ -5,6 +5,12 @@
from src import ModuleManager, utils from src import ModuleManager, utils
QUIET_METHODS = {
"qmode": ["q", "", "728", "729"],
"insp": ["b", "m:", "367", "368"],
"insp": ["b", "~q:", "367", "368"]
}
KICK_REASON = "your behavior is not conducive to the desired environment" KICK_REASON = "your behavior is not conducive to the desired environment"
KICK_REASON_SETTING = utils.Setting("default-kick-reason", KICK_REASON_SETTING = utils.Setting("default-kick-reason",
@ -19,7 +25,7 @@ KICK_REASON_SETTING = utils.Setting("default-kick-reason",
"($n = nick, $u = username, $h = hostname, $a = account)", example="~a:$a")) "($n = nick, $u = username, $h = hostname, $a = account)", example="~a:$a"))
@utils.export("serverset", utils.OptionsSetting( @utils.export("serverset", utils.OptionsSetting(
["qmode", "insp", "unreal", "none"], "mute-method", ["qmode", "insp", "unreal", "none"], "quiet-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)
@ -176,29 +182,40 @@ class Module(ModuleManager.BaseModule):
def tappend(self, event): def tappend(self, event):
event["target"].send_topic(event["target"].topic + event["args"]) event["target"].send_topic(event["target"].topic + event["args"])
def _mute_method(self, server, channel, user): def _quiet_method(self, server):
mask = self._get_hostmask(channel, user) quiet_method = server.get_setting("quiet-method", "qmode").lower()
mute_method = server.get_setting("mute-method", "qmode").lower()
if mute_method == "qmode": if quiet_method in QUIET_METHODS:
return "q", mask mode, prefix, list, start = QUIET_METHODS[quiet_method]
elif mute_method == "insp": return mode, prefix
return "b", "m:%s" % mask
elif mute_method == "unreal":
return "b", "~q:%s" % mask
elif mute_method == "none": elif mute_method == "none":
return None, None return None, None
else:
raise ValueError("Unknown mute-method '%s'" % mute_method) raise ValueError("Unknown mute-method '%s'" % mute_method)
@utils.hook("received.command.mute", usage="[+time] <nickname>") @utils.hook("received.command.quiet")
@utils.hook("received.command.unmute", usage="<nickname>") @utils.hook("received.command.mute")
@utils.kwarg("min_args", 1) @utils.kwarg("min_args", 1)
@utils.kwarg("usage", "[+time] <nickname>")
@utils.kwarg("channel_only", True) @utils.kwarg("channel_only", True)
@utils.kwarg("require_mode", "o") @utils.kwarg("require_mode", "o")
@utils.kwarg("require_access", "mute") @utils.kwarg("require_access", "quiet")
@utils.kwarg("help", "Mute a given user") @utils.kwarg("help", "Quiet a given user")
def _mute(self, event): def quiet(self, event):
add = event["command"] == "mute" self._quiet(event, True)
@utils.hook("received.command.unquiet")
@utils.hook("received.command.unmute")
@utils.kwarg("min_args", 1)
@utils.kwarg("usage", "<nickname>")
@utils.kwarg("channel_only", True)
@utils.kwarg("require_mode", "o")
@utils.kwarg("require_access", "unquiet")
@utils.kwarg("help", "Unquiet a given user")
def unquiet(self, event):
self._quiet(event, False)
def _quiet(self, event, add):
time, args = utils.parse.timed_args(event["args_split"], 1) time, args = utils.parse.timed_args(event["args_split"], 1)
target_name = args[0] target_name = args[0]
@ -209,21 +226,23 @@ class Module(ModuleManager.BaseModule):
if not event["target"].has_user(target_user): if not event["target"].has_user(target_user):
raise utils.EventError("No such user") raise utils.EventError("No such user")
mode, mask = self._mute_method(event["server"], event["target"], mode, prefix = self._quiet_method(event["server"])
target_user)
if mode == None: if mode == None:
raise utils.EventError("This network doesn't support mutes") raise utils.EventError("This network doesn't support quiets")
mask = self._get_hostmask(event["target"], target_user)
mask = "%s%s" % (prefix, mask)
if add and time: if add and time:
self.timers.add_persistent("unmute", time, self.timers.add_persistent("unquiet", time,
server_id=event["server"].id, channel_name=event["target"].name, server_id=event["server"].id, channel_name=event["target"].name,
mode=mode, mask=mask) mode=mode, mask=mask)
mode_modifier = "+" if add else "-" mode_modifier = "+" if add else "-"
event["target"].send_mode("%s%s" % (mode_modifier, mode), [mask]) event["target"].send_mode("%s%s" % (mode_modifier, mode), [mask])
@utils.hook("timer.unmute") @utils.hook("timer.unquiet")
def _timer_unmute(self, event): def _timer_unquiet(self, event):
server = self.bot.get_server_by_id(event["server_id"]) server = self.bot.get_server_by_id(event["server_id"])
if server and event["channel_name"] in server.channels: if server and event["channel_name"] in server.channels:
channel = server.channels.get(event["channel_name"]) channel = server.channels.get(event["channel_name"])