mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-07-06 10:37:19 +00:00
Merge 04b8914531
into 3ef89246ba
This commit is contained in:
commit
724bcf4072
2 changed files with 28 additions and 12 deletions
|
@ -1,10 +1,13 @@
|
||||||
import { GuildMember } from "discord.js";
|
import { GuildMember } from "discord.js";
|
||||||
import { guildPluginEventListener } from "knub";
|
import { guildPluginEventListener } from "knub";
|
||||||
import { SECONDS } from "../../../utils.js";
|
import { SECONDS } from "../../../utils.js";
|
||||||
|
import { renderRecursively } from "../../../utils.js";
|
||||||
import { parseCustomId } from "../../../utils/parseCustomId.js";
|
import { parseCustomId } from "../../../utils/parseCustomId.js";
|
||||||
import { RoleManagerPlugin } from "../../RoleManager/RoleManagerPlugin.js";
|
import { RoleManagerPlugin } from "../../RoleManager/RoleManagerPlugin.js";
|
||||||
import { getAllRolesInButtons } from "../functions/getAllRolesInButtons.js";
|
import { getAllRolesInButtons } from "../functions/getAllRolesInButtons.js";
|
||||||
import { RoleButtonsPluginType, TRoleButtonOption } from "../types.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;
|
const ROLE_BUTTON_CD = 5 * SECONDS;
|
||||||
|
|
||||||
|
@ -31,7 +34,6 @@ export const onButtonInteraction = guildPluginEventListener<RoleButtonsPluginTyp
|
||||||
ephemeral: true,
|
ephemeral: true,
|
||||||
content: "Invalid option selected",
|
content: "Invalid option selected",
|
||||||
})
|
})
|
||||||
// tslint:disable-next-line no-console
|
|
||||||
.catch((err) => console.trace(err.message));
|
.catch((err) => console.trace(err.message));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -53,14 +55,25 @@ export const onButtonInteraction = guildPluginEventListener<RoleButtonsPluginTyp
|
||||||
const rolesToRemove: string[] = [];
|
const rolesToRemove: string[] = [];
|
||||||
const rolesToAdd: 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)) {
|
if (member.roles.cache.has(option.role_id)) {
|
||||||
rolesToRemove.push(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
|
args.interaction
|
||||||
.reply({
|
.reply({ ephemeral: true, ...(typeof formatted === "string" ? { content: formatted } : formatted) })
|
||||||
ephemeral: true,
|
|
||||||
content: `The role **${roleName}** will be removed shortly!`,
|
|
||||||
})
|
|
||||||
// tslint:disable-next-line no-console
|
|
||||||
.catch((err) => console.trace(err.message));
|
.catch((err) => console.trace(err.message));
|
||||||
} else {
|
} else {
|
||||||
rolesToAdd.push(option.role_id);
|
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
|
args.interaction
|
||||||
.reply({
|
.reply({ ephemeral: true, ...(typeof formatted === "string" ? { content: formatted } : formatted) })
|
||||||
ephemeral: true,
|
|
||||||
content: `You will receive the **${roleName}** role shortly!`,
|
|
||||||
})
|
|
||||||
// tslint:disable-next-line no-console
|
|
||||||
.catch((err) => console.trace(err.message));
|
.catch((err) => console.trace(err.message));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,8 @@ const zRoleButtonsConfigItem = z
|
||||||
content: zMessageContent,
|
content: zMessageContent,
|
||||||
}),
|
}),
|
||||||
]),
|
]),
|
||||||
|
add_message: zMessageContent.optional(),
|
||||||
|
remove_message: zMessageContent.optional(),
|
||||||
options: z.array(zRoleButtonOption).max(25),
|
options: z.array(zRoleButtonOption).max(25),
|
||||||
exclusive: z.boolean().default(false),
|
exclusive: z.boolean().default(false),
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue