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()
|
data: new SlashCommandBuilder()
|
||||||
.setName('totalbeatlength')
|
.setName('totalbeatlength')
|
||||||
.setDescription('Calculate the time taken to beat every game on a users beat games list.')
|
.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) {
|
async execute(interaction) {
|
||||||
await interaction.deferReply();
|
await interaction.deferReply();
|
||||||
|
|
||||||
let user = interaction.user;
|
let user = interaction.user;
|
||||||
const userOption = interaction.options.getUser('user');
|
const userOption = interaction.options.getUser('user');
|
||||||
|
const showmissingOption = interaction.options.getBoolean('showmissing');
|
||||||
|
|
||||||
if (userOption) {
|
if (userOption) {
|
||||||
user = userOption;
|
user = userOption;
|
||||||
@ -40,7 +42,7 @@ module.exports = {
|
|||||||
gameIds.push(game.igdb_id);
|
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 timings = [];
|
||||||
const timeData = await getTimesToBeat(`where game_id = (${gameIds}); fields *; limit ${gameIds.length};`);
|
const timeData = await getTimesToBeat(`where game_id = (${gameIds}); fields *; limit ${gameIds.length};`);
|
||||||
@ -56,17 +58,32 @@ module.exports = {
|
|||||||
return interaction.editReply({ embeds: [embed] });
|
return interaction.editReply({ embeds: [embed] });
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < timeData.length; i++)
|
let average;
|
||||||
{
|
let desc;
|
||||||
if (timeData[i])
|
|
||||||
|
if (!showmissingOption) {
|
||||||
|
for (let i = 0; i < timeData.length; i++)
|
||||||
{
|
{
|
||||||
if (timeData[i].normally) { timings.push(timeData[i].normally / 3600); }
|
if (timeData[i])
|
||||||
else if (timeData[i].hastily) { timings.push(timeData[i].hastily / 3600); }
|
{
|
||||||
|
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()
|
const embed = new EmbedBuilder()
|
||||||
.setColor(0x6441a5)
|
.setColor(0x6441a5)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user