Compare commits
6 Commits
1098cfadaa
...
95c52b7ad5
Author | SHA1 | Date |
---|---|---|
baz | 95c52b7ad5 | |
baz | bcee95b612 | |
baz | c7ce9b0220 | |
baz | 31e599533a | |
baz | f2fb035859 | |
baz | 72817556a6 |
|
@ -1,5 +1,5 @@
|
|||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
||||
const { getUserRegistration, getGames, checkGameStorageId } = require('../../databaseHelperFunctions.js');
|
||||
const { getUserRegistration, getBeatenGames, checkGameStorageId } = require('../../databaseHelperFunctions.js');
|
||||
const { getGameJson } = require('../../igdbHelperFunctions.js');
|
||||
|
||||
module.exports = {
|
||||
|
@ -20,7 +20,7 @@ module.exports = {
|
|||
const userDatabaseEntry = await getUserRegistration(user);
|
||||
if (!userDatabaseEntry) return interaction.followUp({ content: `Issue checking registration with "${user.username}".`, ephemeral: true });
|
||||
|
||||
const beatenGamesDatabaseEntries = await getGames(userDatabaseEntry.id);
|
||||
const beatenGamesDatabaseEntries = await getBeatenGames(userDatabaseEntry.id);
|
||||
if (!beatenGamesDatabaseEntries || beatenGamesDatabaseEntries.length == 0) return interaction.followUp({ content: 'No games found.', ephemeral: true });
|
||||
|
||||
let desc = '';
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
||||
const { getUserRegistration, getPlayingGames, checkGameStorageId } = require('../../databaseHelperFunctions.js');
|
||||
const { getGameJson } = require('../../igdbHelperFunctions.js');
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('currentlyplaying')
|
||||
.setDescription('Show the list of games you are currently playing.')
|
||||
.addUserOption(option => option.setName('user').setDescription('The user to check')),
|
||||
async execute(interaction) {
|
||||
await interaction.reply({ content: 'Searching for user...', ephemeral: true });
|
||||
|
||||
let user = interaction.user;
|
||||
const userOption = interaction.options.getUser('user');
|
||||
|
||||
if (userOption) {
|
||||
user = userOption;
|
||||
}
|
||||
|
||||
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);
|
||||
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++) {
|
||||
const gameid = await checkGameStorageId(databaseEntries[i].gameId);
|
||||
const res = await getGameJson(`where id = ${ gameid.igdb_id }; fields *;`);
|
||||
const game = res[0];
|
||||
|
||||
desc = desc.concat('-\t', game.name, '\n');
|
||||
}
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(0x6441a5)
|
||||
.setAuthor({ name: `${user.displayName}`, iconURL: user.avatarURL() })
|
||||
.setTitle(`${user.displayName}'s currently playing games`)
|
||||
.setDescription(desc)
|
||||
.setFooter({ text: 'The Ochulus • 100 Games Challenge', iconURL: interaction.client.user.avatarURL() })
|
||||
.setTimestamp();
|
||||
|
||||
return interaction.followUp({ embeds: [embed] });
|
||||
},
|
||||
};
|
|
@ -49,7 +49,7 @@ module.exports = {
|
|||
const coverUrl = await getCoverURL(game.cover);
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(0xFFD700)
|
||||
.setColor(0x43ABEC)
|
||||
.setAuthor({ name: `${interaction.user.displayName} is planning to beat a game!`, iconURL: interaction.user.avatarURL() })
|
||||
.setTitle(`${game.name}!`)
|
||||
.setThumbnail(`${coverUrl}`)
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
||||
const { getUserRegistration, getPlanningGames, checkGameStorageId } = require('../../databaseHelperFunctions.js');
|
||||
const { getGameJson } = require('../../igdbHelperFunctions.js');
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('plannedgames')
|
||||
.setDescription('Show the list of games you are currently planning to play.')
|
||||
.addUserOption(option => option.setName('user').setDescription('The user to check')),
|
||||
async execute(interaction) {
|
||||
await interaction.reply({ content: 'Searching for user...', ephemeral: true });
|
||||
|
||||
let user = interaction.user;
|
||||
const userOption = interaction.options.getUser('user');
|
||||
|
||||
if (userOption) {
|
||||
user = userOption;
|
||||
}
|
||||
|
||||
const userDatabaseEntry = await getUserRegistration(user);
|
||||
if (!userDatabaseEntry) return interaction.followUp({ content: `Issue checking registration with "${user.username}".`, ephemeral: true });
|
||||
|
||||
const databaseEntries = await getPlanningGames(userDatabaseEntry.id);
|
||||
if (!databaseEntries || databaseEntries.length == 0) return interaction.followUp({ content: 'No games found.', ephemeral: true });
|
||||
|
||||
let desc = '';
|
||||
|
||||
for (let i = 0; i < databaseEntries.length; i++) {
|
||||
const gameid = await checkGameStorageId(databaseEntries[i].gameId);
|
||||
const res = await getGameJson(`where id = ${ gameid.igdb_id }; fields *;`);
|
||||
const game = res[0];
|
||||
|
||||
desc = desc.concat('-\t', game.name, '\n');
|
||||
}
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(0x6441a5)
|
||||
.setAuthor({ name: `${user.displayName}`, iconURL: user.avatarURL() })
|
||||
.setTitle(`${user.displayName}'s planned games to play`)
|
||||
.setDescription(desc)
|
||||
.setFooter({ text: 'The Ochulus • 100 Games Challenge', iconURL: interaction.client.user.avatarURL() })
|
||||
.setTimestamp();
|
||||
|
||||
return interaction.followUp({ embeds: [embed] });
|
||||
},
|
||||
};
|
|
@ -4,8 +4,8 @@ const { checkGameStorage, getUserRegistration, createPlayingGameEntry, getBeaten
|
|||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('nowplaying')
|
||||
.setDescription('Log a game that you are currently playing towards the 100 game challenge!')
|
||||
.setName('startplaying')
|
||||
.setDescription('Log a game that you have started playing towards the 100 game challenge!')
|
||||
.addStringOption(option => option.setName('gamename').setDescription('The name of the game.').setRequired(true))
|
||||
.addNumberOption(option => option.setName('gameid').setDescription('The IGDB game id.').setMinValue(0)),
|
||||
async execute(interaction) {
|
||||
|
@ -49,7 +49,7 @@ module.exports = {
|
|||
const coverUrl = await getCoverURL(game.cover);
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(0xFFD700)
|
||||
.setColor(0x00C921)
|
||||
.setAuthor({ name: `${interaction.user.displayName} has started playing a new game!`, iconURL: interaction.user.avatarURL() })
|
||||
.setTitle(`${game.name}!`)
|
||||
.setThumbnail(`${coverUrl}`)
|
|
@ -74,7 +74,9 @@ async function createPlanningGameEntry(user, game) {
|
|||
|
||||
if (entry.status == 'planning') return false;
|
||||
|
||||
entry.update({ status: 'planning' });
|
||||
entry.status = 'planning';
|
||||
|
||||
await entry.save();
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
@ -86,8 +88,10 @@ async function createPlayingGameEntry(user, game) {
|
|||
|
||||
if (entry.status == 'playing') return false;
|
||||
|
||||
entry.save({ status: 'playing' });
|
||||
entry.status = 'playing';
|
||||
|
||||
await entry.save();
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
|
@ -98,7 +102,9 @@ async function createBeatenGameEntry(user, game) {
|
|||
|
||||
if (entry.status == 'beat') return false;
|
||||
|
||||
entry.update({ status: 'beat' });
|
||||
entry.status = 'beat';
|
||||
|
||||
await entry.save();
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
@ -246,7 +252,7 @@ async function getRecentBeatenGameEntry(userId) {
|
|||
}
|
||||
|
||||
async function getRecentGameEntry(userId, status) {
|
||||
const beatenGameEntry = await LoggedGames.findOne({ where: { userId: userId, status: status }, order: [ [ 'createdAt', 'DESC' ]] })
|
||||
const beatenGameEntry = await LoggedGames.findOne({ where: { userId: userId, status: status }, order: [ [ 'updatedAt', 'ASC' ]] })
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
|
@ -263,13 +269,25 @@ async function getRecentGameEntry(userId, status) {
|
|||
return false;
|
||||
}
|
||||
|
||||
async function getGames(id) {
|
||||
const beatenGameEntry = await LoggedGames.findAll({ where: { userId: id, status: 'beat' } })
|
||||
async function getPlanningGames(id) {
|
||||
return await getGames(id, 'planning');
|
||||
}
|
||||
|
||||
async function getPlayingGames(id) {
|
||||
return await getGames(id, 'playing');
|
||||
}
|
||||
|
||||
async function getBeatenGames(id) {
|
||||
return await getGames(id, 'beat');
|
||||
}
|
||||
|
||||
async function getGames(id, status) {
|
||||
const gameEntries = await LoggedGames.findAll({ where: { userId: id, status: status }, order: [ [ 'updatedAt', 'ASC' ]] })
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
if (beatenGameEntry) return beatenGameEntry;
|
||||
if (gameEntries) return gameEntries;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -309,6 +327,9 @@ module.exports = {
|
|||
getRecentPlayingGameEntry,
|
||||
getRecentBeatenGameEntry,
|
||||
getRecentGameEntry,
|
||||
getPlanningGames,
|
||||
getPlayingGames,
|
||||
getBeatenGames,
|
||||
getGames,
|
||||
backupDatabase,
|
||||
};
|
Loading…
Reference in New Issue