Compare commits
4 Commits
95c52b7ad5
...
3f0084d6e2
Author | SHA1 | Date |
---|---|---|
baz | 3f0084d6e2 | |
baz | cf58edccf5 | |
baz | e4bd9a33ae | |
baz | c31a3d6e04 |
|
@ -20,11 +20,9 @@ module.exports = {
|
|||
const userDatabaseEntry = await getUserRegistration(user);
|
||||
if (!userDatabaseEntry) return interaction.followUp({ content: `Issue checking registration with "${user.username}".`, ephemeral: true });
|
||||
|
||||
let databaseEntries = await getPlayingGames(userDatabaseEntry.id);
|
||||
const databaseEntries = await getPlayingGames(userDatabaseEntry.id);
|
||||
if (!databaseEntries || databaseEntries.length == 0) return interaction.followUp({ content: 'No games found.', ephemeral: true });
|
||||
|
||||
databaseEntries = databaseEntries.reverse();
|
||||
|
||||
let desc = '';
|
||||
|
||||
for (let i = 0; i < databaseEntries.length; i++) {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
||||
const { getUserRegistration, deleteBeatenGameNum, checkGameStorageId, getRecentBeatenGameEntry, deleteBeatenGameId, getBeatenGameCount } = require('../../databaseHelperFunctions.js');
|
||||
const { getUserRegistration, deleteBeatenGameNum, checkGameStorageId, getRecentBeatenGameEntry, deleteBeatenGameId, getBeatenGameCount, getPlanningGameCount, getPlayingGameCount } = require('../../databaseHelperFunctions.js');
|
||||
const { getCoverURL, getGameJson } = require('../../igdbHelperFunctions.js');
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('deletegame')
|
||||
.setName('deletebeatengame')
|
||||
.setDescription('Delete a game that you have beaten from the 100 game challenge!')
|
||||
.addNumberOption(option => option.setName('beatgamenumber').setDescription('Index of the game to delete in the list of beaten games.').setMinValue(1).setMaxValue(100)),
|
||||
async execute(interaction) {
|
||||
|
@ -30,7 +30,9 @@ module.exports = {
|
|||
if (!res) return interaction.followUp({ content: 'No game found.', ephemeral: true });
|
||||
const game = res[0];
|
||||
|
||||
const num = await getBeatenGameCount(userDatabaseEntry);
|
||||
const beatNum = await getBeatenGameCount(userDatabaseEntry);
|
||||
const planNum = await getPlanningGameCount(userDatabaseEntry);
|
||||
const playNum = await getPlayingGameCount(userDatabaseEntry);
|
||||
const coverUrl = await getCoverURL(game.cover);
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
|
@ -38,7 +40,7 @@ module.exports = {
|
|||
.setAuthor({ name: `${interaction.user.displayName} deleted a game!`, iconURL: interaction.user.avatarURL() })
|
||||
.setTitle(`${game.name} deleted!`)
|
||||
.setThumbnail(`${coverUrl}`)
|
||||
.setDescription(`${interaction.user.displayName} has beaten ${num} games, they have ${100 - num} games remaining.`)
|
||||
.setDescription(`${interaction.user.displayName} has ${planNum} games planned, they are playing ${playNum} games, they have beaten ${beatNum} games, they have ${100 - beatNum} games remaining.`)
|
||||
.setFooter({ text: 'The Ochulus • 100 Games Challenge', iconURL: interaction.client.user.avatarURL() })
|
||||
.setTimestamp();
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
||||
const { getUserRegistration, deletePlanningGameNum, checkGameStorageId, getRecentPlanningGameEntry, deletePlanningGameId, getPlayingGameCount, getBeatenGameCount, getPlanningGameCount } = require('../../databaseHelperFunctions.js');
|
||||
const { getCoverURL, getGameJson } = require('../../igdbHelperFunctions.js');
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('deleteplannedgame')
|
||||
.setDescription('Delete a game that you were planning to play!')
|
||||
.addNumberOption(option => option.setName('currentgamenumber').setDescription('Index of the game to delete in the list of planned games.').setMinValue(1)),
|
||||
async execute(interaction) {
|
||||
await interaction.reply({ content: 'Searching for user...', ephemeral: true });
|
||||
|
||||
const beatGameNumber = interaction.options.getNumber('currentgamenumber');
|
||||
|
||||
const userDatabaseEntry = await getUserRegistration(interaction.user);
|
||||
let result;
|
||||
|
||||
if (beatGameNumber) {
|
||||
result = await deletePlanningGameNum(beatGameNumber, userDatabaseEntry);
|
||||
}
|
||||
else {
|
||||
const recentGame = await getRecentPlanningGameEntry(userDatabaseEntry.id);
|
||||
result = await deletePlanningGameId(recentGame.id, userDatabaseEntry);
|
||||
}
|
||||
|
||||
if (result) {
|
||||
const gameDatabaseEntry = await checkGameStorageId(result.gameId);
|
||||
const body = `where id = ${ gameDatabaseEntry.igdb_id }; fields *;`;
|
||||
const res = await getGameJson(body);
|
||||
if (!res) return interaction.followUp({ content: 'No game found.', ephemeral: true });
|
||||
const game = res[0];
|
||||
|
||||
const beatNum = await getBeatenGameCount(userDatabaseEntry);
|
||||
const planNum = await getPlanningGameCount(userDatabaseEntry);
|
||||
const playNum = await getPlayingGameCount(userDatabaseEntry);
|
||||
const coverUrl = await getCoverURL(game.cover);
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(0xFF0000)
|
||||
.setAuthor({ name: `${interaction.user.displayName} deleted a game!`, iconURL: interaction.user.avatarURL() })
|
||||
.setTitle(`${game.name} deleted!`)
|
||||
.setThumbnail(`${coverUrl}`)
|
||||
.setDescription(`${interaction.user.displayName} has ${planNum} games planned, they are playing ${playNum} games, they have beaten ${beatNum} games, they have ${100 - beatNum} games remaining.`)
|
||||
.setFooter({ text: 'The Ochulus • 100 Games Challenge', iconURL: interaction.client.user.avatarURL() })
|
||||
.setTimestamp();
|
||||
|
||||
return interaction.followUp({ embeds: [embed] });
|
||||
}
|
||||
|
||||
return interaction.followUp({ content: 'Unable to delete entry / No entry found.', ephemeral: true });
|
||||
},
|
||||
};
|
|
@ -0,0 +1,52 @@
|
|||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
||||
const { getUserRegistration, deletePlayingGameNum, checkGameStorageId, getRecentPlayingGameEntry, deletePlayingGameId, getPlayingGameCount, getBeatenGameCount, getPlanningGameCount } = require('../../databaseHelperFunctions.js');
|
||||
const { getCoverURL, getGameJson } = require('../../igdbHelperFunctions.js');
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('deleteplayinggame')
|
||||
.setDescription('Delete a game that you was playing!')
|
||||
.addNumberOption(option => option.setName('currentgamenumber').setDescription('Index of the game to delete in the list of currently playing games.').setMinValue(1)),
|
||||
async execute(interaction) {
|
||||
await interaction.reply({ content: 'Searching for user...', ephemeral: true });
|
||||
|
||||
const beatGameNumber = interaction.options.getNumber('currentgamenumber');
|
||||
|
||||
const userDatabaseEntry = await getUserRegistration(interaction.user);
|
||||
let result;
|
||||
|
||||
if (beatGameNumber) {
|
||||
result = await deletePlayingGameNum(beatGameNumber, userDatabaseEntry);
|
||||
}
|
||||
else {
|
||||
const recentGame = await getRecentPlayingGameEntry(userDatabaseEntry.id);
|
||||
result = await deletePlayingGameId(recentGame.id, userDatabaseEntry);
|
||||
}
|
||||
|
||||
if (result) {
|
||||
const gameDatabaseEntry = await checkGameStorageId(result.gameId);
|
||||
const body = `where id = ${ gameDatabaseEntry.igdb_id }; fields *;`;
|
||||
const res = await getGameJson(body);
|
||||
if (!res) return interaction.followUp({ content: 'No game found.', ephemeral: true });
|
||||
const game = res[0];
|
||||
|
||||
const beatNum = await getBeatenGameCount(userDatabaseEntry);
|
||||
const planNum = await getPlanningGameCount(userDatabaseEntry);
|
||||
const playNum = await getPlayingGameCount(userDatabaseEntry);
|
||||
const coverUrl = await getCoverURL(game.cover);
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(0xFF0000)
|
||||
.setAuthor({ name: `${interaction.user.displayName} deleted a game!`, iconURL: interaction.user.avatarURL() })
|
||||
.setTitle(`${game.name} deleted!`)
|
||||
.setThumbnail(`${coverUrl}`)
|
||||
.setDescription(`${interaction.user.displayName} has ${planNum} games planned, they are playing ${playNum} games, they have beaten ${beatNum} games, they have ${100 - beatNum} games remaining.`)
|
||||
.setFooter({ text: 'The Ochulus • 100 Games Challenge', iconURL: interaction.client.user.avatarURL() })
|
||||
.setTimestamp();
|
||||
|
||||
return interaction.followUp({ embeds: [embed] });
|
||||
}
|
||||
|
||||
return interaction.followUp({ content: 'Unable to delete entry / No entry found.', ephemeral: true });
|
||||
},
|
||||
};
|
|
@ -91,7 +91,7 @@ async function createPlayingGameEntry(user, game) {
|
|||
entry.status = 'playing';
|
||||
|
||||
await entry.save();
|
||||
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
|
@ -252,7 +252,7 @@ async function getRecentBeatenGameEntry(userId) {
|
|||
}
|
||||
|
||||
async function getRecentGameEntry(userId, status) {
|
||||
const beatenGameEntry = await LoggedGames.findOne({ where: { userId: userId, status: status }, order: [ [ 'updatedAt', 'ASC' ]] })
|
||||
const beatenGameEntry = await LoggedGames.findOne({ where: { userId: userId, status: status }, order: [ [ 'updatedAt', 'DESC' ]] })
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue