Add date field to plangame, startplaying, beatgame commands

This commit is contained in:
baz 2024-07-13 17:10:13 +01:00
parent cc52a3fdcc
commit e1c12cd852
4 changed files with 51 additions and 9 deletions

View File

@ -7,6 +7,7 @@ module.exports = {
.setName('beatgame') .setName('beatgame')
.setDescription('Log a game that you have beat towards the 100 game challenge!') .setDescription('Log a game that you have beat towards the 100 game challenge!')
.addStringOption(option => option.setName('gamename').setDescription('The name of the game.').setRequired(true)) .addStringOption(option => option.setName('gamename').setDescription('The name of the game.').setRequired(true))
.addStringOption(option => option.setName('date').setDescription('The date to be logged. (YYYY/MM/DD)'))
.addNumberOption(option => option.setName('gameid').setDescription('The IGDB game id.').setMinValue(0)), .addNumberOption(option => option.setName('gameid').setDescription('The IGDB game id.').setMinValue(0)),
async execute(interaction) { async execute(interaction) {
@ -20,6 +21,7 @@ module.exports = {
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 date = interaction.options.getString('date');
if (!gamename && !gameid) return interaction.editReply({ content: 'No gamename or gameid supplied, please supply an option to register a game!', ephemeral: true }); if (!gamename && !gameid) return interaction.editReply({ content: 'No gamename or gameid supplied, please supply an option to register a game!', ephemeral: true });
@ -46,7 +48,19 @@ module.exports = {
const gameDatabaseEntry = await checkGameStorage(game); const gameDatabaseEntry = await checkGameStorage(game);
await createBeatenGameEntry(userDatabaseEntry, gameDatabaseEntry); let gameDate = new Date();
if (date) {
const parsedDate = new Date(date);
if (!isNaN(parsedDate.getTime())) {
gameDate = parsedDate;
}
else {
gameDate = new Date();
}
}
await createBeatenGameEntry(userDatabaseEntry, gameDatabaseEntry, gameDate);
const beatNum = await getBeatenGameCount(userDatabaseEntry); const beatNum = await getBeatenGameCount(userDatabaseEntry);
const planNum = await getPlanningGameCount(userDatabaseEntry); const planNum = await getPlanningGameCount(userDatabaseEntry);

View File

@ -7,7 +7,8 @@ module.exports = {
.setName('plangame') .setName('plangame')
.setDescription('Log a game that you plan beat towards the 100 game challenge!') .setDescription('Log a game that you plan beat towards the 100 game challenge!')
.addStringOption(option => option.setName('gamename').setDescription('The name of the game.').setRequired(true)) .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)), .addNumberOption(option => option.setName('gameid').setDescription('The IGDB game id.').setMinValue(0))
.addStringOption(option => option.setName('date').setDescription('The date to be logged. (YYYY/MM/DD)')),
async execute(interaction) { async execute(interaction) {
await interaction.deferReply(); await interaction.deferReply();
@ -17,6 +18,7 @@ module.exports = {
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 date = interaction.options.getString('date');
if (!gamename && !gameid) return interaction.editReply({ content: 'No gamename or gameid supplied, please supply an option to register a game!', ephemeral: true }); if (!gamename && !gameid) return interaction.editReply({ content: 'No gamename or gameid supplied, please supply an option to register a game!', ephemeral: true });
@ -40,7 +42,19 @@ module.exports = {
const game = res[0]; const game = res[0];
const gameDatabaseEntry = await checkGameStorage(game); const gameDatabaseEntry = await checkGameStorage(game);
await createPlanningGameEntry(userDatabaseEntry, gameDatabaseEntry); let gameDate = new Date();
if (date) {
const parsedDate = new Date(date);
if (!isNaN(parsedDate.getTime())) {
gameDate = parsedDate;
}
else {
gameDate = new Date();
}
}
await createPlanningGameEntry(userDatabaseEntry, gameDatabaseEntry, gameDate);
const beatNum = await getBeatenGameCount(userDatabaseEntry); const beatNum = await getBeatenGameCount(userDatabaseEntry);
const planNum = await getPlanningGameCount(userDatabaseEntry); const planNum = await getPlanningGameCount(userDatabaseEntry);

View File

@ -7,6 +7,7 @@ module.exports = {
.setName('startplaying') .setName('startplaying')
.setDescription('Log a game that you have started playing towards the 100 game challenge!') .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)) .addStringOption(option => option.setName('gamename').setDescription('The name of the game.').setRequired(true))
.addStringOption(option => option.setName('date').setDescription('The date to be logged. (YYYY/MM/DD)'))
.addNumberOption(option => option.setName('gameid').setDescription('The IGDB game id.').setMinValue(0)), .addNumberOption(option => option.setName('gameid').setDescription('The IGDB game id.').setMinValue(0)),
async execute(interaction) { async execute(interaction) {
@ -17,6 +18,7 @@ module.exports = {
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 date = interaction.options.getString('date');
if (!gamename && !gameid) return interaction.editReply({ content: 'No gamename or gameid supplied, please supply an option to register a game!', ephemeral: true }); if (!gamename && !gameid) return interaction.editReply({ content: 'No gamename or gameid supplied, please supply an option to register a game!', ephemeral: true });
@ -43,7 +45,19 @@ module.exports = {
const gameDatabaseEntry = await checkGameStorage(game); const gameDatabaseEntry = await checkGameStorage(game);
await createPlayingGameEntry(userDatabaseEntry, gameDatabaseEntry); let gameDate = new Date();
if (date) {
const parsedDate = new Date(date);
if (!isNaN(parsedDate.getTime())) {
gameDate = parsedDate;
}
else {
gameDate = new Date();
}
}
await createPlayingGameEntry(userDatabaseEntry, gameDatabaseEntry, gameDate);
const beatNum = await getBeatenGameCount(userDatabaseEntry); const beatNum = await getBeatenGameCount(userDatabaseEntry);
const planNum = await getPlanningGameCount(userDatabaseEntry); const planNum = await getPlanningGameCount(userDatabaseEntry);

View File

@ -81,7 +81,7 @@ async function checkGameStorageId(id) {
async function createPlanningGameEntry(user, game, date) { async function createPlanningGameEntry(user, game, date) {
const entry = await checkLoggedGameEntry(user, game); const entry = await checkLoggedGameEntry(user, game);
if (!entry) return await createLoggedGameEntry(user, game, 'planning'); if (!entry) return await createLoggedGameEntry(user, game, 'planning', date);
if (entry.status == 'planning') return false; if (entry.status == 'planning') return false;
@ -102,7 +102,7 @@ async function createPlanningGameEntry(user, game, date) {
async function createPlayingGameEntry(user, game, date) { async function createPlayingGameEntry(user, game, date) {
const entry = await checkLoggedGameEntry(user, game); const entry = await checkLoggedGameEntry(user, game);
if (!entry) return await createLoggedGameEntry(user, game, 'playing'); if (!entry) return await createLoggedGameEntry(user, game, 'playing', date);
if (entry.status == 'playing') return false; if (entry.status == 'playing') return false;
@ -123,7 +123,7 @@ async function createPlayingGameEntry(user, game, date) {
async function createBeatenGameEntry(user, game, date) { async function createBeatenGameEntry(user, game, date) {
const entry = await checkLoggedGameEntry(user, game); const entry = await checkLoggedGameEntry(user, game);
if (!entry) return await createLoggedGameEntry(user, game, 'beat'); if (!entry) return await createLoggedGameEntry(user, game, 'beat', date);
if (entry.status == 'beat') return false; if (entry.status == 'beat') return false;
@ -152,10 +152,10 @@ async function checkLoggedGameEntry(user, game) {
return bg; return bg;
} }
async function createLoggedGameEntry(user, game, status) { async function createLoggedGameEntry(user, game, status, date) {
let bg; let bg;
await LoggedGames.create({ userId: user.id, gameId: game.id, status: status, statusLastChanged: new Date() }) await LoggedGames.create({ userId: user.id, gameId: game.id, status: status, statusLastChanged: date })
.then((data) => { .then((data) => {
bg = data; bg = data;
}) })