aboutsummaryrefslogtreecommitdiff
path: root/bot/src/commands/suggest.js
blob: b8fe68a30974cbe6e0f9ea272fc1d0fc60f477aa (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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import {
    ActionRowBuilder,
    MessageFlags,
    ModalBuilder,
    SlashCommandBuilder,
    TextInputBuilder,
    TextInputStyle,
    EmbedBuilder
} from 'discord.js';
import { abEmbedColour, featureSuggestChannel } from '../storage/consts.js';
import { guildSettings } from '../models/guild-settings.js';

export default {
    data: new SlashCommandBuilder()
        .setName('suggest')
        .setDescription('Suggest something either for AleeBot or this server.')
        .addSubcommand(subcommand =>
            subcommand
                .setName('feature')
                .setDescription('Suggest a feature in AleeBot.'))
        .addSubcommand(subcommand =>
            subcommand
                .setName('guild')
                .setDescription('Suggest something for this server.')),
    async execute(interaction) {
        if (interaction.options.getSubcommand() === 'feature') {
            const modal = new ModalBuilder()
                .setCustomId(`suggest-${interaction.user.id}`)
                .setTitle('Suggest a feature for AleeBot');

            const featureText = new TextInputBuilder()
                .setCustomId('feature')
                .setLabel('Suggest the feature you want')
                .setMaxLength(200)
                .setPlaceholder('Feature')
                .setStyle(TextInputStyle.Paragraph);

            const firstActionRow = new ActionRowBuilder().addComponents(featureText);

            modal.addComponents(firstActionRow);

            await interaction.showModal(modal);

            const filter = (interaction) => interaction.customId === `suggest-${interaction.user.id}`;

            interaction.awaitModalSubmit({ filter, time: 1000 * 1200 })
                .then(async (modalInteraction) => {
                    const feature = modalInteraction.fields.getTextInputValue('feature');

                    modalInteraction.client.channels.cache.get(featureSuggestChannel).send({ embeds: [
                        new EmbedBuilder()
                            .setTitle('AleeBot Feature Suggestion')
                            .setDescription(`This is an AleeBot feature suggested from ${modalInteraction.user.username}.`)
                            .addFields({ name: 'Suggestion Content', value: feature })
                            .setColor(abEmbedColour)
                            .setFooter({ text: `Sending from ${modalInteraction.guild.name}`, iconURL: modalInteraction.guild.iconURL() })
                    ]});

                    return await modalInteraction.reply({content: 'Your suggestion has been sent.', flags: MessageFlags.Ephemeral});
                })
                .catch((err) => {
                    console.error(err);
                });

        }

        if (interaction.options.getSubcommand() === 'guild') {
            if (!interaction.guild) return await interaction.reply({ content: 'This command can only be run in a guild.' });
            const guildSetting = await guildSettings.findOne({ where: { guildID: interaction.guild.id } });
            if (!guildSetting || !guildSetting.suggestionsChannelID) return await interaction.reply({ content: 'This server did not configure to have suggestions enabled.' });

            const modal = new ModalBuilder()
                .setCustomId(`suggest-${interaction.user.id}`)
                .setTitle(`Suggestion for ${interaction.guild.name}`);

            const featureText = new TextInputBuilder()
                .setCustomId('feature')
                .setLabel('Suggestion')
                .setMaxLength(200)
                .setPlaceholder('Feature')
                .setStyle(TextInputStyle.Paragraph);

            const firstActionRow = new ActionRowBuilder().addComponents(featureText);

            modal.addComponents(firstActionRow);

            await interaction.showModal(modal);

            const filter = (interaction) => interaction.customId === `suggest-${interaction.user.id}`;

            interaction.awaitModalSubmit({ filter, time: 1000 * 1200 })
                .then(async (modalInteraction) => {
                    const feature = modalInteraction.fields.getTextInputValue('feature');

                    modalInteraction.client.channels.cache.get(guildSetting.suggestionsChannelID).send({ embeds: [
                        new EmbedBuilder()
                            .setTitle('Suggestion')
                            .setDescription(`This is a suggestion from ${interaction.user.username}.`)
                            .addFields({ name: 'Suggestion Content', value: feature })
                            .setColor(abEmbedColour)
                    ]});

                    return await modalInteraction.reply({content: 'Your suggestion has been sent.', flags: MessageFlags.Ephemeral});
                })
                .catch((err) => {
                    console.error(err);
                });

        }
    }
};