Compare commits

...

3 Commits

11 changed files with 103 additions and 20 deletions

View File

@ -7,6 +7,7 @@ module.exports = {
.setName('beatgame')
.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('date').setDescription('The date to be logged. (YYYY/MM/DD)'))
.addNumberOption(option => option.setName('gameid').setDescription('The IGDB game id.').setMinValue(0)),
async execute(interaction) {
@ -20,6 +21,7 @@ module.exports = {
const gamename = interaction.options.getString('gamename');
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 });
@ -46,7 +48,19 @@ module.exports = {
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 planNum = await getPlanningGameCount(userDatabaseEntry);

View File

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

View File

@ -7,7 +7,8 @@ module.exports = {
.setName('plangame')
.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))
.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) {
await interaction.deferReply();
@ -17,6 +18,7 @@ module.exports = {
const gamename = interaction.options.getString('gamename');
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 });
@ -40,7 +42,19 @@ module.exports = {
const game = res[0];
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 planNum = await getPlanningGameCount(userDatabaseEntry);

View File

@ -7,6 +7,7 @@ module.exports = {
.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))
.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)),
async execute(interaction) {
@ -17,6 +18,7 @@ module.exports = {
const gamename = interaction.options.getString('gamename');
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 });
@ -43,7 +45,19 @@ module.exports = {
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 planNum = await getPlanningGameCount(userDatabaseEntry);

View File

@ -49,7 +49,7 @@ module.exports = {
embed.addFields({ name: 'Estimated Finish Date', value: `${date}`, 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 });
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 });
return interaction.editReply({ embeds: [embed] });
},

View File

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

View File

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

View File

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

17
populateColumn.js Normal file
View File

@ -0,0 +1,17 @@
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);
}
})();