<commit_before>"use strict";

var identd = require("../../identd");
var Msg = require("../../models/msg");
var Chan = require("../../models/chan");
var Helper = require("../../helper");

module.exports = function(irc, network) {
	var client = this;
	var identHandler = this.manager.identHandler;

	network.channels[0].pushMessage(client, new Msg({
		text: "Network created, connecting to " + network.host + ":" + network.port + "..."
	}), true);

	irc.on("registered", function() {
		if (network.irc.network.cap.enabled.length > 0) {
			network.channels[0].pushMessage(client, new Msg({
				text: "Enabled capabilities: " + network.irc.network.cap.enabled.join(", ")
			}), true);
		}

		var delay = 1000;
		var commands = network.commands;
		if (Array.isArray(commands)) {
			commands.forEach(cmd => {
				setTimeout(function() {
					client.input({
						target: network.channels[0].id,
						text: cmd
					});
				}, delay);
				delay += 1000;
			});
		}

		network.channels.forEach(chan => {
			if (chan.type !== Chan.Type.CHANNEL) {
				return;
			}

			setTimeout(function() {
				network.irc.join(chan.name);
			}, delay);
			delay += 1000;
		});
	});

	irc.on("socket connected", function() {
		network.prefixLookup = {};
		irc.network.options.PREFIX.forEach(function(mode) {
			network.prefixLookup[mode.mode] = mode.symbol;
		});

		network.channels[0].pushMessage(client, new Msg({
			text: "Connected to the network."
		}), true);
	});

	irc.on("close", function() {
		network.channels[0].pushMessage(client, new Msg({
			text: "Disconnected from the network, and will not reconnect. Use /connect to reconnect again."
		}), true);
	});

	if (identd.isEnabled()) {
		irc.on("socket connected", function() {
			identd.hook(irc.connection.socket, client.name || network.username);
		});
	}

	if (identHandler) {
		let identSocketId;

		irc.on("socket connected", function() {
			identSocketId = identHandler.addSocket(irc.connection.socket, client.name || network.username);
		});

		irc.on("socket close", function() {
			identHandler.removeSocket(identSocketId);
		});
	}

	if (Helper.config.debug) {
		irc.on("debug", function(message) {
			log.debug("[" + client.name + " (#" + client.id + ") on " + network.name + " (#" + network.id + ")]", message);
		});
	}

	irc.on("socket error", function(err) {
		network.channels[0].pushMessage(client, new Msg({
			type: Msg.Type.ERROR,
			text: "Socket error: " + err
		}), true);
	});

	irc.on("reconnecting", function(data) {
		network.channels[0].pushMessage(client, new Msg({
			text: "Disconnected from the network. Reconnecting in " + Math.round(data.wait / 1000) + " seconds… (Attempt " + data.attempt + " of " + data.max_retries + ")"
		}), true);
	});

	irc.on("ping timeout", function() {
		network.channels[0].pushMessage(client, new Msg({
			text: "Ping timeout, disconnecting…"
		}), true);
	});

	irc.on("server options", function(data) {
		if (network.serverOptions.PREFIX === data.options.PREFIX) {
			return;
		}

		network.prefixLookup = {};

		data.options.PREFIX.forEach(mode => {
			network.prefixLookup[mode.mode] = mode.symbol;
		});

		network.serverOptions.PREFIX = data.options.PREFIX;

		client.emit("network_changed", {
			network: network.id,
			serverOptions: network.serverOptions
		});
	});
};
<commit_msg>Fix #792: irc-fw update changed socket reference<commit_after>"use strict";

var identd = require("../../identd");
var Msg = require("../../models/msg");
var Chan = require("../../models/chan");
var Helper = require("../../helper");

module.exports = function(irc, network) {
	var client = this;
	var identHandler = this.manager.identHandler;

	network.channels[0].pushMessage(client, new Msg({
		text: "Network created, connecting to " + network.host + ":" + network.port + "..."
	}), true);

	irc.on("registered", function() {
		if (network.irc.network.cap.enabled.length > 0) {
			network.channels[0].pushMessage(client, new Msg({
				text: "Enabled capabilities: " + network.irc.network.cap.enabled.join(", ")
			}), true);
		}

		var delay = 1000;
		var commands = network.commands;
		if (Array.isArray(commands)) {
			commands.forEach(cmd => {
				setTimeout(function() {
					client.input({
						target: network.channels[0].id,
						text: cmd
					});
				}, delay);
				delay += 1000;
			});
		}

		network.channels.forEach(chan => {
			if (chan.type !== Chan.Type.CHANNEL) {
				return;
			}

			setTimeout(function() {
				network.irc.join(chan.name);
			}, delay);
			delay += 1000;
		});
	});

	irc.on("socket connected", function() {
		network.prefixLookup = {};
		irc.network.options.PREFIX.forEach(function(mode) {
			network.prefixLookup[mode.mode] = mode.symbol;
		});

		network.channels[0].pushMessage(client, new Msg({
			text: "Connected to the network."
		}), true);
	});

	irc.on("close", function() {
		network.channels[0].pushMessage(client, new Msg({
			text: "Disconnected from the network, and will not reconnect. Use /connect to reconnect again."
		}), true);
	});

	if (identd.isEnabled()) {
		irc.on("raw socket connected", function(socket) {
			identd.hook(socket, client.name || network.username);
		});
	}

	if (identHandler) {
		let identSocketId;

		irc.on("raw socket connected", function(socket) {
			identSocketId = identHandler.addSocket(socket, client.name || network.username);
		});

		irc.on("socket close", function() {
			identHandler.removeSocket(identSocketId);
		});
	}

	if (Helper.config.debug) {
		irc.on("debug", function(message) {
			log.debug("[" + client.name + " (#" + client.id + ") on " + network.name + " (#" + network.id + ")]", message);
		});
	}

	irc.on("socket error", function(err) {
		network.channels[0].pushMessage(client, new Msg({
			type: Msg.Type.ERROR,
			text: "Socket error: " + err
		}), true);
	});

	irc.on("reconnecting", function(data) {
		network.channels[0].pushMessage(client, new Msg({
			text: "Disconnected from the network. Reconnecting in " + Math.round(data.wait / 1000) + " seconds… (Attempt " + data.attempt + " of " + data.max_retries + ")"
		}), true);
	});

	irc.on("ping timeout", function() {
		network.channels[0].pushMessage(client, new Msg({
			text: "Ping timeout, disconnecting…"
		}), true);
	});

	irc.on("server options", function(data) {
		if (network.serverOptions.PREFIX === data.options.PREFIX) {
			return;
		}

		network.prefixLookup = {};

		data.options.PREFIX.forEach(mode => {
			network.prefixLookup[mode.mode] = mode.symbol;
		});

		network.serverOptions.PREFIX = data.options.PREFIX;

		client.emit("network_changed", {
			network: network.id,
			serverOptions: network.serverOptions
		});
	});
};

{'fraction_non_alphanumeric': 0.1854875283446712, 'fraction_numerical': 0.00801209372637944, 'mean_word_length': 3.5944444444444446, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1541929', 'n_tokens_mistral': 2514, 'n_tokens_neox': 2143, 'n_words': 422}