Compare commits

..

No commits in common. "e1c12cd85283508c1b24e002e8ce395b3271a12b" and "a4024d01b568bb1222d7513109e504585251e14a" have entirely different histories.

11 changed files with 20 additions and 103 deletions

View File

@ -7,7 +7,6 @@ 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) {
@ -21,7 +20,6 @@ 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 });
@ -48,19 +46,7 @@ module.exports = {
const gameDatabaseEntry = await checkGameStorage(game); const gameDatabaseEntry = await checkGameStorage(game);
let gameDate = new Date(); await createBeatenGameEntry(userDatabaseEntry, gameDatabaseEntry);
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

@ -29,7 +29,7 @@ module.exports = {
for (let i = 0; i < beatenGamesDatabaseEntries.length; i++) { for (let i = 0; i < beatenGamesDatabaseEntries.length; i++) {
const game = await checkGameStorageId(beatenGamesDatabaseEntries[i].gameId); const game = await checkGameStorageId(beatenGamesDatabaseEntries[i].gameId);
const date = beatenGamesDatabaseEntries[i].statusLastChanged.toLocaleDateString('en-GB', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '/'); const date = beatenGamesDatabaseEntries[i].updatedAt.toLocaleDateString('en-GB', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '/');
desc = desc.concat('**#', (i + 1), ' (', date, ')**: ', game.name, '\n'); desc = desc.concat('**#', (i + 1), ' (', date, ')**: ', game.name, '\n');
} }
} }

View File

@ -29,7 +29,7 @@ module.exports = {
for (let i = 0; i < databaseEntries.length; i++) { for (let i = 0; i < databaseEntries.length; i++) {
const game = await checkGameStorageId(databaseEntries[i].gameId); const game = await checkGameStorageId(databaseEntries[i].gameId);
const date = databaseEntries[i].statusLastChanged.toLocaleDateString('en-GB', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '/'); const date = databaseEntries[i].updatedAt.toLocaleDateString('en-GB', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '/');
desc = desc.concat('**#', (i + 1), ' (', date, ')**: ', game.name, '\n'); desc = desc.concat('**#', (i + 1), ' (', date, ')**: ', game.name, '\n');
} }
} }

View File

@ -20,7 +20,7 @@ module.exports = {
for (let i = 0; i < beatenGamesDatabaseEntries.length; i++) { for (let i = 0; i < beatenGamesDatabaseEntries.length; i++) {
const game = await checkGameStorageId(beatenGamesDatabaseEntries[i].gameId); const game = await checkGameStorageId(beatenGamesDatabaseEntries[i].gameId);
const userentry = await getUserFromId(beatenGamesDatabaseEntries[i].userId); const userentry = await getUserFromId(beatenGamesDatabaseEntries[i].userId);
const date = beatenGamesDatabaseEntries[i].statusLastChanged.toLocaleDateString('en-GB', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '/'); const date = beatenGamesDatabaseEntries[i].updatedAt.toLocaleDateString('en-GB', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '/');
desc = desc.concat('**', date, '**: \t', game.name, ' \t*(', userentry.username, ')*\n'); desc = desc.concat('**', date, '**: \t', game.name, ' \t*(', userentry.username, ')*\n');
} }
} }

View File

@ -7,8 +7,7 @@ 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();
@ -18,7 +17,6 @@ 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 });
@ -42,19 +40,7 @@ module.exports = {
const game = res[0]; const game = res[0];
const gameDatabaseEntry = await checkGameStorage(game); const gameDatabaseEntry = await checkGameStorage(game);
let gameDate = new Date(); await createPlanningGameEntry(userDatabaseEntry, gameDatabaseEntry);
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,7 +7,6 @@ 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) {
@ -18,7 +17,6 @@ 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 });
@ -45,19 +43,7 @@ module.exports = {
const gameDatabaseEntry = await checkGameStorage(game); const gameDatabaseEntry = await checkGameStorage(game);
let gameDate = new Date(); await createPlayingGameEntry(userDatabaseEntry, gameDatabaseEntry);
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

@ -49,7 +49,7 @@ module.exports = {
embed.addFields({ name: 'Estimated Finish Date', value: `${date}`, inline: true }); embed.addFields({ name: 'Estimated Finish Date', value: `${date}`, inline: true });
} }
if (recentEntry) embed.addFields({ name: 'Last Updated', value: `${recentEntry.statusLastChanged.toLocaleDateString('en-GB', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '/')}`, inline: true }); if (recentEntry) embed.addFields({ name: 'Last Updated', value: `${recentEntry.updatedAt.toLocaleDateString('en-GB', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '/')}`, inline: true });
return interaction.editReply({ embeds: [embed] }); return interaction.editReply({ embeds: [embed] });
}, },

View File

@ -9,10 +9,11 @@ const { sequelize, LoggedGames } = require ('./dbObjects.js');
await sequelize.getQueryInterface().addColumn( await sequelize.getQueryInterface().addColumn(
'BeatenGames', 'BeatenGames',
'statusLastChanged', 'status',
{ {
type: DataTypes.DATE, type: DataTypes.ENUM('planning', 'playing', 'beat'),
allowNull: true, allowNull: false,
defaultValue: 'beat',
}, },
); );

View File

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

View File

@ -4,10 +4,6 @@ module.exports = (sequelize, DataTypes) => {
type: DataTypes.ENUM('planning', 'playing', 'beat'), type: DataTypes.ENUM('planning', 'playing', 'beat'),
allowNull: true, allowNull: true,
}, },
statusLastChanged: {
type: DataTypes.DATE,
allowNull: true,
},
}, { }, {
timestamps: true, timestamps: true,
}); });

View File

@ -1,17 +0,0 @@
const { LoggedGames } = require ('./dbObjects.js');
(async () => {
try {
const loggedGames = await LoggedGames.findAll();
for (const loggedGame of loggedGames) {
// Define your logic to populate newColumn based on existing data
loggedGame.statusLastChanged = loggedGame.updatedAt;
await loggedGame.save();
}
console.log('New column populated successfully');
} catch (error) {
console.error('Error populating new column:', error);
}
})();