aboutsummaryrefslogtreecommitdiff
path: root/bot/src/commands/stats.js
blob: 950438688b6d0e04aca319e79e0c8bc27600d7af (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import { commandUsages } from '../models/command-usages.js';
import { abEmbedColour } from '../storage/consts.js';

export default {
    data: new SlashCommandBuilder()
        .setName('stats')
        .setDescription('Shows how many times you executed a command.'),
    async execute(interaction) {
        let cmdUsage = await commandUsages.findAll({ where: { userID: interaction.user.id } });
        const totalCommands = cmdUsage.length;
        const guildCommands = cmdUsage.filter(cmd => cmd.guildID === interaction.guild.id).length;

        const statsEmbed = new EmbedBuilder()
            .setAuthor({ name: `Stats for ${interaction.user.username}`, iconURL: interaction.client.user.avatarURL() })
            .addFields(
                { name: 'Total Commands Executed', value: totalCommands.toString() },
                { name: 'Total Commands Executed in this Guild', value: guildCommands.toString() }
            )
            .setColor(abEmbedColour);

        return await interaction.reply({ embeds: [statsEmbed] });
    }
};