mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
Button role improvements, proper validation
This commit is contained in:
parent
7bf5e1f3c6
commit
653d6c1dc2
5 changed files with 166 additions and 19 deletions
|
@ -4,6 +4,7 @@ import { LogType } from "../../../data/LogType";
|
|||
import { LogsPlugin } from "../../../plugins/Logs/LogsPlugin";
|
||||
import { ReactionRolesPluginType, TButtonPairOpts } from "../types";
|
||||
import { generateStatelessCustomId } from "./buttonCustomIdFunctions";
|
||||
import { splitButtonsIntoRows } from "./splitButtonsIntoRows";
|
||||
|
||||
export async function handleOpenMenu(
|
||||
pluginData: GuildPluginData<ReactionRolesPluginType>,
|
||||
|
@ -12,14 +13,29 @@ export async function handleOpenMenu(
|
|||
context,
|
||||
) {
|
||||
const menuButtons: MessageButton[] = [];
|
||||
if (group.button_menus == null) {
|
||||
await int.reply({
|
||||
content: `A configuration error was encountered, please contact the Administrators!`,
|
||||
ephemeral: true,
|
||||
});
|
||||
pluginData
|
||||
.getPlugin(LogsPlugin)
|
||||
.log(
|
||||
LogType.BOT_ALERT,
|
||||
`**A configuration error occured** on buttons for message ${int.message.id}, no menus found in config`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
for (const menuButton of Object.values(group.button_menus[context.roleOrMenu])) {
|
||||
const customId = await generateStatelessCustomId(pluginData, context.groupName, menuButton.role_or_menu);
|
||||
|
||||
const btn = new MessageButton()
|
||||
.setLabel(menuButton.label)
|
||||
.setLabel(menuButton.label ?? "")
|
||||
.setStyle("PRIMARY")
|
||||
.setType("BUTTON")
|
||||
.setCustomID(customId);
|
||||
.setCustomID(customId)
|
||||
.setDisabled(menuButton.disabled ?? false);
|
||||
|
||||
if (menuButton.emoji) {
|
||||
const emo = pluginData.client.emojis.resolve(menuButton.emoji) ?? menuButton.emoji;
|
||||
|
@ -41,9 +57,9 @@ export async function handleOpenMenu(
|
|||
);
|
||||
return;
|
||||
}
|
||||
const row = new MessageActionRow().addComponents(menuButtons);
|
||||
const rows = splitButtonsIntoRows(menuButtons, Object.values(group.button_menus[context.roleOrMenu])); // new MessageActionRow().addComponents(menuButtons);
|
||||
|
||||
int.reply({ content: `Click to add/remove a role`, components: [row], ephemeral: true });
|
||||
int.reply({ content: `Click to add/remove a role`, components: rows, ephemeral: true });
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -69,12 +85,26 @@ export async function handleModifyRole(
|
|||
}
|
||||
|
||||
const member = await 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 int.reply({ content: `Role **${role.name}** removed`, ephemeral: true });
|
||||
} else {
|
||||
await member.roles.add(role, `Button Roles on message ${int.message.id}`);
|
||||
await int.reply({ content: `Role **${role.name}** added`, ephemeral: true });
|
||||
try {
|
||||
if (member.roles.cache.has(role.id)) {
|
||||
await member.roles.remove(role, `Button Roles on message ${int.message.id}`);
|
||||
await int.reply({ content: `Role **${role.name}** removed`, ephemeral: true });
|
||||
} else {
|
||||
await member.roles.add(role, `Button Roles on message ${int.message.id}`);
|
||||
await int.reply({ content: `Role **${role.name}** added`, ephemeral: true });
|
||||
}
|
||||
} catch (e) {
|
||||
await int.reply({
|
||||
content: "A configuration error was encountered, please contact the Administrators!",
|
||||
ephemeral: true,
|
||||
});
|
||||
pluginData
|
||||
.getPlugin(LogsPlugin)
|
||||
.log(
|
||||
LogType.BOT_ALERT,
|
||||
`**A configuration error occured** on buttons for message ${int.message.id}, error: ${e}. We might be missing permissions!`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue