Skip to content

Commit

Permalink
commands(select-roles-update): implement roles update
Browse files Browse the repository at this point in the history
Signed-off-by: TRACTION <19631364+iamtraction@users.noreply.github.com>
  • Loading branch information
iamtraction committed Sep 28, 2024
1 parent 3b9a89c commit eb7f89f
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/commands/config/select-roles/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class SelectRolesUpdateCommand extends Command {
name: "message",
description: "The new message content.",
},
{
type: ApplicationCommandOptionType.Boolean,
name: "roles",
description: "Reset the roles so you can add them again.",
},
],
userPermissions: [ PermissionFlagsBits.ManageGuild ],
});
Expand All @@ -38,6 +43,7 @@ class SelectRolesUpdateCommand extends Command {
await interaction.deferReply();
const id = interaction.options.getString("id");
const message = generateEmbed(interaction.options.getString("message") || "");
const resetRoles = interaction.options.getBoolean("roles");

// get the select roles group document
const selectRoleGroup = await SelectRoleGroupModel.findById(id);
Expand Down Expand Up @@ -95,7 +101,19 @@ class SelectRolesUpdateCommand extends Command {
await selectRolesMessage.edit({
content: message ? typeof message === "string" ? message : "" : undefined,
embeds: message ? typeof message === "string" ? [] : [ message ] : undefined,
components: arrays.chunks(selectRoles, 5).map(roles => ({
components: resetRoles ? [
{
type: ComponentType.ActionRow,
components: [
{
type: ComponentType.Button,
customId: MessageComponents.SelectRolesNoRolesButton,
style: ButtonStyle.Danger,
label: "Add Roles",
},
],
},
] : arrays.chunks(selectRoles, 5).map(roles => ({
type: ComponentType.ActionRow,
components: roles.map(role => ({
customId: MessageComponents.SelectRolesButton + ":" + role.value,
Expand All @@ -108,7 +126,7 @@ class SelectRolesUpdateCommand extends Command {
});
}

return interaction.editReply(`I've updated the Select Roles Group **${ id }**.`);
return interaction.editReply(`I've updated the Select Roles Group [**${ id }**](${ selectRolesMessage.url }).`);
}

await interaction.editReply(`The Select Roles Group **${ id }** doesn't exist anymore.`);
Expand Down

0 comments on commit eb7f89f

Please sign in to comment.