{"size": 1878, "ext": "js", "max_stars_repo_path": "base/season.js", "max_stars_repo_name": "TiagoDanin/Defend-The-Castle", "max_stars_repo_stars_event_min_datetime": "2020-02-09T07:59:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-08T09:05:48.000Z", "max_issues_repo_path": "base/season.js", "max_issues_repo_name": "TiagoDanin/Defend-The-Castle", "max_issues_repo_issues_event_min_datetime": "2019-11-17T18:48:21.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-18T15:38:51.000Z", "max_forks_repo_path": "base/season.js", "max_forks_repo_name": "TiagoDanin/Defend-The-Castle", "max_forks_repo_forks_event_min_datetime": "2020-04-11T13:14:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-18T13:54:19.000Z"}
{"max_stars_count": 24, "max_issues_count": 13, "max_forks_count": 4, "avg_line_length": 25.7260273973, "max_line_length": 75, "alphanum_fraction": 0.6208732694}
const sortCaches = require('../utilities/sort-caches.js')
const config = require('./config')

const add = async (id, diamonds, database, bot) => {
	if (id && id < 100) {
		return
	}

	const play = await database.getUser(id)
	if (play) {
		const user = {
			from: {
				id
			},
			db: play
		}
		user.db.old = {...user.db}

		for (let i = 0; i < diamonds; i++) {
			user.db.inventory.push('11')
		}

		await database.saveUser(user)
	}

	return bot.telegram.sendMessage(id,
		`*🔥 Hall of Fame 🔥* - @DefendTheCastle - *💎 +${diamonds} 💎*`, {
			parse_mode: 'Markdown'
		}
	).catch(() => {})
}

const done = async (cache, database, bot) => {
	const sortWins = sortCaches.wins(cache)
	const sortBattles = sortCaches.battles(cache)
	const sortOnline = sortCaches.online(cache)

	const output = `
<b>🔥 Hall of Fame 🔥</b>

<b>Online (Interactions)</b> (💎 +1)
🥇 ${sortOnline[0].name} : ${sortOnline[0].id} (${sortOnline[0].count})
🥈 ${sortOnline[1].name} : ${sortOnline[1].id} (${sortOnline[1].count})

<b>Battles (Total)</b> (💎 +3)
🥇 ${sortBattles[0].name} : ${sortBattles[0].id} (${sortBattles[0].battles})
🥈 ${sortBattles[1].name} : ${sortBattles[1].id} (${sortBattles[1].battles})

<b>Battles (Wins)</b> (💎 +1 * Position)
🥇 ${sortWins[0].name} : ${sortWins[0].id} (${sortWins[0].wins})
🥈 ${sortWins[1].name} : ${sortWins[1].id} (${sortWins[1].wins})
🥉 ${sortWins[2].name} : ${sortWins[2].id} (${sortWins[2].wins})
`

	await add(sortWins[0].id, 3, database, bot)
	await add(sortWins[1].id, 2, database, bot)
	await add(sortWins[2].id, 1, database, bot)
	await add(sortBattles[0].id, 3, database, bot)
	await add(sortBattles[1].id, 3, database, bot)
	await add(sortOnline[0].id, 1, database, bot)
	await add(sortOnline[1].id, 1, database, bot)

	return bot.telegram.sendMessage(config.ids.channel,
		output, {
			parse_mode: 'HTML'
		}
	).catch(() => {})
}

module.exports = {
	done
}
