<commit_before>var fs = require('fs');
var path = require('path');
var request = require('request');

const AVATAR_PATH = path.join(__dirname, '../config/avatars/');

function download_image(image_url, name, extension) {
	request
		.get(image_url)
		.on('error', function (err) {
			console.error(err);
		})
		.pipe(fs.createWriteStream(AVATAR_PATH + name + extension));
}

function load_custom_avatars() {
	fs.readdir(AVATAR_PATH, function (err, files) {
		files
			.filter(function (file) {
				return ['.jpg', '.png', '.gif'].indexOf(path.extname(file)) >= 0;
			})
			.forEach(function (file) {
				var name = path.basename(file, path.extname(file));
				Config.customavatars[name] = file;
			});
	});
}

load_custom_avatars();

exports.commands = {
	customavatar: {
		set: function (target, room, user) {
			if (!this.can('customavatar')) return false;

			var parts = target.split(',');

			if (parts.length < 2) return this.parse('/help customavatar');

			var name = toId(parts[0]);
			var image_url = parts[1];
			var ext = path.extname(image_url);

			if (!name || !image_url) return this.parse('/help customavatar');
			if (['.jpg', '.png', '.gif'].indexOf(ext) < 0) {
				return this.errorReply("Image url must have .jpg, .png, or .gif extension.");
			}

			Config.customavatars[name] = name + ext;

			download_image(image_url, name, ext);
			this.sendReply(parts[0] + "'s avatar has been set.");
		},

		delete: function (target, room, user) {
			if (!this.can('customavatar')) return false;

			var userid = toId(target);
			var image = Config.customavatars[userid];

			if (!image) {
				return this.errorReply("This user does not have a custom avatar");
			}

			delete Config.customavatars[userid];
<commit_msg>Forcefully prefix http:// to links without it<commit_after>var fs = require('fs');
var path = require('path');
var request = require('request');

const AVATAR_PATH = path.join(__dirname, '../config/avatars/');

function download_image(image_url, name, extension) {
	request
		.get(image_url)
		.on('error', function (err) {
			console.error(err);
		})
		.pipe(fs.createWriteStream(AVATAR_PATH + name + extension));
}

function load_custom_avatars() {
	fs.readdir(AVATAR_PATH, function (err, files) {
		files
			.filter(function (file) {
				return ['.jpg', '.png', '.gif'].indexOf(path.extname(file)) >= 0;
			})
			.forEach(function (file) {
				var name = path.basename(file, path.extname(file));
				Config.customavatars[name] = file;
			});
	});
}

load_custom_avatars();

exports.commands = {
	customavatar: {
		set: function (target, room, user) {
			if (!this.can('customavatar')) return false;

			var parts = target.split(',');

			if (parts.length < 2) return this.parse('/help customavatar');

			var name = toId(parts[0]);
			var image_url = parts[1];
			if (image_url.indexOf('http://') !== 0 && image_url.indexOf('https://') !== 0) image_url = 'http://' + image_url;
			var ext = path.extname(image_url);

			if (!name || !image_url) return this.parse('/help customavatar');
			if (['.jpg', '.png', '.gif'].indexOf(ext) < 0) {
				return this.errorReply("Image url must have .jpg, .png, or .gif extension.");
			}

			Config.customavatars[name] = name + ext;

			download_image(image_url, name, ext);
			this.sendReply(parts[0] + "'s avatar has been set.");
		},

		delete: function (target, room, user) {
			if (!this.can('customavatar')) return false;

			var userid = toId(target);
			var image = Config.customavatars[userid];

			if (!image) {
				return this.errorReply("This user does not have a custom avatar");
			}

			delete Config.customavatars[userid];

{'fraction_non_alphanumeric': 0.17484067608755888, 'fraction_numerical': 0.0038791909116098642, 'mean_word_length': 3.884979702300406, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '637515', 'n_tokens_mistral': 1398, 'n_tokens_neox': 1209, 'n_words': 292}