2019-07-11 20:28:05 +00:00
|
|
|
#--depends-on config
|
|
|
|
|
|
|
|
from src import ModuleManager, utils
|
|
|
|
|
2019-07-11 20:34:16 +00:00
|
|
|
DELAY = 5
|
|
|
|
|
2019-07-11 21:18:10 +00:00
|
|
|
rejoin_setting = utils.BoolSetting("kick-rejoin",
|
|
|
|
"Whether or not I should rejoin channels I get kicked from")
|
|
|
|
delay_setting = utils.IntSetting("kick-rejoin-delay",
|
|
|
|
"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)
|
2019-07-11 20:28:05 +00:00
|
|
|
class Module(ModuleManager.BaseModule):
|
2019-07-11 21:18:10 +00:00
|
|
|
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))
|
|
|
|
|
2019-07-11 20:28:05 +00:00
|
|
|
@utils.hook("self.kick")
|
|
|
|
def on_kick(self, event):
|
2019-07-11 21:18:10 +00:00
|
|
|
if self._should_rejoin(event["server"], event["channel"]):
|
|
|
|
delay = self._get_delay(event["server"], event["channel"])
|
2019-07-11 20:34:16 +00:00
|
|
|
self.timers.add("kick-rejoin", delay, server=event["server"],
|
|
|
|
channel_name=event["channel"].name)
|
|
|
|
|
|
|
|
@utils.hook("timer.kick-rejoin")
|
|
|
|
def timer(self, event):
|
|
|
|
event["server"].send_join(event["channel_name"])
|