From 1ea5c016b4c6fa321f32eefe752637c0876298ca Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Tue, 29 Mar 2022 22:33:00 -0500 Subject: [PATCH] Add feature for checking scores --- src/commands/score.ts | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/commands/score.ts 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] }); + }); +}