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-09-15 21:22:41 +00:00
|
|
|
if delay == 0:
|
|
|
|
self._rejoin(event["server"], event["channel"].name)
|
|
|
|
else:
|
2019-10-08 12:49:43 +00:00
|
|
|
self.timers.add("kick-rejoin",
|
|
|
|
self._timer(event["server"], event["channel"].name),
|
|
|
|
delay)
|
2019-07-11 20:34:16 +00:00
|
|
|
|
2019-10-08 12:49:43 +00:00
|
|
|
def _timer(self, server, channel_name):
|
|
|
|
return lambda timer: self._rejoin(server, channel_name)
|
2019-09-15 21:22:41 +00:00
|
|
|
|
|
|
|
def _rejoin(self, server, channel_name):
|
|
|
|
server.send_join(channel_name)
|