Compare commits
	
		
			2 Commits
		
	
	
		
			3b86e362b5
			...
			328baba353
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 328baba353 | |||
| e5e6147d60 | 
							
								
								
									
										49
									
								
								commands/100-games/estimatedfinishdate.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								commands/100-games/estimatedfinishdate.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,49 @@
 | 
			
		||||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
 | 
			
		||||
const { getUserRegistration, getBeatenGames } = require('../../databaseHelperFunctions.js');
 | 
			
		||||
 | 
			
		||||
module.exports = {
 | 
			
		||||
    data: new SlashCommandBuilder()
 | 
			
		||||
    .setName('estimatedfinishdate')
 | 
			
		||||
    .setDescription('Get an estimated date as to when a user will finish the 100 games challenge.')
 | 
			
		||||
    .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 beatenGamesDatabaseEntries = await getBeatenGames(userDatabaseEntry.id);
 | 
			
		||||
        let desc = '';
 | 
			
		||||
 | 
			
		||||
        if (!beatenGamesDatabaseEntries || beatenGamesDatabaseEntries.length == 0) {
 | 
			
		||||
            desc = `${user.displayName} has not beaten any games yet.`;
 | 
			
		||||
        } else {
 | 
			
		||||
            const today = new Date();
 | 
			
		||||
            const start = new Date(2024, 1, 1);
 | 
			
		||||
            const days = (today - start) / (1000 * 3600 * 24);
 | 
			
		||||
            const timepergame = days / beatenGamesDatabaseEntries.length;
 | 
			
		||||
            const finishdate = new Date();
 | 
			
		||||
            finishdate.setDate(start.getDate() + (timepergame * 100));
 | 
			
		||||
            const formatteddate = finishdate.toLocaleDateString('en-GB', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '/');
 | 
			
		||||
            desc = `${user.displayName} is estimated to finish the 100 Games Challenge on **${formatteddate}**.`;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        const embed = new EmbedBuilder()
 | 
			
		||||
        .setColor(0x6441a5)
 | 
			
		||||
        .setAuthor({ name: `${user.displayName}`, iconURL: user.avatarURL() })
 | 
			
		||||
        .setThumbnail(user.avatarURL())
 | 
			
		||||
        .setTitle(`${user.displayName}'s Estimated Finish Date`)
 | 
			
		||||
        .setDescription(desc)
 | 
			
		||||
        .setFooter({ text: 'The Ochulus • 100 Games Challenge', iconURL: interaction.client.user.avatarURL() })
 | 
			
		||||
        .setTimestamp();
 | 
			
		||||
 | 
			
		||||
        return interaction.followUp({ embeds: [embed] });
 | 
			
		||||
    },
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										41
									
								
								commands/100-games/globalbeatlist.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								commands/100-games/globalbeatlist.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,41 @@
 | 
			
		||||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
 | 
			
		||||
const { getAllBeatenGames, checkGameStorageId, getUserFromId } = require('../../databaseHelperFunctions.js');
 | 
			
		||||
const { getGameJson } = require('../../igdbHelperFunctions.js');
 | 
			
		||||
 | 
			
		||||
module.exports = {
 | 
			
		||||
    data: new SlashCommandBuilder()
 | 
			
		||||
    .setName('globalbeatlist')
 | 
			
		||||
    .setDescription('Show a list of all games beaten for the 100 games challenge in chronological order.'),
 | 
			
		||||
    async execute(interaction) {
 | 
			
		||||
        await interaction.reply({ content: 'Searching for games...', ephemeral: true });
 | 
			
		||||
 | 
			
		||||
        const user = interaction.user;
 | 
			
		||||
 | 
			
		||||
        const beatenGamesDatabaseEntries = await getAllBeatenGames();
 | 
			
		||||
        let desc = '';
 | 
			
		||||
 | 
			
		||||
        if (!beatenGamesDatabaseEntries || beatenGamesDatabaseEntries.length == 0) {
 | 
			
		||||
            desc = 'No games beaten yet.';
 | 
			
		||||
        } else {
 | 
			
		||||
            for (let i = 0; i < beatenGamesDatabaseEntries.length; i++) {
 | 
			
		||||
                const gameid = await checkGameStorageId(beatenGamesDatabaseEntries[i].gameId);
 | 
			
		||||
                const res = await getGameJson(`where id = ${ gameid.igdb_id }; fields *;`);
 | 
			
		||||
                const game = res[0];
 | 
			
		||||
                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, '/');
 | 
			
		||||
                desc = desc.concat('**', date, '**: \t', game.name, ' \t*(', userentry.username, ')*\n');
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        const embed = new EmbedBuilder()
 | 
			
		||||
        .setColor(0x6441a5)
 | 
			
		||||
        .setAuthor({ name: `${user.displayName}`, iconURL: user.avatarURL() })
 | 
			
		||||
        .setThumbnail(interaction.client.user.avatarURL())
 | 
			
		||||
        .setTitle('Global Beat List')
 | 
			
		||||
        .setDescription(desc)
 | 
			
		||||
        .setFooter({ text: 'The Ochulus • 100 Games Challenge', iconURL: interaction.client.user.avatarURL() })
 | 
			
		||||
        .setTimestamp();
 | 
			
		||||
 | 
			
		||||
        return interaction.followUp({ embeds: [embed] });
 | 
			
		||||
    },
 | 
			
		||||
};
 | 
			
		||||
@ -35,6 +35,17 @@ async function getUserRegistration(user) {
 | 
			
		||||
    return null;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function getUserFromId(id) {
 | 
			
		||||
    const u = await Users.findOne({ where: { id: id } })
 | 
			
		||||
    .catch((err) => {
 | 
			
		||||
        console.log(err);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    if (u) return u;
 | 
			
		||||
 | 
			
		||||
    return null;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function checkGameStorage(game) {
 | 
			
		||||
    let g = await Games.findOne({ where: { igdb_id: game.id, name: game.name } })
 | 
			
		||||
    .catch((err) => {
 | 
			
		||||
@ -292,6 +303,17 @@ async function getGames(id, status) {
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function getAllBeatenGames() {
 | 
			
		||||
    const gameEntries = await LoggedGames.findAll({ where: { status: 'beat' }, order: [ [ 'updatedAt', 'ASC' ]] })
 | 
			
		||||
    .catch((err) => {
 | 
			
		||||
        console.log(err);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    if (gameEntries) return gameEntries;
 | 
			
		||||
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function backupDatabase() {
 | 
			
		||||
    const date = new Date().toJSON().slice(0, 10);
 | 
			
		||||
 | 
			
		||||
@ -306,6 +328,7 @@ async function backupDatabase() {
 | 
			
		||||
module.exports = {
 | 
			
		||||
    checkUserRegistration,
 | 
			
		||||
    getUserRegistration,
 | 
			
		||||
    getUserFromId,
 | 
			
		||||
    checkGameStorage,
 | 
			
		||||
    createPlanningGameEntry,
 | 
			
		||||
    createPlayingGameEntry,
 | 
			
		||||
@ -331,5 +354,6 @@ module.exports = {
 | 
			
		||||
    getPlayingGames,
 | 
			
		||||
    getBeatenGames,
 | 
			
		||||
    getGames,
 | 
			
		||||
    getAllBeatenGames,
 | 
			
		||||
    backupDatabase,
 | 
			
		||||
};
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user