Compare commits
No commits in common. "e263e9732cb0fc575b6032467607719699aa06de" and "91bffb65c7285f2b8e5dc74a58eab5a0e03296b6" have entirely different histories.
e263e9732c
...
91bffb65c7
|
@ -1,6 +1,5 @@
|
||||||
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 { checkUserRegistration, checkGameStorage, getUserRegistration, createBeatenGameEntry, getBeatenGameCount } = require('../../databaseHelperFunctions.js');
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
|
@ -12,10 +11,6 @@ module.exports = {
|
||||||
.addStringOption(option => option.setName('datebeaten').setDescription('The date you beat the game (today if empty).'))
|
.addStringOption(option => option.setName('datebeaten').setDescription('The date you beat the game (today if empty).'))
|
||||||
.addStringOption(option => option.setName('platform').setDescription('The platform the game was released on.')),
|
.addStringOption(option => option.setName('platform').setDescription('The platform the game was released on.')),
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
|
|
||||||
if (!checkUserRegistration(interaction.user)) return interaction.reply(`Issue checking registration with "${interaction.user.username}".`);
|
|
||||||
const userDatabaseEntry = await getUserRegistration(interaction.user);
|
|
||||||
|
|
||||||
const gamename = interaction.options.getString('gamename');
|
const gamename = interaction.options.getString('gamename');
|
||||||
const gameid = interaction.options.getNumber('gameid');
|
const gameid = interaction.options.getNumber('gameid');
|
||||||
const platform = interaction.options.getString('platform');
|
const platform = interaction.options.getString('platform');
|
||||||
|
@ -36,10 +31,6 @@ module.exports = {
|
||||||
|
|
||||||
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 gameDatabaseEntry = await checkGameStorage(res[0]);
|
|
||||||
|
|
||||||
await createBeatenGameEntry(userDatabaseEntry, gameDatabaseEntry);
|
|
||||||
const num = await getBeatenGameCount(userDatabaseEntry);
|
|
||||||
const coverUrl = await getCoverURL(res[0].cover);
|
const coverUrl = await getCoverURL(res[0].cover);
|
||||||
|
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
|
@ -47,7 +38,7 @@ module.exports = {
|
||||||
.setAuthor({ name: `${interaction.user.displayName} beat a new game!`, iconURL: interaction.user.avatarURL() })
|
.setAuthor({ name: `${interaction.user.displayName} beat a new game!`, iconURL: interaction.user.avatarURL() })
|
||||||
.setTitle(`${res[0].name} beaten!`)
|
.setTitle(`${res[0].name} beaten!`)
|
||||||
.setThumbnail(`${coverUrl}`)
|
.setThumbnail(`${coverUrl}`)
|
||||||
.setDescription(`${interaction.user.displayName} has beaten ${num} games, they have ${100 - num} games remaining.`)
|
.setDescription(`${interaction.user.displayName} has beaten 69 games, they have 31 games remaining.`)
|
||||||
.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();
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
const { Users, Games, BeatenGames } = require ('./dbObjects.js');
|
const { SlashCommandBuilder } = require('discord.js');
|
||||||
|
const { Users } = require ('./dbObjects.js');
|
||||||
|
|
||||||
async function checkUserRegistration(user) {
|
async function checkUserRegistration(user) {
|
||||||
|
|
||||||
|
@ -22,87 +23,6 @@ async function checkUserRegistration(user) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getUserRegistration(user) {
|
|
||||||
|
|
||||||
let u = await Users.findOne({ where: { discord_id: user.id } })
|
|
||||||
.catch((err) => {
|
|
||||||
console.log(err);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (u) return u;
|
|
||||||
|
|
||||||
await Users.create({ discord_id: user.id, username: user.username })
|
|
||||||
.then((data) => {
|
|
||||||
u = data;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.log(err);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (u) return u;
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function checkGameStorage(game) {
|
|
||||||
let g = await Games.findOne({ where: { igdb_id: game.id, name: game.name } })
|
|
||||||
.catch((err) => {
|
|
||||||
console.log(err);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (g) return g;
|
|
||||||
|
|
||||||
await Games.create({ igdb_id: game.id, name: game.name })
|
|
||||||
.then((data) => {
|
|
||||||
g = data;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.log(err);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (g) return g;
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function createBeatenGameEntry(user, game) {
|
|
||||||
let bg = await BeatenGames.findOne({ where: { userId: user.id, gameId: game.id } })
|
|
||||||
.catch((err) => {
|
|
||||||
console.log(err);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (bg) return false;
|
|
||||||
|
|
||||||
await BeatenGames.create({ userId: user.id, gameId: game.id })
|
|
||||||
.then((data) => {
|
|
||||||
bg = data;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.log(err);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (bg) return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getBeatenGameCount(user) {
|
|
||||||
const u = await Users.findOne({ where: { id: user.id } })
|
|
||||||
.catch((err) => {
|
|
||||||
console.log(err);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!u) return -1;
|
|
||||||
|
|
||||||
const count = await u.countBeatenGames();
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
checkUserRegistration,
|
checkUserRegistration,
|
||||||
getUserRegistration,
|
|
||||||
checkGameStorage,
|
|
||||||
createBeatenGameEntry,
|
|
||||||
getBeatenGameCount,
|
|
||||||
};
|
};
|
Loading…
Reference in New Issue