Compare commits

...

4 Commits

Author SHA1 Message Date
baz 08ca63b120 Add remakes and remasters to game search command 2023-12-27 22:28:09 +00:00
baz 89818275c1 Add beatlist command 2023-12-27 22:27:55 +00:00
baz 5edbce160c make eslint stop crying at me 2023-12-27 21:46:09 +00:00
baz 662812964f Change recentGame description 2023-12-27 21:44:30 +00:00
5 changed files with 64 additions and 5 deletions

View File

@ -24,7 +24,7 @@ module.exports = {
body = body.concat('where id = ', gameid, '; '); body = body.concat('where id = ', gameid, '; ');
} else if (gamename) { } else if (gamename) {
body = body.concat('search "', gamename, '"; '); body = body.concat('search "', gamename, '"; ');
body = body.concat('limit 25; where (category = 0 | category = 4) & version_parent = null;'); body = body.concat('limit 25; where (category = 0 | category = 4 | category = 8 | category = 9) & version_parent = null;');
} }
body = body.concat('fields *;'); body = body.concat('fields *;');

View File

@ -0,0 +1,46 @@
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { getUserRegistration, getGames, checkGameStorageId } = require('../../databaseHelperFunctions.js');
const { getGameJson } = require('../../igdbHelperFunctions.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('beatlist')
.setDescription('Show the list of games you have beaten.')
.addUserOption(option => option.setName('user').setDescription('The user to check')),
async execute(interaction) {
let user = interaction.user;
const userOption = interaction.options.getUser('user');
if (userOption) {
user = userOption;
}
const userDatabaseEntry = await getUserRegistration(user);
if (!userDatabaseEntry) return interaction.reply({ content: `Issue checking registration with "${user.username}".`, ephemeral: true });
await interaction.reply({ content: `Searching for ${user.username}...`, ephemeral: true });
const beatenGamesDatabaseEntries = await getGames(userDatabaseEntry.id);
if (!beatenGamesDatabaseEntries || beatenGamesDatabaseEntries.length == 0) return interaction.followUp({ content: 'No games found.', ephemeral: true });
let desc = '';
for (let i = 0; i < beatenGamesDatabaseEntries.length; i++) {
const gameid = await checkGameStorageId(beatenGamesDatabaseEntries[i].gameId);
const res = await getGameJson(`where id = ${ gameid.igdb_id }; fields *;`);
const game = res[0];
desc = desc.concat('#', (i + 1), ' \t', game.name, '\n');
}
const embed = new EmbedBuilder()
.setColor(0x6441a5)
.setAuthor({ name: `${user.displayName}`, iconURL: user.avatarURL() })
.setTitle(`${interaction.user.username}'s beaten games`)
.setDescription(desc)
.setFooter({ text: 'The Ochulus • 100 Games Challenge', iconURL: interaction.client.user.avatarURL() })
.setTimestamp();
return interaction.followUp({ embeds: [embed] });
},
};

View File

@ -1,6 +1,6 @@
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { getCoverURL, getGameJson } = require('../../igdbHelperFunctions.js'); const { getCoverURL, getGameJson } = require('../../igdbHelperFunctions.js');
const { getUserRegistration, getRecentGameEntry } = require('../../databaseHelperFunctions.js'); const { getUserRegistration, getRecentGameEntry, getBeatenGameCount } = require('../../databaseHelperFunctions.js');
module.exports = { module.exports = {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
@ -27,6 +27,7 @@ module.exports = {
const game = res[0]; const game = res[0];
const coverUrl = await getCoverURL(game.cover); const coverUrl = await getCoverURL(game.cover);
const num = await getBeatenGameCount(userDatabaseEntry);
const embed = new EmbedBuilder() const embed = new EmbedBuilder()
.setColor(0xFFD700) .setColor(0xFFD700)
@ -35,7 +36,7 @@ module.exports = {
.setThumbnail(`${coverUrl}`) .setThumbnail(`${coverUrl}`)
.setFooter({ text: 'The Ochulus • 100 Games Challenge', iconURL: interaction.client.user.avatarURL() }) .setFooter({ text: 'The Ochulus • 100 Games Challenge', iconURL: interaction.client.user.avatarURL() })
.setTimestamp() .setTimestamp()
.addFields({ name: 'Description', value: `${game.summary}` }); .setDescription(`${interaction.user.displayName} has beaten ${num} games, they have ${100 - num} games remaining.`);
return interaction.reply({ embeds: [embed] }); return interaction.reply({ embeds: [embed] });
}, },

View File

@ -41,7 +41,7 @@ module.exports = {
async function searchGamesWithMinimumReview(gamename) { async function searchGamesWithMinimumReview(gamename) {
let body = `search "${gamename}"; `; let body = `search "${gamename}"; `;
body = await body.concat('fields *; limit 25; where (category = 0 | category = 4) & version_parent = null & total_rating_count > 0;'); body = await body.concat('fields *; limit 25; where (category = 0 | category = 4 | category = 8 | category = 9) & version_parent = null & total_rating_count > 0;');
const games = await getGameJson(body); const games = await getGameJson(body);

View File

@ -172,6 +172,17 @@ async function getRecentGameEntry(userId) {
return false; return false;
} }
async function getGames(id) {
const beatenGameEntry = await BeatenGames.findAll({ where: { userId: id } })
.catch((err) => {
console.log(err);
});
if (beatenGameEntry) return beatenGameEntry;
return false;
}
module.exports = { module.exports = {
checkUserRegistration, checkUserRegistration,
getUserRegistration, getUserRegistration,
@ -183,4 +194,5 @@ module.exports = {
checkGameStorageId, checkGameStorageId,
getLeaderboardEntries, getLeaderboardEntries,
getRecentGameEntry, getRecentGameEntry,
getGames,
}; };