aboutsummaryrefslogtreecommitdiff
path: root/src/core_modules/banmask.py
blob: bc33d4a9498bd2b2c3d9ebc9894e8f0aa42937e3 (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
from src import ModuleManager, utils

SETTING = utils.Setting("ban-format",
    "Set ban format "
    "(${n} = nick, ${u} = username, ${h} = hostname, ${a} = account",
    example="*!${u}@${h}")

@utils.export("channelset", SETTING)
@utils.export("serverset", SETTING)
class Module(ModuleManager.BaseModule):
    def _format_hostmask(self, user, s):
        vars = {}
        vars["n"] = vars["nickname"] = user.nickname
        vars["u"] = vars["username"] = user.username
        vars["h"] = vars["hostname"] = user.hostname
        vars["a"] = vars["account"] = user.account or ""
        missing, out = utils.parse.format_token_replace(s, vars)
        return out
    @utils.export("ban-mask")
    def banmask(self, server, channel, user):
        format = channel.get_setting("ban-format",
            server.get_setting("ban-format", "*!${u}@${h}"))
        return self._format_hostmask(user, format)