bitbot-3.11-fork/modules/channel_blacklist.py

41 lines
1.6 KiB
Python
Raw Normal View History

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:]
changed = False
channels_out = []
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)
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
if changed:
if not channels_out:
2019-09-05 13:14:21 +00:00
event["line"].invalidate()
else:
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
@utils.hook("received.join")
def on_join(self, event):
if event["channel"].get_setting("blacklist", False):
event["channel"].send_part()