2018-10-03 12:22:37 +00:00
|
|
|
from src import ModuleManager, utils
|
2016-03-29 11:56:58 +00:00
|
|
|
|
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", [])
|
|
|
|
if not channels:
|
|
|
|
return
|
|
|
|
|
2018-07-15 22:56:06 +00:00
|
|
|
chan_keys = event["server"].get_setting("channel_keys", {})
|
|
|
|
channels_sorted = sorted(channels,
|
|
|
|
key=lambda x: 0 if x in chan_keys else 1)
|
|
|
|
|
|
|
|
keys_sorted = list(map(lambda x: x[1],
|
|
|
|
sorted(chan_keys.items(),
|
|
|
|
key=lambda x: channels_sorted.index(x[0]))))
|
|
|
|
|
|
|
|
for i in range(len(channels_sorted)):
|
|
|
|
channel = channels_sorted[i]
|
|
|
|
key = None if len(keys_sorted) <= i else keys_sorted[i]
|
|
|
|
event["server"].attempted_join[channel] = key
|
|
|
|
|
|
|
|
event["server"].send_join(
|
|
|
|
",".join(channels_sorted), ",".join(keys_sorted))
|
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)
|
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)
|