3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-07-06 10:37:19 +00:00
This commit is contained in:
seeyebe 2025-06-08 01:11:26 +03:00 committed by GitHub
commit 724bcf4072
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 12 deletions

View file

@ -1,10 +1,13 @@
import { GuildMember } from "discord.js";
import { guildPluginEventListener } from "knub";
import { SECONDS } from "../../../utils.js";
import { renderRecursively } from "../../../utils.js";
import { parseCustomId } from "../../../utils/parseCustomId.js";
import { RoleManagerPlugin } from "../../RoleManager/RoleManagerPlugin.js";
import { getAllRolesInButtons } from "../functions/getAllRolesInButtons.js";
import { RoleButtonsPluginType, TRoleButtonOption } from "../types.js";
import { renderTemplate, TemplateSafeValueContainer } from "../../../templateFormatter.js";
import { memberToTemplateSafeMember, roleToTemplateSafeRole, userToTemplateSafeUser } from "../../../utils/templateSafeObjects.js";
const ROLE_BUTTON_CD = 5 * SECONDS;
@ -31,7 +34,6 @@ export const onButtonInteraction = guildPluginEventListener<RoleButtonsPluginTyp
ephemeral: true,
content: "Invalid option selected",
})
// tslint:disable-next-line no-console
.catch((err) => console.trace(err.message));
return;
}
@ -53,14 +55,25 @@ export const onButtonInteraction = guildPluginEventListener<RoleButtonsPluginTyp
const rolesToRemove: string[] = [];
const rolesToAdd: string[] = [];
const renderTemplateText = async (str: string) =>
renderTemplate(
str,
new TemplateSafeValueContainer({
user: member ? memberToTemplateSafeMember(member) : userToTemplateSafeUser(args.interaction.user),
role: role ? roleToTemplateSafeRole(role) : new TemplateSafeValueContainer({ name: roleName, id: option.role_id }),
}),
);
if (member.roles.cache.has(option.role_id)) {
rolesToRemove.push(option.role_id);
const messageTemplate = config.buttons[name].remove_message || `The role **${roleName}** will be removed shortly!`;
const formatted = typeof messageTemplate === "string"
? await renderTemplateText(messageTemplate)
: await renderRecursively(messageTemplate, renderTemplateText);
args.interaction
.reply({
ephemeral: true,
content: `The role **${roleName}** will be removed shortly!`,
})
// tslint:disable-next-line no-console
.reply({ ephemeral: true, ...(typeof formatted === "string" ? { content: formatted } : formatted) })
.catch((err) => console.trace(err.message));
} else {
rolesToAdd.push(option.role_id);
@ -73,12 +86,13 @@ export const onButtonInteraction = guildPluginEventListener<RoleButtonsPluginTyp
}
}
const messageTemplate = config.buttons[name].add_message || `You will receive the **${roleName}** role shortly!`;
const formatted = typeof messageTemplate === "string"
? await renderTemplateText(messageTemplate)
: await renderRecursively(messageTemplate, renderTemplateText);
args.interaction
.reply({
ephemeral: true,
content: `You will receive the **${roleName}** role shortly!`,
})
// tslint:disable-next-line no-console
.reply({ ephemeral: true, ...(typeof formatted === "string" ? { content: formatted } : formatted) })
.catch((err) => console.trace(err.message));
}

View file

@ -44,6 +44,8 @@ const zRoleButtonsConfigItem = z
content: zMessageContent,
}),
]),
add_message: zMessageContent.optional(),
remove_message: zMessageContent.optional(),
options: z.array(zRoleButtonOption).max(25),
exclusive: z.boolean().default(false),
})