refactor -b/-q/-m timer logic in to 1 function
This commit is contained in:
parent
87bc9bab9e
commit
c4136a50ec
2 changed files with 26 additions and 27 deletions
|
@ -35,6 +35,21 @@ KICK_REASON_SETTING = utils.Setting("default-kick-reason",
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
_name = "ChanOp"
|
_name = "ChanOp"
|
||||||
|
|
||||||
|
@utils.hook("timer.unmode")
|
||||||
|
def unmode(self, timer):
|
||||||
|
channel = self.bot.database.channels.by_id(timer.kwargs["channel"])
|
||||||
|
|
||||||
|
if channel:
|
||||||
|
server_id, channel_name = channel
|
||||||
|
server = self.bot.get_server_by_id(server_id)
|
||||||
|
if server and channel_name in server.channels:
|
||||||
|
channel = server.channels.get(channel_name)
|
||||||
|
mode = "-%s" % timer.kwargs.get("mode", "b")
|
||||||
|
|
||||||
|
arg = timer.kwargs.get("args", [timer.kwargs.get("arg", None)])
|
||||||
|
server.send_mode(channel.name, mode, arg)
|
||||||
|
|
||||||
|
|
||||||
def _kick_reason(self, server, channel):
|
def _kick_reason(self, server, channel):
|
||||||
return channel.get_setting("default-kick-reason",
|
return channel.get_setting("default-kick-reason",
|
||||||
server.get_setting("default-kick-reason",
|
server.get_setting("default-kick-reason",
|
||||||
|
@ -84,15 +99,8 @@ class Module(ModuleManager.BaseModule):
|
||||||
channel.send_ban(hostmask)
|
channel.send_ban(hostmask)
|
||||||
|
|
||||||
if not time == None:
|
if not time == None:
|
||||||
self.timers.add_persistent("unban", time, server_id=server.id,
|
self.timers.add_persistent("unmode", time, channel=channel.id,
|
||||||
channel_name=channel.name, hostmask=hostmask)
|
arg=hostmask)
|
||||||
|
|
||||||
@utils.hook("timer.unban")
|
|
||||||
def _timer_unban(self, event):
|
|
||||||
server = self.bot.get_server_by_id(event["server_id"])
|
|
||||||
if server and event["channel_name"] in server.channels:
|
|
||||||
channel = server.channels.get(event["channel_name"])
|
|
||||||
channel.send_unban(event["hostmask"])
|
|
||||||
|
|
||||||
@utils.hook("received.command.ban")
|
@utils.hook("received.command.ban")
|
||||||
@utils.hook("received.command.b", alias_of="ban")
|
@utils.hook("received.command.b", alias_of="ban")
|
||||||
|
@ -212,20 +220,12 @@ class Module(ModuleManager.BaseModule):
|
||||||
mask = "%s%s" % (prefix, mask)
|
mask = "%s%s" % (prefix, mask)
|
||||||
|
|
||||||
if add and time:
|
if add and time:
|
||||||
self.timers.add_persistent("unquiet", time,
|
self.timers.add_persistent("unmode", time, channel=spec[0].id,
|
||||||
server_id=server.id, channel_name=spec[0].name,
|
mode=mode, arg=mask)
|
||||||
mode=mode, mask=mask)
|
|
||||||
|
|
||||||
mode_modifier = "+" if add else "-"
|
mode_modifier = "+" if add else "-"
|
||||||
spec[0].send_mode("%s%s" % (mode_modifier, mode), [mask])
|
spec[0].send_mode("%s%s" % (mode_modifier, mode), [mask])
|
||||||
|
|
||||||
@utils.hook("timer.unquiet")
|
|
||||||
def _timer_unquiet(self, event):
|
|
||||||
server = self.bot.get_server_by_id(event["server_id"])
|
|
||||||
if server and event["channel_name"] in server.channels:
|
|
||||||
channel = server.channels.get(event["channel_name"])
|
|
||||||
channel.send_mode("-%s" % event["mode"], [event["mask"]])
|
|
||||||
|
|
||||||
@utils.hook("received.command.invite")
|
@utils.hook("received.command.invite")
|
||||||
@utils.kwarg("require_mode", "o")
|
@utils.kwarg("require_mode", "o")
|
||||||
@utils.kwarg("require_access", "invite")
|
@utils.kwarg("require_access", "invite")
|
||||||
|
@ -349,14 +349,8 @@ class Module(ModuleManager.BaseModule):
|
||||||
event["spec"][0].send_mode("+m")
|
event["spec"][0].send_mode("+m")
|
||||||
|
|
||||||
if event["spec"][1]:
|
if event["spec"][1]:
|
||||||
self.timers.add_persistent("cunmute", event["spec"][1],
|
self.timers.add_persistent("unmode", event["spec"][1],
|
||||||
server_id=event["server"].id,
|
channel=event["spec"][0].id, mode="m")
|
||||||
channel_name=event["spec"][0].name)
|
|
||||||
@utils.hook("timer.cunmute")
|
|
||||||
def cunmute_timer(self, event):
|
|
||||||
server = self.bot.get_server_by_id(event["server_id"])
|
|
||||||
if server and event["channel_name"] in server.channels:
|
|
||||||
self._cunmute(server.channels.get(event["channel_name"]))
|
|
||||||
|
|
||||||
@utils.hook("received.command.cunmute")
|
@utils.hook("received.command.cunmute")
|
||||||
@utils.kwarg("require_mode", "o")
|
@utils.kwarg("require_mode", "o")
|
||||||
|
|
|
@ -68,6 +68,11 @@ class Channels(Table):
|
||||||
channels WHERE server_id=? AND name=?""",
|
channels WHERE server_id=? AND name=?""",
|
||||||
[server_id, name.lower()])
|
[server_id, name.lower()])
|
||||||
return value if value == None else value[0]
|
return value if value == None else value[0]
|
||||||
|
def by_id(self, channel_id: int):
|
||||||
|
value = self.database.execute_fetchone(
|
||||||
|
"SELECT server_id, name FROM channels WHERE channel_id=?",
|
||||||
|
[channel_id])
|
||||||
|
return value
|
||||||
def rename(self, channel_id: int, new_name: str):
|
def rename(self, channel_id: int, new_name: str):
|
||||||
self.database.execute("UPDATE channels SET name=? where channel_id=?",
|
self.database.execute("UPDATE channels SET name=? where channel_id=?",
|
||||||
[new_name.lower(), channel_id])
|
[new_name.lower(), channel_id])
|
||||||
|
|
Loading…
Reference in a new issue