Add option to view games with missing length info to totalbeatlength
This commit is contained in:
parent
5b9e7e1132
commit
05b8cfa228
@ -6,12 +6,14 @@ module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('totalbeatlength')
|
||||
.setDescription('Calculate the time taken to beat every game on a users beat games list.')
|
||||
.addUserOption(option => option.setName('user').setDescription('The user to check')),
|
||||
.addUserOption(option => option.setName('user').setDescription('The user to check'))
|
||||
.addBooleanOption(option => option.setName('showmissing').setDescription('Replaces the output with a list of games with missing length information')),
|
||||
async execute(interaction) {
|
||||
await interaction.deferReply();
|
||||
|
||||
let user = interaction.user;
|
||||
const userOption = interaction.options.getUser('user');
|
||||
const showmissingOption = interaction.options.getBoolean('showmissing');
|
||||
|
||||
if (userOption) {
|
||||
user = userOption;
|
||||
@ -40,7 +42,7 @@ module.exports = {
|
||||
gameIds.push(game.igdb_id);
|
||||
}
|
||||
|
||||
const beatGameIGDBEntries = await getGameJson(String.prototype.concat(`where id = (${gameIds}); fields *; limit ${gameIds.length};`));
|
||||
let beatGameIGDBEntries = await getGameJson(String.prototype.concat(`where id = (${gameIds}); fields *; limit ${gameIds.length};`));
|
||||
|
||||
const timings = [];
|
||||
const timeData = await getTimesToBeat(`where game_id = (${gameIds}); fields *; limit ${gameIds.length};`);
|
||||
@ -56,17 +58,32 @@ module.exports = {
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
for (let i = 0; i < timeData.length; i++)
|
||||
{
|
||||
if (timeData[i])
|
||||
let average;
|
||||
let desc;
|
||||
|
||||
if (!showmissingOption) {
|
||||
for (let i = 0; i < timeData.length; i++)
|
||||
{
|
||||
if (timeData[i].normally) { timings.push(timeData[i].normally / 3600); }
|
||||
else if (timeData[i].hastily) { timings.push(timeData[i].hastily / 3600); }
|
||||
if (timeData[i])
|
||||
{
|
||||
if (timeData[i].normally) { timings.push(timeData[i].normally / 3600); }
|
||||
else if (timeData[i].hastily) { timings.push(timeData[i].hastily / 3600); }
|
||||
}
|
||||
}
|
||||
|
||||
average = Math.round(timings.reduce((sum, num) => sum + num, 0));
|
||||
desc = `${user.displayName} has spent an estimated **${average} hours** beating games for the 100 games challenge *(${timings.length} of ${beatenGamesDatabaseEntries.length} included)*. `;
|
||||
} else {
|
||||
for (let i = 0; i < timeData.length; i++)
|
||||
{
|
||||
if (timeData[i].normally || timeData[i].hastily)
|
||||
{
|
||||
beatGameIGDBEntries = beatGameIGDBEntries.filter(item => item.id !== timeData[i].game_id);
|
||||
}
|
||||
}
|
||||
desc = beatGameIGDBEntries.map(item => `[${item.name}](<${item.url}>)`).join('\n');
|
||||
}
|
||||
|
||||
const average = Math.round(timings.reduce((sum, num) => sum + num, 0));
|
||||
const desc = `${user.displayName} has spent an estimated **${average} hours** beating games for the 100 games challenge *(${timings.length} of ${beatenGamesDatabaseEntries.length} included)*. `;
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(0x6441a5)
|
||||
|
Loading…
x
Reference in New Issue
Block a user