diff --git a/src/commands/score.ts b/src/commands/score.ts new file mode 100644 index 0000000..c8f3db1 --- /dev/null +++ b/src/commands/score.ts @@ -0,0 +1,40 @@ +import { SlashCommandBuilder } from '@discordjs/builders'; +import { MessageEmbed } from 'discord.js'; + +import log from '../helpers/log'; +import userScore from '../models/userScore'; + +export const data = new SlashCommandBuilder() + .setName('score') + .setDescription('Returns the score of the current user or another') + .addUserOption(option => { + option + .setName('user') + .setDescription('The user to find the score for') + .setRequired(false); + + return option; + }); + +export async function execute(interaction) { + const scoreEmbed = new MessageEmbed() + .setColor('#ffffff'); + + const user = interaction.options.getUser('user') || interaction.user; + userScore.findOne({ authorID: user.id }, async (err, score) => { + if (err) { + log({ logger: 'db', content: `Unable to obtain user: ${err}`, level: 'info' }); + } + + if (!score) { + await interaction.reply({ content: 'Unfortunately, that user does not seem to have used AwesomeSciBo yet.', ephemeral: true }); + return; + } + + scoreEmbed + .setAuthor({ name: user.tag, iconURL: user.displayAvatarURL(true) }) + .setDescription(`Score: \`${score.score}\``); + + await interaction.reply({ embeds: [scoreEmbed] }); + }); +}