aboutsummaryrefslogtreecommitdiff
path: root/modules/channel_blacklist.py
blob: aa3213f3591e90e4b1ef41daa039e9d9ea60d16f (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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:]

            remove = []
            for channel_name in channels:
                id = event["server"].channels.get_id(channel_name, create=False)
                if not id == None:
                    if self.bot.database.channel_settings.get(id, "blacklist",
                            False):
                        remove.append(channel_name)
                        if keys:
                            keys.pop(0)
            for channel_name in remove:
                channels.remove(channel_name)

            if remove:
                if not channels:
                    event["line"].invalidate()
                else:
                    event["line"].args[0] = ",".join(channels)
                    event["line"].args[1:] = keys