Batch chart game developers
This commit is contained in:
parent
e01dfd8291
commit
7977cada59
@ -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, getCompanyInfo } = require('../../igdbHelperFunctions.js');
|
||||
const { getGameJson, getInvolvedCompanies, getCompanies } = require('../../igdbHelperFunctions.js');
|
||||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
@ -18,7 +18,6 @@ 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;
|
||||
@ -51,38 +50,41 @@ module.exports = {
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
const beatGameIGDBEntries = [];
|
||||
const gameIds = [];
|
||||
|
||||
for (let i = 0; i < beatenGamesDatabaseEntries.length; i++) {
|
||||
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 game = await checkGameStorageId(beatenGamesDatabaseEntries[i].gameId);
|
||||
gameIds.push(game.igdb_id);
|
||||
}
|
||||
|
||||
const companies = [];
|
||||
const companyIds = new Set();
|
||||
const beatGameIGDBEntries = await getGameJson(String.prototype.concat(`where id = (${gameIds}); fields *; limit ${gameIds.length};`));
|
||||
|
||||
const involvedCompanyIds = 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++) {
|
||||
companyIds.add(beatGameIGDBEntries[i].involved_companies[j]);
|
||||
involvedCompanyIds.add(beatGameIGDBEntries[i].involved_companies[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const ids = [...companyIds];
|
||||
const tempIds = [];
|
||||
const involvedIds = [...involvedCompanyIds];
|
||||
|
||||
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 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);
|
||||
}
|
||||
}
|
||||
|
||||
const compIds = [...companyIds];
|
||||
const companies = await getCompanies(compIds);
|
||||
|
||||
|
||||
const developers = [];
|
||||
const counts = [];
|
||||
|
||||
|
@ -94,6 +94,54 @@ 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;
|
||||
@ -193,6 +241,8 @@ module.exports = {
|
||||
getPlatformID,
|
||||
getGameJson,
|
||||
getReleaseDates,
|
||||
getInvolvedCompanies,
|
||||
getCompanies,
|
||||
getCompanyInfo,
|
||||
getGenres,
|
||||
getFranchise,
|
||||
|
Loading…
x
Reference in New Issue
Block a user