diff --git a/backend/src/plugins/ReactionRoles/commands/PostButtonRolesCmd.ts b/backend/src/plugins/ReactionRoles/commands/PostButtonRolesCmd.ts index 6dc4f2fd..6bd19017 100644 --- a/backend/src/plugins/ReactionRoles/commands/PostButtonRolesCmd.ts +++ b/backend/src/plugins/ReactionRoles/commands/PostButtonRolesCmd.ts @@ -1,8 +1,7 @@ import { reactionRolesCmd } from "../types"; import { commandTypeHelpers as ct } from "../../../commandTypes"; -import { MessageActionRow, MessageButton, MessageComponentInteraction, TextChannel } from "discord.js"; +import { MessageActionRow, MessageButton, TextChannel } from "discord.js"; import { sendErrorMessage, sendSuccessMessage } from "src/pluginUtils"; -import moment from "moment"; import { ButtonMenuActions } from "../util/buttonMenuActions"; export const PostButtonRolesCmd = reactionRolesCmd({ @@ -35,7 +34,6 @@ export const PostButtonRolesCmd = reactionRolesCmd({ for (const button of Object.values(group.default_buttons)) { let customId = ""; if ((await pluginData.guild.roles.fetch(button.role_or_menu)) != null) { - // TODO: Make universal, currently can only handle custom emoji and not default ones customId = `${args.button_group}::${ButtonMenuActions.GRANT_ROLE}::${button.role_or_menu}`; } else { customId = `${args.button_group}::${ButtonMenuActions.OPEN_MENU}::${button.role_or_menu}`; @@ -47,8 +45,10 @@ export const PostButtonRolesCmd = reactionRolesCmd({ .setType("BUTTON") .setCustomID(customId); - const emo = pluginData.client.emojis.resolve(button.emoji); - if (emo) btn.setEmoji(emo); + if (button.emoji) { + const emo = pluginData.client.emojis.resolve(button.emoji) ?? button.emoji; + btn.setEmoji(emo); + } buttons.push(btn); } diff --git a/backend/src/plugins/ReactionRoles/events/ButtonInteractionEvt.ts b/backend/src/plugins/ReactionRoles/events/ButtonInteractionEvt.ts index b37b89d8..51694c1f 100644 --- a/backend/src/plugins/ReactionRoles/events/ButtonInteractionEvt.ts +++ b/backend/src/plugins/ReactionRoles/events/ButtonInteractionEvt.ts @@ -1,5 +1,13 @@ -import { Interaction, MessageComponentInteraction, MessageComponentInteractionCollector } from "discord.js"; +import { + Interaction, + MessageActionRow, + MessageButton, + MessageComponentInteraction, + MessageComponentInteractionCollector, + TextChannel, +} from "discord.js"; import { LogType } from "src/data/LogType"; +import { logger } from "src/logger"; import { pluginInfo } from "src/plugins/Automod/info"; import { LogsPlugin } from "src/plugins/Logs/LogsPlugin"; import { reactionRolesEvt } from "../types"; @@ -57,21 +65,54 @@ export const ButtonInteractionEvt = reactionRolesEvt({ const member = await meta.pluginData.guild.members.fetch(int.user.id); if (member.roles.cache.has(role.id)) { await member.roles.remove(role, `Button Roles on message ${int.message.id}`); - await sendEphemeralReply(int, `You have removed the role <@&${role.id}>`); + await sendEphemeralReply(int, `Role **${role.name}** removed`); } else { await member.roles.add(role, `Button Roles on message ${int.message.id}`); - await sendEphemeralReply(int, `You have added the role <@&${role.id}>`); + await sendEphemeralReply(int, `Role **${role.name}** added`); } return; } - // TODO: Send ephemeral reply with buttons that are part of the selected menu if (action === ButtonMenuActions.OPEN_MENU) { - console.log("Disable TSLint error"); + const menuButtons: MessageButton[] = []; + for (const menuButton of Object.values(group.button_menus[roleOrMenu])) { + let customId = ""; + customId = `${groupName}::${ButtonMenuActions.GRANT_ROLE}::${menuButton.role}`; + + const btn = new MessageButton() + .setLabel(menuButton.label) + .setStyle("PRIMARY") + .setType("BUTTON") + .setCustomID(customId); + + if (menuButton.emoji) { + const emo = meta.pluginData.client.emojis.resolve(menuButton.emoji) ?? menuButton.emoji; + btn.setEmoji(emo); + } + menuButtons.push(btn); + } + + if (menuButtons.length === 0) { + await sendEphemeralReply(int, `A configuration error was encountered, please contact the Administrators!`); + meta.pluginData + .getPlugin(LogsPlugin) + .log( + LogType.BOT_ALERT, + `**A configuration error occured** on buttons for message ${int.message.id}, menu **${roleOrMenu}** not found in config`, + ); + return; + } + const row = new MessageActionRow().addComponents(menuButtons); + + int.reply({ content: `Click to add/remove a role`, components: [row], ephemeral: true, split: false }); + return; } - await sendEphemeralReply(int, split.join("\n")); // TODO: Remove debug output + logger.warn( + `Action ${action} on button ${int.customID} (Guild: ${int.guildID}, Channel: ${int.channelID}) is unknown!`, + ); + await sendEphemeralReply(int, `A internal error was encountered, please contact the Administrators!`); }, });