Compare commits
2 Commits
e81668c514
...
b2adab3ec8
Author | SHA1 | Date |
---|---|---|
baz | b2adab3ec8 | |
baz | 00ced7006e |
|
@ -30,9 +30,7 @@ module.exports = {
|
|||
|
||||
if (!games[0]) return interaction.followUp('No game found.');
|
||||
|
||||
await games.sort((a, b) => {
|
||||
return (a.total_rating_count == null) - (b.total_rating_count == null) || +(a.total_rating_count > b.total_rating_count) || -(a.total_rating_count < b.total_rating_count);
|
||||
});
|
||||
await games.sort((a, b) => parseInt(b.total_rating_count) - parseInt(a.total_rating_count));
|
||||
|
||||
const game = games[0];
|
||||
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
||||
const { getCoverURL, getGameJson } = require('../../igdbHelperFunctions.js');
|
||||
const { getUserRegistration, getRecentGameEntry } = require('../../databaseHelperFunctions.js');
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('recentbeat')
|
||||
.setDescription('Get the most recent game you have beat.')
|
||||
.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 "${interaction.user.username}".`, ephemeral: true });
|
||||
|
||||
const gameDatabaseEntry = await getRecentGameEntry(userDatabaseEntry.id);
|
||||
if (!gameDatabaseEntry) return interaction.reply({ content: 'No game found.', ephemeral: true });
|
||||
|
||||
const body = `where id = ${ gameDatabaseEntry.igdb_id }; fields *;`;
|
||||
const res = await getGameJson(body);
|
||||
if (!res) return interaction.reply({ content: 'No game found.', ephemeral: true });
|
||||
const game = res[0];
|
||||
|
||||
const coverUrl = await getCoverURL(game.cover);
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(0xFFD700)
|
||||
.setAuthor({ name: `${user.displayName}'s most recent beat game!`, iconURL: user.avatarURL() })
|
||||
.setTitle(game.name)
|
||||
.setThumbnail(`${coverUrl}`)
|
||||
.setFooter({ text: 'The Ochulus • 100 Games Challenge', iconURL: interaction.client.user.avatarURL() })
|
||||
.setTimestamp()
|
||||
.addFields({ name: 'Description', value: `${game.summary}` });
|
||||
|
||||
return interaction.reply({ embeds: [embed] });
|
||||
},
|
||||
};
|
|
@ -2,17 +2,7 @@ const { Users, Games, BeatenGames } = require ('./dbObjects.js');
|
|||
|
||||
async function checkUserRegistration(user) {
|
||||
|
||||
let u = await Users.findOne({ where: { discord_id: user.id } })
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
if (u) return true;
|
||||
|
||||
await Users.create({ discord_id: user.id, username: user.username })
|
||||
.then((data) => {
|
||||
u = data;
|
||||
})
|
||||
const u = await Users.findOne({ where: { discord_id: user.id } })
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
|
@ -164,6 +154,24 @@ async function getLeaderboardEntries() {
|
|||
return results;
|
||||
}
|
||||
|
||||
async function getRecentGameEntry(userId) {
|
||||
const beatenGameEntry = await BeatenGames.findOne({ where: { userId: userId }, order: [ [ 'createdAt', 'DESC' ]] })
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
if (!beatenGameEntry) return false;
|
||||
|
||||
const game = await Games.findOne({ where: { id: beatenGameEntry.gameId } })
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
if (game) return game;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
checkUserRegistration,
|
||||
getUserRegistration,
|
||||
|
@ -174,4 +182,5 @@ module.exports = {
|
|||
deleteBeatenGameNum,
|
||||
checkGameStorageId,
|
||||
getLeaderboardEntries,
|
||||
getRecentGameEntry,
|
||||
};
|
Loading…
Reference in New Issue