Update game details and random game embeds

This commit is contained in:
baz 2025-05-14 23:17:25 +01:00
parent bb99f2ff73
commit abd3c10316
3 changed files with 85 additions and 11 deletions

View File

@ -1,5 +1,5 @@
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { getCoverURL, getGameJson, getGenres, getFranchise, getReleaseDates, getInvolvedCompanies, getCompanies } = require('../../igdbHelperFunctions.js');
const { getCoverURL, getGameJson, getGenres, getFranchise, getReleaseDates, getInvolvedCompanies, getCompanies, getTimeToBeat } = require('../../igdbHelperFunctions.js');
module.exports = {
data: new SlashCommandBuilder()
@ -87,11 +87,10 @@ module.exports = {
const publishers = [];
for (const company of companies) {
if (company.developed)
{
if (company.developed.find(item => item === game.id)) {
developers.push(company.name);
developers.push(`[${company.name}](${company.url})`);
}
}
@ -99,7 +98,7 @@ module.exports = {
if (company.published)
{
if (company.published.find(item => item === game.id)) {
publishers.push(company.name);
publishers.push(`[${company.name}](${company.url})`);
}
}
}
@ -131,7 +130,32 @@ module.exports = {
if (game.franchises) {
const franchise = await getFranchise(game.franchises);
embed.addFields({ name: 'Franchise', value: `${franchise}`, inline: true });
embed.addFields({ name: 'Franchise', value: `[${franchise.name}](${franchise.url})`, inline: true });
}
const gameTimeToBeat = await getTimeToBeat(game.id);
if (gameTimeToBeat) {
const timings = [];
if (gameTimeToBeat.hastily) {
const hours = Math.floor(gameTimeToBeat.hastily / 3600);
timings.push(`Hastily: ${hours}hr`);
}
if (gameTimeToBeat.normally) {
const hours = Math.floor(gameTimeToBeat.normally / 3600);
timings.push(`Normally: ${hours}hr`);
}
if (gameTimeToBeat.completely) {
const hours = Math.floor(gameTimeToBeat.completely / 3600);
timings.push(`Completely: ${hours}hr`);
}
if (timings.length > 0) {
embed.addFields({ name: 'Time to Beat', value: `${timings.join('\n')}`, inline: true });
}
}
embed.addFields({ name: 'ID', value: `${game.id}`, inline: true });

View File

@ -1,5 +1,5 @@
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { getCoverURL, getGameJson, getInvolvedCompanies, getCompanies, getGenres, getReleaseDates, getFranchise } = require('../../igdbHelperFunctions.js');
const { getCoverURL, getGameJson, getInvolvedCompanies, getCompanies, getGenres, getReleaseDates, getFranchise, getTimeToBeat } = require('../../igdbHelperFunctions.js');
module.exports = {
data: new SlashCommandBuilder()
@ -77,11 +77,10 @@ module.exports = {
const publishers = [];
for (const company of companies) {
if (company.developed)
{
if (company.developed.find(item => item === game.id)) {
developers.push(company.name);
developers.push(`[${company.name}](${company.url})`);
}
}
@ -89,7 +88,7 @@ module.exports = {
if (company.published)
{
if (company.published.find(item => item === game.id)) {
publishers.push(company.name);
publishers.push(`[${company.name}](${company.url})`);
}
}
}
@ -120,7 +119,32 @@ module.exports = {
if (game.franchises) {
const franchise = await getFranchise(game.franchises);
embed.addFields({ name: 'Franchise', value: `${franchise}`, inline: true });
embed.addFields({ name: 'Franchise', value: `[${franchise.name}](${franchise.url})`, inline: true });
}
const gameTimeToBeat = await getTimeToBeat(game.id);
if (gameTimeToBeat) {
const timings = [];
if (gameTimeToBeat.hastily) {
const hours = Math.floor(gameTimeToBeat.hastily / 3600);
timings.push(`Hastily: ${hours}hr`);
}
if (gameTimeToBeat.normally) {
const hours = Math.floor(gameTimeToBeat.normally / 3600);
timings.push(`Normally: ${hours}hr`);
}
if (gameTimeToBeat.completely) {
const hours = Math.floor(gameTimeToBeat.completely / 3600);
timings.push(`Completely: ${hours}hr`);
}
if (timings.length > 0) {
embed.addFields({ name: 'Time to Beat', value: `${timings.join('\n')}`, inline: true });
}
}
embed.addFields({ name: 'ID', value: `${game.id}`, inline: true });

View File

@ -233,7 +233,32 @@ async function getFranchise(id) {
console.error(err);
});
return franchise.name;
return franchise;
}
async function getTimeToBeat(id) {
let gameTimeToBeats;
await fetch(
'https://api.igdb.com/v4/game_time_to_beats',
{ method: 'POST',
headers: {
'Accept': 'application/json',
'Client-ID': `${process.env.igdbClientId}`,
'Authorization': `Bearer ${process.env.igdbAccessToken}`,
},
body: `where game_id = ${id}; fields *;`,
})
.then(response => response.json())
.then(response => {
gameTimeToBeats = response[0];
})
.catch(err => {
console.error(err);
});
return gameTimeToBeats;
}
module.exports = {
@ -246,4 +271,5 @@ module.exports = {
getCompanyInfo,
getGenres,
getFranchise,
getTimeToBeat,
};