Compare commits

..

No commits in common. "ca68c4a017a9444e5327605b1f2dfdae79b59d9f" and "e489a1c710246a23e81ec3c30c9670264aab06b7" have entirely different histories.

3 changed files with 7 additions and 93 deletions

View File

@ -1,88 +0,0 @@
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('searchgame')
.setDescription('Searches the igdb database for matching games.')
.addStringOption(option => option.setName('gamename').setDescription('The name of the game').setRequired(true)),
async execute(interaction) {
const gamename = interaction.options.getString('gamename');
await interaction.reply(`Searching for ${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);
await games.sort((a, b) => parseInt(b.total_rating_count) - parseInt(a.total_rating_count));
let description = '';
for (const game of games) {
const release_dates = game['release_dates'];
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`);
}
}
if (description == '') description = 'No games found.';
const embed = new EmbedBuilder()
.setTitle(`"${gamename}" Search Results`)
.setDescription(`${description.slice(0, 1998)}`)
.setColor(0x6441a5);
await interaction.followUp({ embeds: [embed] });
},
};
async function getGameJson(body) {
let res;
await fetch(
'https://api.igdb.com/v4/games',
{ method: 'POST',
headers: {
'Accept': 'application/json',
'Client-ID': `${process.env.igdbClientId}`,
'Authorization': `Bearer ${process.env.igdbAccessToken}`,
},
body: body,
})
.then(response => response.json())
.then(response => {
res = response;
})
.catch(err => {
console.error(err);
});
return res;
}
async function getReleaseDates(id) {
let date;
await fetch(
'https://api.igdb.com/v4/release_dates',
{ method: 'POST',
headers: {
'Accept': 'application/json',
'Client-ID': `${process.env.igdbClientId}`,
'Authorization': `Bearer ${process.env.igdbAccessToken}`,
},
body: `where id = ${id}; fields category,checksum,created_at,date,game,human,m,platform,region,status,updated_at,y;`,
})
.then(response => response.json())
.then(response => {
date = response[0].human;
})
.catch(err => {
console.error(err);
});
return date;
}

View File

@ -1,10 +1,10 @@
const { REST, Routes } = require('discord.js'); const { REST, Routes } = require('discord.js');
const { config } = require('dotenv');
config();
const fs = require('node:fs'); const fs = require('node:fs');
const path = require('node:path'); const path = require('node:path');
const { config } = require('dotenv');
config();
const commands = []; const commands = [];
// Grab all the command files from the commands directory you created earlier // Grab all the command files from the commands directory you created earlier
const foldersPath = path.join(__dirname, 'commands'); const foldersPath = path.join(__dirname, 'commands');

View File

@ -1,13 +1,15 @@
// Require the necessary discord.js classes // Require the necessary discord.js classes
const fs = require('node:fs'); const fs = require('node:fs');
const path = require('node:path'); const path = require('node:path');
const { pathToFileURL } = require('node:url');
const { fileURLToPath } = require('url');
const { Client, Collection, Events, GatewayIntentBits } = require('discord.js'); const { Client, Collection, Events, GatewayIntentBits } = require('discord.js');
const { config } = require('dotenv'); const { config } = require('dotenv');
config(); config();
const { igdb } = require('./igdb.js'); const { igdb } = require('./igdb.js');
new igdb(); const igdbHelper = new igdb();
// Create a new client instance // Create a new client instance
const client = new Client({ intents: [GatewayIntentBits.Guilds] }); const client = new Client({ intents: [GatewayIntentBits.Guilds] });
@ -76,4 +78,4 @@ const Tags = sequelize.define('tags', {
client.once(Events.ClientReady, () => { client.once(Events.ClientReady, () => {
Tags.sync({ force: true }); Tags.sync({ force: true });
console.log(`Logged in as ${client.user.tag}!`); console.log(`Logged in as ${client.user.tag}!`);
}); })