Add extra checking to GameDetails
This commit is contained in:
parent
ec8f707414
commit
99f53cfc78
|
@ -1,5 +1,5 @@
|
||||||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
||||||
const { getCoverURL, getGameJson, getCompanyInfo, getGenres, getFranchise } = require('../../igdbHelperFunctions.js');
|
const { getCoverURL, getGameJson, getCompanyInfo, getGenres, getFranchise, getReleaseDates } = require('../../igdbHelperFunctions.js');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
|
@ -30,13 +30,21 @@ module.exports = {
|
||||||
|
|
||||||
if (!games[0]) return interaction.followUp('No game found.');
|
if (!games[0]) return interaction.followUp('No game found.');
|
||||||
|
|
||||||
await games.sort((a, b) => parseInt(b.total_rating_count) - parseInt(a.total_rating_count));
|
// await games.sort((a, b) => parseInt(b.total_rating_count) - parseInt(a.total_rating_count));
|
||||||
|
await games.sort((a, b) => {
|
||||||
|
return (a.total_rating_count == null) - (b.total_rating_count == null) || +(a.total_rating_count > b.total_rating_count) || -(a.total_rating_count < b.total_rating_count);
|
||||||
|
});
|
||||||
|
|
||||||
const game = games[0];
|
const game = games[0];
|
||||||
|
|
||||||
const coverUrl = await getCoverURL(game.cover);
|
const coverUrl = await getCoverURL(game.cover);
|
||||||
|
|
||||||
const release_date = new Intl.DateTimeFormat('en-GB', { dateStyle: 'full' }).format(game.first_release_date * 1000);
|
let release_date;
|
||||||
|
if (game.first_release_date) {
|
||||||
|
release_date = new Intl.DateTimeFormat('en-GB', { dateStyle: 'full' }).format(game.first_release_date * 1000);
|
||||||
|
} else if (game.release_dates) {
|
||||||
|
release_date = await getReleaseDates(game.release_dates[0]);
|
||||||
|
}
|
||||||
|
|
||||||
const genres = [];
|
const genres = [];
|
||||||
for (const genreId of game.genres) {
|
for (const genreId of game.genres) {
|
||||||
|
@ -44,6 +52,7 @@ module.exports = {
|
||||||
genres.push(genre);
|
genres.push(genre);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Build Embed
|
||||||
const embed = new EmbedBuilder();
|
const embed = new EmbedBuilder();
|
||||||
embed.setColor(0x6441a5);
|
embed.setColor(0x6441a5);
|
||||||
embed.setTitle(`${game.name}`);
|
embed.setTitle(`${game.name}`);
|
||||||
|
@ -56,8 +65,10 @@ module.exports = {
|
||||||
|
|
||||||
for (const company of game.involved_companies) {
|
for (const company of game.involved_companies) {
|
||||||
const info = await getCompanyInfo(company);
|
const info = await getCompanyInfo(company);
|
||||||
|
if (info.name) {
|
||||||
companies.push(info.name);
|
companies.push(info.name);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
embed.addFields({ name: 'Developers', value: `${companies.join(', ')}`, inline: true });
|
embed.addFields({ name: 'Developers', value: `${companies.join(', ')}`, inline: true });
|
||||||
}
|
}
|
||||||
|
@ -69,7 +80,6 @@ module.exports = {
|
||||||
embed.addFields({ name: 'Rating', value: `${game.total_rating.toFixed(0)} / 100, ${game.total_rating_count } ratings`, inline: true });
|
embed.addFields({ name: 'Rating', value: `${game.total_rating.toFixed(0)} / 100, ${game.total_rating_count } ratings`, inline: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
embed.addFields({ name: 'ID', value: `${game.id}`, inline: true });
|
|
||||||
embed.setFooter({ text: 'The Ochulus • 100 Games Challenge', iconURL: interaction.client.user.avatarURL() });
|
embed.setFooter({ text: 'The Ochulus • 100 Games Challenge', iconURL: interaction.client.user.avatarURL() });
|
||||||
embed.setTimestamp();
|
embed.setTimestamp();
|
||||||
|
|
||||||
|
@ -78,6 +88,8 @@ module.exports = {
|
||||||
embed.addFields({ name: 'Franchise', value: `${franchise}`, inline: true });
|
embed.addFields({ name: 'Franchise', value: `${franchise}`, inline: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
embed.addFields({ name: 'ID', value: `${game.id}`, inline: true });
|
||||||
|
|
||||||
return interaction.followUp({ embeds: [embed] });
|
return interaction.followUp({ embeds: [embed] });
|
||||||
},
|
},
|
||||||
};
|
};
|
Loading…
Reference in New Issue