mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-16 14:11:50 +00:00
Expand button reactions functionality
This commit is contained in:
parent
7c757d4b96
commit
a94e7593ec
2 changed files with 52 additions and 11 deletions
|
@ -1,8 +1,7 @@
|
||||||
import { reactionRolesCmd } from "../types";
|
import { reactionRolesCmd } from "../types";
|
||||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
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 { sendErrorMessage, sendSuccessMessage } from "src/pluginUtils";
|
||||||
import moment from "moment";
|
|
||||||
import { ButtonMenuActions } from "../util/buttonMenuActions";
|
import { ButtonMenuActions } from "../util/buttonMenuActions";
|
||||||
|
|
||||||
export const PostButtonRolesCmd = reactionRolesCmd({
|
export const PostButtonRolesCmd = reactionRolesCmd({
|
||||||
|
@ -35,7 +34,6 @@ export const PostButtonRolesCmd = reactionRolesCmd({
|
||||||
for (const button of Object.values(group.default_buttons)) {
|
for (const button of Object.values(group.default_buttons)) {
|
||||||
let customId = "";
|
let customId = "";
|
||||||
if ((await pluginData.guild.roles.fetch(button.role_or_menu)) != null) {
|
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}`;
|
customId = `${args.button_group}::${ButtonMenuActions.GRANT_ROLE}::${button.role_or_menu}`;
|
||||||
} else {
|
} else {
|
||||||
customId = `${args.button_group}::${ButtonMenuActions.OPEN_MENU}::${button.role_or_menu}`;
|
customId = `${args.button_group}::${ButtonMenuActions.OPEN_MENU}::${button.role_or_menu}`;
|
||||||
|
@ -47,8 +45,10 @@ export const PostButtonRolesCmd = reactionRolesCmd({
|
||||||
.setType("BUTTON")
|
.setType("BUTTON")
|
||||||
.setCustomID(customId);
|
.setCustomID(customId);
|
||||||
|
|
||||||
const emo = pluginData.client.emojis.resolve(button.emoji);
|
if (button.emoji) {
|
||||||
if (emo) btn.setEmoji(emo);
|
const emo = pluginData.client.emojis.resolve(button.emoji) ?? button.emoji;
|
||||||
|
btn.setEmoji(emo);
|
||||||
|
}
|
||||||
|
|
||||||
buttons.push(btn);
|
buttons.push(btn);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 { LogType } from "src/data/LogType";
|
||||||
|
import { logger } from "src/logger";
|
||||||
import { pluginInfo } from "src/plugins/Automod/info";
|
import { pluginInfo } from "src/plugins/Automod/info";
|
||||||
import { LogsPlugin } from "src/plugins/Logs/LogsPlugin";
|
import { LogsPlugin } from "src/plugins/Logs/LogsPlugin";
|
||||||
import { reactionRolesEvt } from "../types";
|
import { reactionRolesEvt } from "../types";
|
||||||
|
@ -57,21 +65,54 @@ export const ButtonInteractionEvt = reactionRolesEvt({
|
||||||
const member = await meta.pluginData.guild.members.fetch(int.user.id);
|
const member = await meta.pluginData.guild.members.fetch(int.user.id);
|
||||||
if (member.roles.cache.has(role.id)) {
|
if (member.roles.cache.has(role.id)) {
|
||||||
await member.roles.remove(role, `Button Roles on message ${int.message.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 {
|
} else {
|
||||||
await member.roles.add(role, `Button Roles on message ${int.message.id}`);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Send ephemeral reply with buttons that are part of the selected menu
|
|
||||||
if (action === ButtonMenuActions.OPEN_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!`);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue