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 { Chart } = require('chart.js/auto');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const { getUserRegistration, getBeatenGames, checkGameStorageId } = require('../../databaseHelperFunctions.js');
|
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');
|
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@ -18,7 +18,6 @@ module.exports = {
|
|||||||
let user = interaction.user;
|
let user = interaction.user;
|
||||||
const userOption = interaction.options.getUser('user');
|
const userOption = interaction.options.getUser('user');
|
||||||
const yearOption = interaction.options.getInteger('year');
|
const yearOption = interaction.options.getInteger('year');
|
||||||
const ignoreadventure = interaction.options.getBoolean('ignoreadventure');
|
|
||||||
|
|
||||||
if (userOption) {
|
if (userOption) {
|
||||||
user = userOption;
|
user = userOption;
|
||||||
@ -51,38 +50,41 @@ module.exports = {
|
|||||||
return interaction.editReply({ embeds: [embed] });
|
return interaction.editReply({ embeds: [embed] });
|
||||||
}
|
}
|
||||||
|
|
||||||
const beatGameIGDBEntries = [];
|
const gameIds = [];
|
||||||
|
|
||||||
for (let i = 0; i < beatenGamesDatabaseEntries.length; i++) {
|
for (let i = 0; i < beatenGamesDatabaseEntries.length; i++) {
|
||||||
const game = await checkGameStorageId(beatenGamesDatabaseEntries[i].gameId);
|
const game = await checkGameStorageId(beatenGamesDatabaseEntries[i].gameId);
|
||||||
const json = await getGameJson(String.prototype.concat('where id = ', game.igdb_id, '; fields *;'));
|
gameIds.push(game.igdb_id);
|
||||||
beatGameIGDBEntries.push(json[0]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const companies = [];
|
const beatGameIGDBEntries = await getGameJson(String.prototype.concat(`where id = (${gameIds}); fields *; limit ${gameIds.length};`));
|
||||||
const companyIds = new Set();
|
|
||||||
|
const involvedCompanyIds = new Set();
|
||||||
|
|
||||||
for (let i = 0; i < beatGameIGDBEntries.length; i++) {
|
for (let i = 0; i < beatGameIGDBEntries.length; i++) {
|
||||||
if (beatGameIGDBEntries[i].involved_companies)
|
if (beatGameIGDBEntries[i].involved_companies)
|
||||||
{
|
{
|
||||||
for (let j = 0; j < beatGameIGDBEntries[i].involved_companies.length; j++) {
|
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 involvedIds = [...involvedCompanyIds];
|
||||||
const tempIds = [];
|
|
||||||
|
|
||||||
for (let i = 0; i < ids.length; i++) {
|
const involvedCompanies = await getInvolvedCompanies(involvedIds);
|
||||||
const company = await getCompanyInfo(ids[i]);
|
const companyIds = new Set();
|
||||||
|
for (let i = 0; i < involvedCompanies.length; i++) {
|
||||||
if (!tempIds.includes(company.id)) {
|
if (involvedCompanies[i].company)
|
||||||
tempIds.push(company.id);
|
{
|
||||||
companies.push(company);
|
companyIds.add(involvedCompanies[i].company);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const compIds = [...companyIds];
|
||||||
|
const companies = await getCompanies(compIds);
|
||||||
|
|
||||||
|
|
||||||
const developers = [];
|
const developers = [];
|
||||||
const counts = [];
|
const counts = [];
|
||||||
|
|
||||||
|
@ -94,6 +94,54 @@ async function getReleaseDates(id) {
|
|||||||
return date;
|
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) {
|
async function getCompanyInfo(id) {
|
||||||
|
|
||||||
let involved_company;
|
let involved_company;
|
||||||
@ -193,6 +241,8 @@ module.exports = {
|
|||||||
getPlatformID,
|
getPlatformID,
|
||||||
getGameJson,
|
getGameJson,
|
||||||
getReleaseDates,
|
getReleaseDates,
|
||||||
|
getInvolvedCompanies,
|
||||||
|
getCompanies,
|
||||||
getCompanyInfo,
|
getCompanyInfo,
|
||||||
getGenres,
|
getGenres,
|
||||||
getFranchise,
|
getFranchise,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user