2019-09-05 13:14:21 +00:00
|
|
|
from src import EventManager, ModuleManager, utils
|
|
|
|
|
|
|
|
@utils.export("channelset", utils.BoolSetting("blacklist",
|
|
|
|
"Refuse to join a given channel"))
|
|
|
|
class Module(ModuleManager.BaseModule):
|
|
|
|
@utils.hook("preprocess.send.join")
|
|
|
|
@utils.kwarg("priority", EventManager.PRIORITY_HIGH)
|
|
|
|
def preprocess_send_join(self, event):
|
|
|
|
if event["line"].args:
|
|
|
|
channels = event["line"].args[0].split(",")
|
|
|
|
keys = event["line"].args[1:]
|
|
|
|
|
2019-09-05 13:32:30 +00:00
|
|
|
changed = False
|
|
|
|
channels_out = []
|
2019-09-07 11:58:20 +00:00
|
|
|
for channel_name in filter(None, channels):
|
2019-09-05 13:14:21 +00:00
|
|
|
id = event["server"].channels.get_id(channel_name, create=False)
|
2019-09-05 13:32:30 +00:00
|
|
|
if not id == None and self.bot.database.channel_settings.get(
|
|
|
|
id, "blacklist", False):
|
|
|
|
changed = True
|
|
|
|
if keys:
|
|
|
|
keys.pop(0)
|
|
|
|
else:
|
|
|
|
key = None
|
|
|
|
if keys:
|
|
|
|
key = keys.pop(0)
|
|
|
|
channels_out.append([channel_name, key])
|
2019-09-05 13:14:21 +00:00
|
|
|
|
2019-09-05 13:32:30 +00:00
|
|
|
if changed:
|
|
|
|
if not channels_out:
|
2019-09-05 13:14:21 +00:00
|
|
|
event["line"].invalidate()
|
|
|
|
else:
|
2019-09-05 13:32:30 +00:00
|
|
|
channels = [c[0] for c in channels_out]
|
|
|
|
keys = [c[1] for c in channels_out if c[1]]
|
2019-09-05 13:14:21 +00:00
|
|
|
event["line"].args[0] = ",".join(channels)
|
|
|
|
event["line"].args[1:] = keys
|
2019-09-05 14:16:18 +00:00
|
|
|
|
|
|
|
@utils.hook("received.join")
|
|
|
|
def on_join(self, event):
|
|
|
|
if event["channel"].get_setting("blacklist", False):
|
|
|
|
event["channel"].send_part()
|