コード例 #1
0
def antispam_del_cb(word, word_eol, userdata):
    """Removes one filter from the current antispam filters.
    This function doesnt check for duplicates, it removes every instance of the
    selected filter.
    Arguments:
    word     -- array of strings sent by HexChat/X-Chat to every hook (ignored)
    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.CONNECTED == 1:
        sql = "".join(["DELETE FROM filters WHERE filter='", word_eol[1], "'"])
        helper.gatodb_cursor_execute(sql)
        helper.gatodb_commit()
        message = "".join([word_eol[1], " has been deleted from AntiSpam",
                           " filters"])
        helper.query_line(message)
        antispam_reload()
    else:
        helper.gprint("Enable the AntiSpam system before deleting filters")
    return xchat.EAT_ALL
コード例 #2
0
def antispam_add_cb(word, word_eol, userdata):
    """Adds a new filter to the end of the current antispam filters list.
    This function doesn't check for duplicates, just adds at the end.
    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.CONNECTED == 1:
        sql = "".join(['INSERT INTO filters ("id", "filter")',
                       ' VALUES (null, "', word[1], '")'])
        helper.gatodb_cursor_execute(sql)
        helper.gatodb_commit()
        message = "".join([word[1], " filter has been added to AntiSpam",
                           " filters"])
        helper.query_line(message)
        del message
        antispam_reload()
    else:
        helper.gprint("Enable the AntiSpam system before adding filters")
    return xchat.EAT_ALL
コード例 #3
0
def antispam_list_cb(word, word_eol, userdata):
    """Shows the list of currently active AntiSapm filters.
    Arguments:
    word     -- array of strings sent by HexChat/X-Chat to every hook (ignored)
    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)
    """
    sql = "SELECT id, filter FROM filters"
    for item in helper.gatodb_cursor_execute(sql):
        message = "".join([str(item[0]), ": ", item[1]])
        helper.query_line(message)
    del message
    return xchat.EAT_ALL
コード例 #4
0
def antispam_reload():
    """Reload the antispam filters list to apply changes"""
    # Use the global variables so this change applies to the wole module
    global ANTISPAM
    global SPAMBOTS
    global CHANNELS
    if helper.CONNECTED == 1:
        ANTISPAM = int(helper.conf_read("spam", "protections"))
        SPAMBOTS = int(helper.conf_read("spambots", "protections"))
        CHANNELS = helper.conf_read("channels", "protections")
        # Load the new filter list and compile the regexps
        filters = helper.gatodb_cursor_execute("SELECT filter FROM filters")
        COMP_FILTERS = []
        for item in filters:
            COMP_FILTERS.append(re.compile("".join([".*", item[0], ".*"]),
                                           re.IGNORECASE))
    else:
        helper.gprint("Failed to reload filters, AntiSpam disabled")
        ANTISPAM = 0
        SPAMBOTS = 0
        CHANNELS = []
コード例 #5
0
import helper

#############################################################################
# Define some environment variables
#############################################################################


#############################################################################
# Initialize the module
#############################################################################
# Load the filter list and compile the regular expressions
if helper.CONNECTED == 1:
    ANTISPAM = int(helper.conf_read("spam", "protections"))
    SPAMBOTS = int(helper.conf_read("spambots", "protections"))
    CHANNELS = helper.conf_read("channels", "protections").split(",")
    filters = helper.gatodb_cursor_execute("SELECT filter FROM filters")
    COMP_FILTERS = []
    for item in filters:
        COMP_FILTERS.append(re.compile("".join([".*", item[0], ".*"]),
                                       re.IGNORECASE))
else:
    helper.gprint("AntiSpam is disabled or couldn't read the filters list")
    ANTISPAM = 0
    SPAMBOTS = 0
    CHANNELS = []


#############################################################################
# Define internal use functions
#############################################################################
def antispam_reload():