{"size": 1646, "ext": "js", "max_stars_repo_path": "modules/misc/currency.js", "max_stars_repo_name": "Ravexburn/LuckyBot", "max_stars_repo_stars_event_min_datetime": "2017-12-27T06:18:53.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-18T20:10:47.000Z", "max_issues_repo_path": "modules/misc/currency.js", "max_issues_repo_name": "Ravexburn/LuckyBot", "max_issues_repo_issues_event_min_datetime": "2017-12-29T05:36:12.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-04T22:41:05.000Z", "max_forks_repo_path": "modules/misc/currency.js", "max_forks_repo_name": "Ravexburn/LuckyBot", "max_forks_repo_forks_event_min_datetime": "2017-12-27T23:47:56.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-02T17:18:54.000Z"}
{"max_stars_count": 21, "max_issues_count": 5, "max_forks_count": 14, "avg_line_length": 35.0212765957, "max_line_length": 148, "alphanum_fraction": 0.6822600243}
const Discord = require("discord.js");
const Profile = require("./profile_data.js");
const profile = new Profile();
const Enmap = require("enmap");
const EnmapLevel = require("enmap-level");
const currencyProvider = new EnmapLevel({ name: 'tickets' });
const currency = new Enmap({ provider: currencyProvider });
const MSG_TIME = 6 * 60 * 60 * 1000;

module.exports = (bot = Discord.Client) => {

	require("../../functions/functions.js")(bot);

	curFunction = async function curFunction(message) {

		if (message.system || message.author.bot || message.channel.type === "dm") return;

		let userID = message.author.id;
		if (!currency.has(userID)) {
			currency.set(userID, 0);
		}
		let curTimer = currency.get(userID);
		if (!curTimer) {
			curTimer = 0;
		}
		const timedif = message.createdTimestamp - curTimer;
		if (curTimer <= message.createdTimestamp && timedif >= MSG_TIME) {
			curTimer = message.createdTimestamp;
			currency.set(userID, curTimer);
			try {
				const data = await profile.getProfileData(userID);
				await data;
				let tickets = data.tickets;
				let guildSize = Math.floor(bot.guilds.size / 100) + 1;
				tickets = tickets + guildSize;
				message.channel.send(`You have been granted ${guildSize} ticket(s)! <:rooDuck:432962760570044417>`).catch(console.error);
				await profile.setCur(userID, tickets);
			} catch (error) {
				console.log(error);
			}
		} else {
			let time = MSG_TIME - timedif;
			const {seconds, minutes, hours} = timeFunction(time);
			message.channel.send(`Please wait ${hours}h ${minutes}m and ${seconds}s for a new ticket! <:rooScared:433018721326596117>`).catch(console.error);
		}
	};
};