<commit_before>/*
    Voucher System for SpacialGaze
    Coded by HoeenHero
*/
'use strict';

const fs = require('fs');
let writeJSON = true;
let noRead = false;
let shopItems = ['Custom Symbol', 'Custom Avatar', 'Custom Color', 'Custom Title', 'Custom Icon'];
const eventLeaders = ['krakenmare', 'celestialtater'];
const expiresIn = 5; //false = never, otherwise specify a number of days. Vouchers will expire this number of days from creation.

class Voucher {
	constructor(userid, voucher, item, expires, id) {
		this.userid = userid;
		this.goodFor = voucher;
		this.expires = (expires ? expires : (expiresIn !== false ? (expiresIn * 24 * 60 * 60 * 1000 + Date.now()) : null));
		this.item = (item ? item : null); //item from shop / amount of currency
		this.id = (id ? id : SG.vouchers.storageForVocuherIds);
		if (!id) SG.vouchers.storageForVocuherIds++;
	}

	redeem() {
		if (!Users(this.userid)) return false;
		if (this.expires !== null && this.expires <= Date.now()) return 'expired'; //Voucher is expired
		switch (toId(this.goodFor)) {
		case 'currency':
			let self = this;
			Economy.writeMoney(self.userid, self.item, () => {
				Economy.readMoney(self.userid, newAmount => {
					if (Users(self.userid).connected) Users(self.userid).popup('|html|You have redemed a voucher for ' + self.item + ' ' + (self.item > 1 ? global.currencyPlural : global.currencyName) + '.');
				});
			});
			Economy.logTransaction(Chat.escapeHTML(Users(self.userid).name) + ' has redemed a voucher for ' + self.item + ' ' + (self.item === 1 ? global.currencyName : global.currencyPlural) + '.');
			break;
		case 'item':
			let valid = false;
			for (let i = 0; i < shopItems.length; i++) {
				if (toId(shopItems[i]) === toId(this.item)) valid = i;
			}
			if (!valid && valid !== 0) return false;
			if (!user.tokens) user.tokens = {};
			switch (toId(this.item)) {
			case 'customsymbol':
				Users(this.userid).popup('|html|You have redeemed a Custom Symbol. To activate your custom symbol, you can set it with with /customsymbol [symbol];<br/>once you set your symbol, you\'ll need to purchase this again to set a new one.<br/>You can remove your symbol with /resetsymbol.<br/>');
				Users(this.userid).canCustomSymbol = true;
				break;
			case 'customavatar':
				if (user.tokens.avatar) return 'token';
				user.tokens.avatar = true;
				Users(this.userid).popup('|html|You have purchased a Custom Avatar. Upper staff has been notified of your purchase and will contact you shortly.<br/>Inappropriate images may be denied; 80x80 is the optimal image resolution.<br/>');
				SG.messageSeniorStaff(Users(this.userid).name + " has purchased a Custom Avatar. Please contact this user to setup their Custom Avatar.");
				break;
			case 'customcolor':
				if (user.tokens.color) return 'token';
				user.tokens.color = true;
				Users(this.userid).popup('|html|You have purchased a Custom Name Color. Upper staff has been notified of your purchase and will contact you shortly.<br/>Colors must be easily visible on the website.<br/>');
				SG.messageSeniorStaff(Users(this.userid).name + " has purchased a Custom Color. Please contact this user to setup their Custom Color.");
				break;
			case 'customtitle':
				if (user.tokens.title) return 'token';
				user.tokens.title = true;
				Users(this.userid).popup('|html|You have purchased a Custom Title. Upper staff has been notified of your purchase and will contact you shortly.');
				SG.messageSeniorStaff(Users(this.userid).name + " has purchased a Custom Title. Please contact this user to setup their Custom Color.");
				break;
			case 'customicon':
				if (user.tokens.icon) return 'token';
				user.tokens.icon = true;
				Users(this.userid).popup('|html|You have purchased a Userlist Icon. Upper staff has been notified of your purchase and will contact you shortly.<br/>Inappropriate images may be denied; must be a 32x32 image.<br/>');
				SG.messageSeniorStaff(Users(this.userid).name + " has purchased a Userlist Icon. Please contact this user to setup their Userlist Icon.");
				break;
			}<commit_msg>Fixes & comment out unneeded code<commit_after>/*
    Voucher System for SpacialGaze
    Coded by HoeenHero
*/
'use strict';

const fs = require('fs');
let writeJSON = true;
let noRead = false;
let shopItems = ['Custom Symbol', 'Custom Avatar', 'Custom Color', 'Custom Title', 'Custom Icon'];
const eventLeaders = ['krakenmare', 'celestialtater'];
const expiresIn = 5; //false = never, otherwise specify a number of days. Vouchers will expire this number of days from creation.

class Voucher {
	constructor(userid, voucher, item, expires, id) {
		this.userid = userid;
		this.goodFor = voucher;
		this.expires = (expires ? expires : (expiresIn !== false ? (expiresIn * 24 * 60 * 60 * 1000 + Date.now()) : null));
		this.item = (item ? item : null); //item from shop / amount of currency
		this.id = (id ? id : SG.vouchers.storageForVocuherIds);
		if (!id) SG.vouchers.storageForVocuherIds++;
	}

	redeem() {
		if (!Users(this.userid)) return false;
		if (this.expires !== null && this.expires <= Date.now()) return 'expired'; //Voucher is expired
		switch (toId(this.goodFor)) {
		case 'currency':
			let self = this;
			Economy.writeMoney(self.userid, self.item, () => {
				Economy.readMoney(self.userid, newAmount => {
					if (Users(self.userid).connected) Users(self.userid).popup('|html|You have redemed a voucher for ' + self.item + ' ' + (self.item > 1 ? global.currencyPlural : global.currencyName) + '.');
				});
			});
			Economy.logTransaction(Chat.escapeHTML(Users(self.userid).name) + ' has redemed a voucher for ' + self.item + ' ' + (self.item === 1 ? global.currencyName : global.currencyPlural) + '.');
			break;
		case 'item':
			let user = Users(this.userid);
			let valid = false;
			for (let i = 0; i < shopItems.length; i++) {
				if (toId(shopItems[i]) === toId(this.item)) valid = i;
			}
			if (!valid && valid !== 0) return false;
			if (!user.tokens) user.tokens = {};
			switch (toId(this.item)) {
			case 'customsymbol':
				Users(this.userid).popup('|html|You have redeemed a Custom Symbol. To activate your custom symbol, you can set it with with /customsymbol [symbol];<br/>once you set your symbol, you\'ll need to purchase this again to set a new one.<br/>You can remove your symbol with /resetsymbol.<br/>');
				Users(this.userid).canCustomSymbol = true;
				break;
			case 'customavatar':
				if (user.tokens.avatar) return 'token';
				user.tokens.avatar = true;
				Users(this.userid).popup('|html|You have purchased a Custom Avatar. Upper staff has been notified of your purchase and will contact you shortly.<br/>Inappropriate images may be denied; 80x80 is the optimal image resolution.<br/>');
				//SG.messageSeniorStaff(Users(this.userid).name + " has purchased a Custom Avatar. Please contact this user to setup their Custom Avatar.");
				break;
			case 'customcolor':
				if (user.tokens.color) return 'token';
				user.tokens.color = true;
				Users(this.userid).popup('|html|You have purchased a Custom Name Color. Upper staff has been notified of your purchase and will contact you shortly.<br/>Colors must be easily visible on the website.<br/>');
				//SG.messageSeniorStaff(Users(this.userid).name + " has purchased a Custom Color. Please contact this user to setup their Custom Color.");
				break;
			case 'customtitle':
				if (user.tokens.title) return 'token';
				user.tokens.title = true;
				Users(this.userid).popup('|html|You have purchased a Custom Title. Upper staff has been notified of your purchase and will contact you shortly.');
				//SG.messageSeniorStaff(Users(this.userid).name + " has purchased a Custom Title. Please contact this user to setup their Custom Color.");
				break;
			case 'customicon':
				if (user.tokens.icon) return 'token';
				user.tokens.icon = true;
				Users(this.userid).popup('|html|You have purchased a Userlist Icon. Upper staff has been notified of your purchase and will contact you shortly.<br/>Inappropriate images may be denied; must be a 32x32 image.<br/>');
				//SG.messageSeniorStaff(Users(this.userid).name + " has purchased a Userlist Icon. Please contact this user to setup their Userlist Icon.");
				break;
			}
{'fraction_non_alphanumeric': 0.13317073170731708, 'fraction_numerical': 0.005609756097560975, 'mean_word_length': 3.8469267139479904, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 27, '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': '2952768', 'n_tokens_mistral': 2841, 'n_tokens_neox': 2486, 'n_words': 843}