2018-08-31 09:51:47 +00:00
|
|
|
|
|
|
|
|
2016-03-29 11:56:58 +00:00
|
|
|
class Module(object):
|
2018-08-31 11:55:52 +00:00
|
|
|
def __init__(self, bot, events):
|
|
|
|
events.on("received.numeric.001").hook(self.on_connect)
|
|
|
|
events.on("self.join").hook(self.on_join)
|
|
|
|
events.on("self.kick").hook(self.on_kick)
|
2016-03-29 11:56:58 +00:00
|
|
|
|
2018-07-15 22:56:06 +00:00
|
|
|
def on_connect(self, event):
|
2018-08-31 09:51:47 +00:00
|
|
|
channels = event["server"].get_setting("autojoin", [])
|
2018-07-15 22:56:06 +00:00
|
|
|
chan_keys = event["server"].get_setting("channel_keys", {})
|
|
|
|
channels_sorted = sorted(channels,
|
2018-08-31 09:51:47 +00:00
|
|
|
key=lambda x: 0 if x in chan_keys else 1)
|
2018-07-15 22:56:06 +00:00
|
|
|
|
|
|
|
keys_sorted = list(map(lambda x: x[1],
|
2018-08-31 09:51:47 +00:00
|
|
|
sorted(chan_keys.items(),
|
|
|
|
key=lambda x: channels_sorted.index(x[0]))))
|
2018-07-15 22:56:06 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
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", [])
|
|
|
|
if not event["channel"].name in channels:
|
2018-08-18 23:20:24 +00:00
|
|
|
channels.append(event["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-07-02 10:09:22 +00:00
|
|
|
def on_kick(self, event):
|
|
|
|
channels = event["server"].get_setting("autojoin", [])
|
|
|
|
if event["channel"].name in channels:
|
|
|
|
channels.remove(event["channel"].name)
|
|
|
|
event["server"].set_setting("autojoin", channels)
|