Update game details and random game embeds
This commit is contained in:
parent
bb99f2ff73
commit
abd3c10316
@ -1,5 +1,5 @@
|
|||||||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
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 = {
|
module.exports = {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
@ -87,11 +87,10 @@ module.exports = {
|
|||||||
const publishers = [];
|
const publishers = [];
|
||||||
|
|
||||||
for (const company of companies) {
|
for (const company of companies) {
|
||||||
|
|
||||||
if (company.developed)
|
if (company.developed)
|
||||||
{
|
{
|
||||||
if (company.developed.find(item => item === game.id)) {
|
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)
|
||||||
{
|
{
|
||||||
if (company.published.find(item => item === game.id)) {
|
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) {
|
if (game.franchises) {
|
||||||
const franchise = await getFranchise(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 });
|
embed.addFields({ name: 'ID', value: `${game.id}`, inline: true });
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
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 = {
|
module.exports = {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
@ -77,11 +77,10 @@ module.exports = {
|
|||||||
const publishers = [];
|
const publishers = [];
|
||||||
|
|
||||||
for (const company of companies) {
|
for (const company of companies) {
|
||||||
|
|
||||||
if (company.developed)
|
if (company.developed)
|
||||||
{
|
{
|
||||||
if (company.developed.find(item => item === game.id)) {
|
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)
|
||||||
{
|
{
|
||||||
if (company.published.find(item => item === game.id)) {
|
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) {
|
if (game.franchises) {
|
||||||
const franchise = await getFranchise(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 });
|
embed.addFields({ name: 'ID', value: `${game.id}`, inline: true });
|
||||||
|
@ -233,7 +233,32 @@ async function getFranchise(id) {
|
|||||||
console.error(err);
|
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 = {
|
module.exports = {
|
||||||
@ -246,4 +271,5 @@ module.exports = {
|
|||||||
getCompanyInfo,
|
getCompanyInfo,
|
||||||
getGenres,
|
getGenres,
|
||||||
getFranchise,
|
getFranchise,
|
||||||
|
getTimeToBeat,
|
||||||
};
|
};
|
Loading…
x
Reference in New Issue
Block a user