Compare commits

...

6 Commits

Author SHA1 Message Date
baz 95c52b7ad5 Update embed colours 2024-02-11 21:06:43 +00:00
baz bcee95b612 Create plannedgames command 2024-02-11 21:05:24 +00:00
baz c7ce9b0220 Create currentlyplaying command 2024-02-11 21:05:15 +00:00
baz 31e599533a Update beatlist to new helperfunctions 2024-02-11 21:05:07 +00:00
baz f2fb035859 Database Helper Functions updates 2024-02-11 21:04:55 +00:00
baz 72817556a6 Rename nowplaying to startplaying 2024-02-11 20:35:33 +00:00
6 changed files with 128 additions and 13 deletions

View File

@ -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 = '';

View File

@ -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] });
},
};

View File

@ -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}`)

View File

@ -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] });
},
};

View File

@ -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}`)

View File

@ -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,7 +88,9 @@ 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,
};