Compare commits

..

No commits in common. "791d4dd33a37bb9d28e7605a04c111f093c82a1e" and "e01dfd8291559d9755fbaca35b245ebfde630679" have entirely different histories.

3 changed files with 34 additions and 87 deletions

View File

@ -2,7 +2,7 @@ const { createCanvas } = require('canvas');
const { Chart } = require('chart.js/auto');
const fs = require('fs');
const { getUserRegistration, getBeatenGames, checkGameStorageId } = require('../../databaseHelperFunctions.js');
const { getGameJson, getInvolvedCompanies, getCompanies } = require('../../igdbHelperFunctions.js');
const { getGameJson, getCompanyInfo } = require('../../igdbHelperFunctions.js');
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
module.exports = {
@ -18,6 +18,7 @@ module.exports = {
let user = interaction.user;
const userOption = interaction.options.getUser('user');
const yearOption = interaction.options.getInteger('year');
const ignoreadventure = interaction.options.getBoolean('ignoreadventure');
if (userOption) {
user = userOption;
@ -50,41 +51,38 @@ module.exports = {
return interaction.editReply({ embeds: [embed] });
}
const gameIds = [];
const beatGameIGDBEntries = [];
for (let i = 0; i < beatenGamesDatabaseEntries.length; i++) {
const game = await checkGameStorageId(beatenGamesDatabaseEntries[i].gameId);
gameIds.push(game.igdb_id);
const game = await checkGameStorageId(beatenGamesDatabaseEntries[i].gameId);
const json = await getGameJson(String.prototype.concat('where id = ', game.igdb_id, '; fields *;'));
beatGameIGDBEntries.push(json[0]);
}
const beatGameIGDBEntries = await getGameJson(String.prototype.concat(`where id = (${gameIds}); fields *; limit ${gameIds.length};`));
const involvedCompanyIds = new Set();
const companies = [];
const companyIds = new Set();
for (let i = 0; i < beatGameIGDBEntries.length; i++) {
if (beatGameIGDBEntries[i].involved_companies)
{
for (let j = 0; j < beatGameIGDBEntries[i].involved_companies.length; j++) {
involvedCompanyIds.add(beatGameIGDBEntries[i].involved_companies[j]);
companyIds.add(beatGameIGDBEntries[i].involved_companies[j]);
}
}
}
const involvedIds = [...involvedCompanyIds];
const ids = [...companyIds];
const tempIds = [];
const involvedCompanies = await getInvolvedCompanies(involvedIds);
const companyIds = new Set();
for (let i = 0; i < involvedCompanies.length; i++) {
if (involvedCompanies[i].company)
{
companyIds.add(involvedCompanies[i].company);
for (let i = 0; i < ids.length; i++) {
const company = await getCompanyInfo(ids[i]);
if (!tempIds.includes(company.id)) {
tempIds.push(company.id);
companies.push(company);
}
}
const compIds = [...companyIds];
const companies = await getCompanies(compIds);
const developers = [];
const counts = [];

View File

@ -2,7 +2,7 @@ const { createCanvas } = require('canvas');
const { Chart } = require('chart.js/auto');
const fs = require('fs');
const { getUserRegistration, getBeatenGames, checkGameStorageId } = require('../../databaseHelperFunctions.js');
const { getGameJson, getInvolvedCompanies, getCompanies } = require('../../igdbHelperFunctions.js');
const { getGameJson, getCompanyInfo } = require('../../igdbHelperFunctions.js');
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
module.exports = {
@ -18,6 +18,7 @@ module.exports = {
let user = interaction.user;
const userOption = interaction.options.getUser('user');
const yearOption = interaction.options.getInteger('year');
const ignoreadventure = interaction.options.getBoolean('ignoreadventure');
if (userOption) {
user = userOption;
@ -50,40 +51,38 @@ module.exports = {
return interaction.editReply({ embeds: [embed] });
}
const gameIds = [];
const beatGameIGDBEntries = [];
for (let i = 0; i < beatenGamesDatabaseEntries.length; i++) {
const game = await checkGameStorageId(beatenGamesDatabaseEntries[i].gameId);
gameIds.push(game.igdb_id);
const game = await checkGameStorageId(beatenGamesDatabaseEntries[i].gameId);
const json = await getGameJson(String.prototype.concat('where id = ', game.igdb_id, '; fields *;'));
beatGameIGDBEntries.push(json[0]);
}
const beatGameIGDBEntries = await getGameJson(String.prototype.concat(`where id = (${gameIds}); fields *; limit ${gameIds.length};`));
const involvedCompanyIds = new Set();
const companies = [];
const companyIds = new Set();
for (let i = 0; i < beatGameIGDBEntries.length; i++) {
if (beatGameIGDBEntries[i].involved_companies)
{
for (let j = 0; j < beatGameIGDBEntries[i].involved_companies.length; j++) {
involvedCompanyIds.add(beatGameIGDBEntries[i].involved_companies[j]);
companyIds.add(beatGameIGDBEntries[i].involved_companies[j]);
}
}
}
const involvedIds = [...involvedCompanyIds];
const ids = [...companyIds];
const tempIds = [];
const involvedCompanies = await getInvolvedCompanies(involvedIds);
const companyIds = new Set();
for (let i = 0; i < involvedCompanies.length; i++) {
if (involvedCompanies[i].company)
{
companyIds.add(involvedCompanies[i].company);
for (let i = 0; i < ids.length; i++) {
const company = await getCompanyInfo(ids[i]);
if (!tempIds.includes(company.id)) {
tempIds.push(company.id);
companies.push(company);
}
}
const compIds = [...companyIds];
const companies = await getCompanies(compIds);
const publishers = [];
const counts = [];

View File

@ -94,54 +94,6 @@ async function getReleaseDates(id) {
return date;
}
async function getInvolvedCompanies(ids) {
let involved_companies;
await fetch(
'https://api.igdb.com/v4/involved_companies',
{ method: 'POST',
headers: {
'Accept': 'application/json',
'Client-ID': `${process.env.igdbClientId}`,
'Authorization': `Bearer ${process.env.igdbAccessToken}`,
},
body: `where id = (${ids}); fields *; limit ${ids.length};`,
})
.then(response => response.json())
.then(response => {
involved_companies = response;
})
.catch(err => {
return console.error(err);
});
return involved_companies;
}
async function getCompanies(ids) {
let companies;
await fetch(
'https://api.igdb.com/v4/companies',
{ method: 'POST',
headers: {
'Accept': 'application/json',
'Client-ID': `${process.env.igdbClientId}`,
'Authorization': `Bearer ${process.env.igdbAccessToken}`,
},
body: `where id = (${ids}); fields *; limit ${ids.length};`,
})
.then(response => response.json())
.then(response => {
companies = response;
})
.catch(err => {
return console.error(err);
});
return companies;
}
async function getCompanyInfo(id) {
let involved_company;
@ -241,8 +193,6 @@ module.exports = {
getPlatformID,
getGameJson,
getReleaseDates,
getInvolvedCompanies,
getCompanies,
getCompanyInfo,
getGenres,
getFranchise,