Compare commits
No commits in common. "d986b2cb7f5203609d852c706276737c999938e2" and "ca68c4a017a9444e5327605b1f2dfdae79b59d9f" have entirely different histories.
d986b2cb7f
...
ca68c4a017
|
@ -16,7 +16,7 @@ module.exports = {
|
||||||
|
|
||||||
if (!gamename && !gameid) return interaction.reply('No gamename or gameid supplied, please supply an option to register a game!');
|
if (!gamename && !gameid) return interaction.reply('No gamename or gameid supplied, please supply an option to register a game!');
|
||||||
|
|
||||||
let body = '';
|
let body = "";
|
||||||
|
|
||||||
if (gameid) {
|
if (gameid) {
|
||||||
body = body.concat('where id = ', gameid,'; ');
|
body = body.concat('where id = ', gameid,'; ');
|
||||||
|
@ -26,9 +26,9 @@ module.exports = {
|
||||||
|
|
||||||
body = body.concat('fields *;');
|
body = body.concat('fields *;');
|
||||||
|
|
||||||
const res = await getGameJson(body);
|
let res = await getGameJson(body);
|
||||||
|
|
||||||
if (!res[0]) return interaction.reply('No game found for the options supplied.');
|
if (!res[0]) return interaction.reply("No game found for the options supplied.");
|
||||||
|
|
||||||
const coverUrl = await getCoverURL(res[0].cover);
|
const coverUrl = await getCoverURL(res[0].cover);
|
||||||
|
|
||||||
|
@ -49,14 +49,14 @@ async function getGameJson(body) {
|
||||||
let res;
|
let res;
|
||||||
|
|
||||||
await fetch(
|
await fetch(
|
||||||
'https://api.igdb.com/v4/games',
|
"https://api.igdb.com/v4/games",
|
||||||
{ method: 'POST',
|
{ method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
'Client-ID': `${process.env.igdbClientId}`,
|
'Client-ID': `${process.env.igdbClientId}`,
|
||||||
'Authorization': `Bearer ${process.env.igdbAccessToken}`,
|
'Authorization': `Bearer ${process.env.igdbAccessToken}`,
|
||||||
},
|
},
|
||||||
body: body,
|
body: body
|
||||||
})
|
})
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
@ -72,14 +72,14 @@ async function getGameJson(body) {
|
||||||
async function getPlatformID(platform) {
|
async function getPlatformID(platform) {
|
||||||
|
|
||||||
await fetch(
|
await fetch(
|
||||||
'https://api.igdb.com/v4/platforms',
|
"https://api.igdb.com/v4/platforms",
|
||||||
{ method: 'POST',
|
{ method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
'Client-ID': `${process.env.igdbClientId}`,
|
'Client-ID': `${process.env.igdbClientId}`,
|
||||||
'Authorization': `Bearer ${process.env.igdbAccessToken}`,
|
'Authorization': `Bearer ${process.env.igdbAccessToken}`,
|
||||||
},
|
},
|
||||||
body: `where name = "${platform}", alternative_name = "${platform}"; fields id;`,
|
body: `where name = "${platform}", alternative_name = "${platform}"; fields id;`
|
||||||
})
|
})
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
@ -91,17 +91,17 @@ async function getPlatformID(platform) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getCoverURL(id) {
|
async function getCoverURL(id) {
|
||||||
let url = 'https://upload.wikimedia.org/wikipedia/commons/d/d1/Image_not_available.png';
|
let url = "https://upload.wikimedia.org/wikipedia/commons/d/d1/Image_not_available.png";
|
||||||
|
|
||||||
await fetch(
|
await fetch(
|
||||||
'https://api.igdb.com/v4/covers',
|
"https://api.igdb.com/v4/covers",
|
||||||
{ method: 'POST',
|
{ method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
'Client-ID': `${process.env.igdbClientId}`,
|
'Client-ID': `${process.env.igdbClientId}`,
|
||||||
'Authorization': `Bearer ${process.env.igdbAccessToken}`,
|
'Authorization': `Bearer ${process.env.igdbAccessToken}`,
|
||||||
},
|
},
|
||||||
body: `where id = ${id}; fields url;`,
|
body: `where id = ${id}; fields url;`
|
||||||
})
|
})
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
|
|
@ -10,19 +10,20 @@ module.exports = {
|
||||||
const gamename = interaction.options.getString('gamename');
|
const gamename = interaction.options.getString('gamename');
|
||||||
await interaction.reply(`Searching for ${gamename}...`);
|
await interaction.reply(`Searching for ${gamename}...`);
|
||||||
|
|
||||||
let games = await searchGamesWithMinimumReview(gamename);
|
let body = `search "${gamename}"; `;
|
||||||
|
body = await body.concat('fields *; limit 25; where (category = 0 | category = 4) & version_parent = null;');
|
||||||
|
|
||||||
if (games.length == 0) games = await searchGamesWithoutMinimumReview(gamename);
|
const games = await getGameJson(body);
|
||||||
|
|
||||||
if (games.length == 0) return interaction.followUp('No games found.');
|
|
||||||
|
|
||||||
await games.sort((a, b) => parseInt(b.total_rating_count) - parseInt(a.total_rating_count));
|
await games.sort((a, b) => parseInt(b.total_rating_count) - parseInt(a.total_rating_count));
|
||||||
|
|
||||||
let description = '';
|
let description = '';
|
||||||
|
|
||||||
for (const game of games) {
|
for (const game of games) {
|
||||||
if (game.first_release_date && (game.category == 0 || game.category == 4)) {
|
const release_dates = game['release_dates'];
|
||||||
const release_date = new Intl.DateTimeFormat('en-GB', { dateStyle: 'long' }).format(game.first_release_date * 1000);
|
if (release_dates && (game.category == 0 || game.category == 4)) {
|
||||||
|
const release_date = await getReleaseDates(release_dates[0]);
|
||||||
|
|
||||||
description = description.concat(`- **${game.name}** (*${release_date}*) - ID: ${game.id} \n`);
|
description = description.concat(`- **${game.name}** (*${release_date}*) - ID: ${game.id} \n`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,24 +39,6 @@ module.exports = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
async function searchGamesWithMinimumReview(gamename) {
|
|
||||||
let body = `search "${gamename}"; `;
|
|
||||||
body = await body.concat('fields *; limit 25; where (category = 0 | category = 4) & version_parent = null & total_rating_count > 0;');
|
|
||||||
|
|
||||||
const games = await getGameJson(body);
|
|
||||||
|
|
||||||
return games;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function searchGamesWithoutMinimumReview(gamename) {
|
|
||||||
let body = `search "${gamename}"; `;
|
|
||||||
body = await body.concat('fields *; limit 25; where (category = 0 | category = 4) & version_parent = null;');
|
|
||||||
|
|
||||||
const games = await getGameJson(body);
|
|
||||||
|
|
||||||
return games;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getGameJson(body) {
|
async function getGameJson(body) {
|
||||||
let res;
|
let res;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue