def amule_cb(word, word_eol, userdata): """Read aMule's onlinesig file and shows up/down speeds and total downloaded in the active channel. 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) """ if path.exists(_AMULESIG): lines = open(_AMULESIG, "r").readlines() if lines[0] == "0": helper.gprint("aMule isn't connected") else: down_speed = (lines[6])[0:-1] up_speed = (lines[7])[0:-1] total_down = helper.units(int(lines[11]), 1024) version = lines[13][0:-1] xchat.command("".join(["say ( aMule ", version, " )", " Download: ", down_speed, "KB/s -", " Upload: ", up_speed, "KB/s -" " Downloaded: ", total_down])) else: helper.gprint([_AMULESIG, " file does not exist, check whether you", " have 'Online signature' enabled in your aMule", " settings"]) return xchat.EAT_ALL
def _save(self, submission): """ Saves the final submission to csv using the helper module""" if self.verbose: helper.gprint("Saving data to csv") helper.save_submission_csv(submission, "ensemble")
def transmission_cb(word, word_eol, userdata): """Reads transmission's stats file and show total Upload and Download in the active channel 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) """ if path.exists(_TRANSMISSIONSTATS): lines = open(_TRANSMISSIONSTATS, "r").readlines() downloaded = helper.units(int(lines[1].split(":")[1][1:-3]), 1024) uploaded = helper.units(int(lines[5].split(":")[1][1:-1]), 1024) xchat.command("".join(["say ( Transmission ) Downloaded: ", downloaded, " - Uploaded: ", uploaded])) else: helper.gprint("".join(["There is no stats file. Please, check your", " Transmission setting"])) return xchat.EAT_ALL
def anti_ctcp_cb(word, word_eol, userdata): """Detect CTCPs sent to protected channels and kick/ban 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("ctcps", "protections") == "1": channels = helper.conf_read("channels", "protections").split(',') for channel in channels: if channel.lower() == word[2].lower(): if _CTCP_RE.search(word[3]): message = "".join(["Received a CTCP to channel ", word[2]]) helper.gprint(message) host = word[0][1:].split("@")[-1] xchat.command("".join(["ban *!*@", host])) nick = word[0][1:].split("!")[0] xchat.command("".join(["kick ", nick, "CTCPs to channel"])) return xchat.EAT_NONE
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
def run(self): """ Main algorithmic loop""" np.random.seed(420) folds = self._get_folds() classifiers, classifier_count = self._build_classifiers(0, self.estimators) # Init train test split blend sets blend_train = np.zeros((self.x.shape[0], classifier_count)) blend_test = np.zeros((self.submission_data.shape[0], classifier_count)) # Loop through the classifiers for c_index, classifier in enumerate(classifiers): if self.verbose: helper.bprint(f"Classifier: {c_index} - {classifier}") fold_sum = np.zeros((self.submission_data.shape[0], len(folds))) # Loop trough all the k-folds for f_index, (train, test) in enumerate(folds): helper.cprint(f"Training fold {f_index}") x_train, x_test, y_train, y_test = self._get_sets(train, test) classifier.fit(x_train, y_train) # Predict on test split set test_pred = np.array(classifier.predict_proba(x_test)) blend_train[test, c_index] = test_pred[:, 1] # Predit on submission data sub_pred = np.array(classifier.predict_proba(self.submission_data)) fold_sum[:, f_index] = sub_pred[:, 1] blend_test[:, c_index] = fold_sum.mean(1) helper.gprint(f"Done training {classifier}") # Blend the classifiers final_sub = self._blend(blend_train, blend_test) # Save to csv after stretching self._save(self._stretch(final_sub))
def param_tuning(params): tic = time.perf_counter() # Load data using helper X, y, submission_data = helper.load_data(False) # Create model and set estimator grid # Use GPU for faster results model = xgb.XGBRegressor(tree_method="gpu_hist", gpu_id=0,objective='binary:logistic',booster='gbtree',eval_metric='mlogloss', n_estimators=1000) # Execute the grid search helper.bprint('Starting grid search') kfold = StratifiedKFold(n_splits=10, shuffle=True) grid_search = GridSearchCV(model, params, scoring="neg_mean_squared_error", n_jobs=-1, cv=kfold) grid_result = grid_search.fit(X, y) # Print best result helper.gprint("Best: %f using %s" % (grid_result.best_score_, grid_result.best_params_)) toc = time.perf_counter() helper.bprint(f"Hyper parameter tuned in {toc - tic:0.4f} seconds")
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 = []
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
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
def vuze_cb(word, word_eol, userdata): """Read Vuze's statistics file and shows Upload and Download speed in the active channel. 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) """ if path.exists(_VUZESTATS): dom1 = xml.dom.minidom.parse(_VUZESTATS) stats = dom1.getElementsByTagName('STATS')[0] glob = stats.getElementsByTagName('GLOBAL')[0] down = glob.getElementsByTagName('DOWNLOAD_SPEED')[0] down_speed = down.getElementsByTagName('TEXT')[0].firstChild.data up = glob.getElementsByTagName('UPLOAD_SPEED')[0] up_speed = up.getElementsByTagName('TEXT')[0].firstChild.data xchat.command("".join(["say ( Vuze ) Download: ", down_speed, " - ", "Upload: ", up_speed])) del down, down_speed, up, up_speed, glob, stats, dom1 else: helper.gprint("".join([_VUZESTATS, " file does not exist, check your", " Vuze settings"])) return xchat.EAT_ALL
def graphics_cb(word, word_eol, userdata): """Shows graphics devices information on the current channel. 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) """ # Find a list of devices data = Popen("lspci | grep VGA", shell=True, stdout=PIPE, stderr=PIPE) error = data.stderr.readlines() if len(error) > 0: for line in error: helper.gprint(line) devices = ["Unknown device"] else: devices = [] for line in data.stdout: devices.append(line.split(": ")[1][:-1]) # Show a line for each device found for device in devices: xchat.command("".join(["say ", "[ Graphics ] Device: ", device])) # Find the screen resolution for all active screen data = Popen("xdpyinfo | grep dimensions", shell=True, stdout=PIPE, stderr=PIPE) error = data.stderr.readlines() if len(error) > 0: for line in error: helper.gprint(line) resolutions = ["Unknown resolution"] else: resolutions = [] for line in data.stdout: resolutions.append(line.split(": ")[1][:-1]) # Show a line for each active screen for resolution in resolutions: xchat.command("".join(["say ", "[ Graphics ] Screen: ", resolution])) return xchat.EAT_ALL
def software_cb(word, word_eol, userdata): """Shows information about the current kernel, LIBC, X11 and GCC on the current channel. 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) """ # Find kernel and libc data = platform.uname() kernel = " ".join([data[0], data[2]]) libc = " ".join(platform.libc_ver()[0:2]) # Find X11 server and version xdpyinfo = Popen("xdpyinfo | grep version:", shell=True, stdout=PIPE, stderr=PIPE) error = xdpyinfo.stderr.readlines() if len(error) > 0: for i in range(len(error)): helper.gprint(error[i]) x11 = "Unknown" else: xserver = xdpyinfo.stdout.readlines()[0].split()[-1] xdpyinfo = Popen('xdpyinfo | grep "vendor string"', shell=True, stdout=PIPE, stderr=PIPE) error = xdpyinfo.stderr.readlines() if len(error) > 0: for i in range(len(error)): helper.gprint(error[i]) xversion = "Unknown" else: x_version = xdpyinfo.stdout.readlines() xversion = x_version[0].split()[3] x11 = "".join([xversion, " ", xserver]) # Find GCC version gcc = Popen("gcc --version", shell=True, stdout=PIPE, stderr=PIPE) error = gcc.stderr.readlines() if len(error) > 0: for i in range(len(error)): helper.gprint(error[i]) gcc = "Unknown" else: gcc_output = gcc.stdout.readlines() if gcc_output[0] == "bash: gcc: command not found": gcc = "Not installed" else: data = gcc_output[0].split() gcc = data[-1] command = "".join(["say [ Software ] Kernel: ", kernel, " - LIBC: ", libc, " - X11: ", x11, " - GCC: ", gcc]) xchat.command(command) del data, kernel, libc, xdpyinfo, gcc, gcc_output, error, x_version del xversion, x11, xserver return xchat.EAT_ALL
############################################################################# # 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(): """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: