TheOchulus/commands/100-games/currentlyplaying.js

47 lines
2.0 KiB
JavaScript
Raw Permalink Normal View History

2024-02-11 22:05:15 +01:00
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { getUserRegistration, getPlayingGames, checkGameStorageId } = require('../../databaseHelperFunctions.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.deferReply();
2024-02-11 22:05:15 +01:00
let user = interaction.user;
const userOption = interaction.options.getUser('user');
if (userOption) {
user = userOption;
}
const userDatabaseEntry = await getUserRegistration(user);
if (!userDatabaseEntry) return interaction.editReply({ content: `Issue checking registration with "${user.username}".`, ephemeral: true });
2024-02-11 22:05:15 +01:00
2024-02-11 22:17:21 +01:00
const databaseEntries = await getPlayingGames(userDatabaseEntry.id);
2024-02-11 22:05:15 +01:00
let desc = '';
if (!databaseEntries || databaseEntries.length == 0) {
desc = `${user.displayName} is currently playing no games.`;
} else {
2024-03-18 20:54:35 +01:00
desc = desc.concat('__Total: ', databaseEntries.length, '__\n');
2024-02-28 19:02:18 +01:00
for (let i = 0; i < databaseEntries.length; i++) {
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, '/');
2024-03-18 20:54:35 +01:00
desc = desc.concat('**#', (i + 1), ' (', date, ')**: ', game.name, '\n');
}
2024-02-11 22:05:15 +01:00
}
const embed = new EmbedBuilder()
.setColor(0x6441a5)
2024-02-28 19:02:18 +01:00
.setThumbnail(user.avatarURL())
.setTitle(`${user.displayName}'s Currently Playing Games`)
2024-02-11 22:05:15 +01:00
.setDescription(desc)
.setFooter({ text: 'The Ochulus • 100 Games Challenge', iconURL: interaction.client.user.avatarURL() })
.setTimestamp();
return interaction.editReply({ embeds: [embed] });
2024-02-11 22:05:15 +01:00
},
};