<commit_before>'use strict';

const authStateFile = 'fauna_oauth2_state.json';

let oauth2;
let authState = {};

function saveAuthState(utils) {
	let state = {};

	Object.keys(authState).forEach(function(key) {
		if ('token' in authState[key]) {
			state[key] = authState[key].token;
		}
		else {
			state[key] = authState[key];
		}
	});

	utils.file.writeJson(authStateFile, state);
}

function setAccessToken(ircbot, utils, sender, accountName, token) {
	authState[accountName] = {
		token: token
	};

	saveAuthState(utils);

	ircbot.notice(sender, 'Authorization successful!');
}

function getAccountName(ircbot, sender, callback) {
	ircbot.remoteWhois(sender, function(info) {
		if (!('secure_connection' in info)) {
			ircbot.notice(sender, sender + ': This command only works over secure IRC connections');
			return;
		}

		if (!('account' in info)) {
			ircbot.notice(sender, sender + ': You are not logged in to IRC services. Please login and retry.');
			return;
		}

		callback(info.account);
	});
}

function getAuthURL(config, utils, sender, accountName, callback) {
	const crypto = require('crypto');
	let authParams = config.oauth2.authParams;

	crypto.randomBytes(32, (err, buf) => {
		if (err) {
			throw err;<commit_msg>Do not require secure connection for fauna commands<commit_after>'use strict';

const authStateFile = 'fauna_oauth2_state.json';

let oauth2;
let authState = {};

function saveAuthState(utils) {
	let state = {};

	Object.keys(authState).forEach(function(key) {
		if ('token' in authState[key]) {
			state[key] = authState[key].token;
		}
		else {
			state[key] = authState[key];
		}
	});

	utils.file.writeJson(authStateFile, state);
}

function setAccessToken(ircbot, utils, sender, accountName, token) {
	authState[accountName] = {
		token: token
	};

	saveAuthState(utils);

	ircbot.notice(sender, 'Authorization successful!');
}

function getAccountName(ircbot, sender, callback) {
	ircbot.remoteWhois(sender, function(info) {
		// broken for some reason - too lazy to debug
		// if (!('secure_connection' in info)) {
		// 	ircbot.notice(sender, sender + ': This command only works over secure IRC connections');
		// 	return;
		// }

		if (!('account' in info)) {
			ircbot.notice(sender, sender + ': You are not logged in to IRC services. Please login and retry.');
			return;
		}

		callback(info.account);
	});
}

function getAuthURL(config, utils, sender, accountName, callback) {
	const crypto = require('crypto');
	let authParams = config.oauth2.authParams;

	crypto.randomBytes(32, (err, buf) => {
		if (err) {
			throw err;
{'fraction_non_alphanumeric': 0.14335664335664336, 'fraction_numerical': 0.003885003885003885, 'mean_word_length': 4.421052631578948, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3917861', 'n_tokens_mistral': 926, 'n_tokens_neox': 847, 'n_words': 210}