support enabling kick-rejoin per channel

This commit is contained in:
jesopo 2019-07-11 22:18:10 +01:00
parent baa13d9e7f
commit c083d4845a

View file

@ -4,15 +4,27 @@ from src import ModuleManager, utils
DELAY = 5 DELAY = 5
@utils.export("serverset", utils.BoolSetting("kick-rejoin", rejoin_setting = utils.BoolSetting("kick-rejoin",
"Whether or not I should rejoin channels I get kicked from")) "Whether or not I should rejoin channels I get kicked from")
@utils.export("serverset", utils.IntSetting("kick-rejoin-delay", delay_setting = utils.IntSetting("kick-rejoin-delay",
"Amount of seconds to wait before rejoining a channel")) "Amount of seconds to wait before rejoining a channel")
@utils.export("serverset", rejoin_setting)
@utils.export("serverset", delay_setting)
@utils.export("channelset", rejoin_setting)
@utils.export("channelset", delay_setting)
class Module(ModuleManager.BaseModule): class Module(ModuleManager.BaseModule):
def _should_rejoin(self, server, channel):
return channel.get_setting("kick-rejoin",
server.get_setting("kick-rejoin", False))
def _get_delay(self, server, channel):
return channel.get_setting("kick-rejoin-delay",
server.get_setting("kick-rejoin-delay", DELAY))
@utils.hook("self.kick") @utils.hook("self.kick")
def on_kick(self, event): def on_kick(self, event):
if event["server"].get_setting("kick-rejoin", False): if self._should_rejoin(event["server"], event["channel"]):
delay = event["server"].get_setting("kick-rejoin-delay", DELAY) delay = self._get_delay(event["server"], event["channel"])
self.timers.add("kick-rejoin", delay, server=event["server"], self.timers.add("kick-rejoin", delay, server=event["server"],
channel_name=event["channel"].name) channel_name=event["channel"].name)