2016-03-29 11:56:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Module(object):
|
2017-07-12 09:00:27 +00:00
|
|
|
def __init__(self, bot):
|
|
|
|
bot.events.on("self").on("part").hook(self.on_self_part)
|
|
|
|
bot.events.on("self").on("join").hook(self.on_join)
|
|
|
|
bot.events.on("received").on("numeric").on("366").hook(
|
|
|
|
self.on_identify_trigger)
|
|
|
|
bot.events.on("received").on("numeric").on("001").hook(
|
|
|
|
self.on_identify_trigger)
|
2016-03-29 11:56:58 +00:00
|
|
|
|
2017-07-12 09:00:27 +00:00
|
|
|
def on_self_part(self, event):
|
|
|
|
pass
|
2016-03-29 11:56:58 +00:00
|
|
|
|
2017-07-12 09:00:27 +00:00
|
|
|
def on_join(self, event):
|
|
|
|
channels = set(event["server"].get_setting("autojoin", []))
|
|
|
|
channels.add(event["channel"].name)
|
|
|
|
event["server"].set_setting("autojoin", list(channels))
|
|
|
|
|
|
|
|
def on_identify_trigger(self, event):
|
|
|
|
if event["number"]=="001" and not event["server"].sasl_success: return
|
|
|
|
if event["line_split"][3].lower() == "#bitbot" or event["number"]=="001":
|
|
|
|
channels = event["server"].get_setting("autojoin", [])
|
|
|
|
chan_keys = event["server"].get_setting("channel_keys", {})
|
2017-10-27 12:15:33 +00:00
|
|
|
channels_sorted = sorted(channels,
|
|
|
|
key=lambda x: 0 if x in chan_keys else 1)
|
|
|
|
|
|
|
|
keys_sorted = map(lambda x: x[1],
|
|
|
|
sorted(chan_keys.items(),
|
|
|
|
key=lambda x: channels_sorted.index(x[0])))
|
|
|
|
event["server"].send_join(
|
|
|
|
",".join(channels_sorted), ",".join(keys_sorted))
|
|
|
|
|
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)
|