Ejemplo n.º 1
0
def anti_caps_cb(word, word_eol, userdata):
    """Detects caps abuse in protected channels, warns the user the first time
    and expels repeat offenders
    Arguments:
    word     -- array of strings sent by HexChat/X-Chat to every hook
    word_eol -- array of strings sent by HexChat/X-Chat to every hook
    userdata -- optional variable that can be sent to a hook (ignored)
    """
    if helper.conf_read("caps", "protections") == "1":
        for channel in helper.conf_read("channels", "protections").split(','):
            if channel.lower() == word[2].lower():
                string = word_eol[3][1:]
                if _ACTION_RE.match(string):
                    string = string[7:]
                if string.isupper() and len(string) > 10:
                    host = word[0][1:].split("@")[1]
                    nick = word[0][1:].split("!")[0]
                    if host in _HOSTS_ABUSING_CAPS:
                        _HOSTS_ABUSING_CAPS.remove(host)
                        message = "".join([" Writing in all caps is against",
                                           " the rules and you were warned."])
                        helper.expel(message, "1", word)
                    else:
                        _HOSTS_ABUSING_CAPS.append(host)
                        message = "".join(["msg ", word[2], " ", nick, ":",
                                           " do not write in all caps, it is",
                                           " against the rules. Next time you",
                                           " will be expelled."])
                    xchat.command(message)
    return xchat.EAT_NONE
Ejemplo n.º 2
0
def anti_away_cb(word, word_eol, userdata):
    """Detects away messages in protected channels and expels the author
    Arguments:
    word     -- array of strings sent by HexChat/X-Chat to every hook
    word_eol -- array of strings sent by HexChat/X-Chat to every hook (ignored)
    userdata -- optional variable that can be sent to a hook (ignored)
    """
    if helper.conf_read("away", "protections") == "1":
        if word[2].lower() in helper.conf_read("channels",
                                               "protections").split(','):
            awaystr = helper.conf_read("awaystr", "protections").split(",")
            for i in range(len(awaystr)):
                if word_eol[3].find(awaystr[i]) > 0:
                    ban = "1"
                    message = "".join([" Disable automatic away messages,",
                                       " if you are out, just shut up"])
                    helper.expel(message, ban, word)
    return xchat.EAT_NONE
Ejemplo n.º 3
0
def antispam_cb(word, word_eol, userdata):
    """Compare received messages with a list of filters and remove those who
    match. Also, optionally, expel the spamer.
    Arguments:
    word     -- array of strings sent by HexChat/X-Chat to every hook
    word_eol -- array of strings sent by HexChat/X-Chat to every hook (ignored)
    userdata -- optional variable that can be sent to a hook (ignored)
    """
    global SPAMBOTS
    global ANTISPAM
    global CHANNELS
    # Check whether the message was receiven on a protected channel and the
    # antispam is enabled. If so, expel the spammer
    if word[2].lower() in CHANNELS and ANTISPAM == 1:
        for spam_exp in COMP_FILTERS:
            if spam_exp.search(word_eol[3][1:]):
                ban = "1"
                message = " Spam/Troll"
                helper.expel(message, ban, word)
                # Once the spammer is expelled, return to X-Chat/Hexchat so
                # the check for private messages isn't executed when it's a
                # public channel message.
                return xchat.EAT_NONE
    # Check whether the message was received in a private conversation and
    # spambots protection is enabled.
    elif word[2] == xchat.get_info("nick") and SPAMBOTS == 1:
        # If so, check whether it contains spam
        for spam_exp in COMP_FILTERS:
            if spam_exp.search(word_eol[3][1:]):
                # If there is spam, expel the author
                ban = "1"
                message = " Spambot"
                helper.expel(message, ban, word)
                # And return to X-Chat/Hexchat eating the entire message
                return xchat.EAT_ALL
    # If this point is reached, this protections are disabled OR there is no
    # spam OR the message is from an unprotected channel, so return to
    # X-chat/Hexchat without doing anything
    else:
        return xchat.EAT_NONE
Ejemplo n.º 4
0
def anti_colors_cb(word, word_eol, userdata):
    """Detects messages containing colors/bold/underline on protected channels,
    warns the author the first time and expels repeat ofenders.
    Arguments:
    word     -- array of strings sent by HexChat/X-Chat to every hook
    word_eol -- array of strings sent by HexChat/X-Chat to every hook
    userdata -- optional variable that can be sent to a hook (ignored)
    """
    # Only act on protected channels
    if word[2].lower() in helper.conf_read("channels",
                                           "protections").split(","):
        string = word_eol[3][1:]
        if _ACTION_RE.match(string):
            string = string[7:]
        if _COLORS_RE.search(string):
            # If we are banning colors, expel the author
            if helper.conf_read("ban_colors", "protections") == "1":
                host = word[0][1:].split("@")[1]
                if host in _HOSTS_ABUSING_COLORS:
                    _HOSTS_ABUSING_COLORS.remove(host)
                    message = "".join([" Using colors is against the",
                                       " rules and you were warned."])
                    helper.expel(message, "1", word)
                else:
                    _HOSTS_ABUSING_COLORS.append(host)
                    message = "".join(["msg ", word[2], " ",
                                       word[0][1:].split("!")[0], ": do NOT",
                                       " use colors/bold/underline in",
                                       " this channel, it is against the",
                                       " rules. Next time you will be",
                                       " expelled."])
                    xchat.command(message)
            # If we are ignoring messages containing colors
            if helper.conf_read("ignore_colors", "protections") == "1":
                helper.gprint("".join(["Message from ",
                                       word[0][1:].split("!")[0],
                                       " ignored because it contains",
                                       " colors."]))
                return xchat.EAT_ALL
    return xchat.EAT_NONE