2018-10-03 12:22:37 +00:00
|
|
|
from src import ModuleManager, utils
|
2016-03-29 11:56:58 +00:00
|
|
|
|
2019-07-22 11:42:43 +00:00
|
|
|
BATCH_MAX = 10
|
|
|
|
|
2018-09-26 17:27:17 +00:00
|
|
|
class Module(ModuleManager.BaseModule):
|
2019-02-16 15:53:14 +00:00
|
|
|
@utils.hook("received.001")
|
2018-07-15 22:56:06 +00:00
|
|
|
def on_connect(self, event):
|
2019-02-10 14:55:46 +00:00
|
|
|
channels = event["server"].get_setting("autojoin", [])
|
2019-07-02 20:38:31 +00:00
|
|
|
if channels:
|
2019-07-22 11:42:43 +00:00
|
|
|
channel_batches = [channels[i:i+BATCH_MAX] for i in range(
|
|
|
|
0, len(channels), BATCH_MAX)]
|
|
|
|
for channel_batch in channel_batches:
|
|
|
|
event["server"].send_joins(channel_batch)
|
2016-03-29 11:56:58 +00:00
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("self.join")
|
2017-07-12 09:00:27 +00:00
|
|
|
def on_join(self, event):
|
2018-08-05 11:57:19 +00:00
|
|
|
channels = event["server"].get_setting("autojoin", [])
|
2019-01-24 17:12:50 +00:00
|
|
|
channel_name = event["server"].irc_lower(event["channel"].name)
|
2018-12-05 15:46:51 +00:00
|
|
|
if not channel_name in channels:
|
|
|
|
channels.append(channel_name)
|
2018-08-05 11:57:19 +00:00
|
|
|
event["server"].set_setting("autojoin", channels)
|
2017-07-12 09:00:27 +00:00
|
|
|
|
2018-09-03 11:22:06 +00:00
|
|
|
def _remove_channel(self, server, channel_name):
|
|
|
|
channels = server.get_setting("autojoin", [])
|
|
|
|
if channel_name in channels:
|
2018-09-05 12:55:53 +00:00
|
|
|
channels.remove(channel_name)
|
2018-09-10 07:58:15 +00:00
|
|
|
server.set_setting("autojoin", channels)
|
2020-07-03 12:14:00 +00:00
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
2018-09-03 11:22:06 +00:00
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("self.part")
|
2018-09-19 00:41:53 +00:00
|
|
|
def on_part(self, event):
|
2018-09-03 11:22:06 +00:00
|
|
|
self._remove_channel(event["server"], event["channel"].name)
|
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("self.kick")
|
2018-09-03 11:22:06 +00:00
|
|
|
def on_kick(self, event):
|
|
|
|
self._remove_channel(event["server"], event["channel"].name)
|
2020-07-03 12:14:00 +00:00
|
|
|
|
|
|
|
@utils.hook("raw.received.470")
|
|
|
|
def on_linkchannel(self, event):
|
|
|
|
initial = event["line"].args[1]
|
|
|
|
initial_lower = event["server"].irc_lower(initial)
|
|
|
|
linked = event["line"].args[2]
|
|
|
|
|
|
|
|
if self._remove_channel(event["server"], initial_lower):
|
|
|
|
self.log.warn(f"{str(event['server'])} "
|
|
|
|
f"channel {initial} linked to {linked} "
|
|
|
|
"- removed from autojoin")
|