From 06e42b61e394d5cb27c8cf28ca2656b9d6e7323e Mon Sep 17 00:00:00 2001 From: Louis Hollingworth Date: Sun, 18 Jun 2023 17:59:48 +0100 Subject: [PATCH] (#2) Added perk management for members. Closes #2 Signed-off-by: Louis Hollingworth --- src/commands/perks.ts | 70 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/commands/perks.ts diff --git a/src/commands/perks.ts b/src/commands/perks.ts new file mode 100644 index 0000000..d56a704 --- /dev/null +++ b/src/commands/perks.ts @@ -0,0 +1,70 @@ +import { + ApplicationCommandOptionType, + Channel, + CommandInteraction, +} from "discord.js"; +import { Discord, Slash, SlashGroup, SlashOption } from "discordx"; +import { prisma } from "../main.js"; + +@Discord() +@SlashGroup({ description: "Manage your booster perks", name: "perks" }) +@SlashGroup("perks") +export class Perks { + @Slash({ description: "Manage your role" }) + async role( + @SlashOption({ + name: "name", + description: "Change the name of your role", + type: ApplicationCommandOptionType.String, + }) + name?: string, + @SlashOption({ + name: "colour", + description: "Change the colour of your role (in hex)", + type: ApplicationCommandOptionType.String, + }) + colour?: string, + channel: Channel, + interaction: CommandInteraction + ) { + const m = await prisma.member.findUnique({ + where: { + dgid_duid: { + dgid: interaction.guildId!, + duid: interaction.user.id, + }, + }, + }); + + if (!m || !m.booster_role_id) { + interaction.reply({ + content: + "It appears that you may not be a booster of this guild, contact <@207603534789738496> if you think this is a mistake.", + ephemeral: true, + }); + } else { + const r = await interaction.guild?.roles.fetch(m.booster_role_id); + if (r) { + await interaction.guild?.roles.edit(r, { + name: name ?? undefined, + color: + colour != undefined + ? colour.startsWith("#") + ? parseInt(colour.replace("#", "0x"), 16) + : parseInt(`0x${colour}`) + : undefined, + }); + interaction.reply({ + content: "Role updated!", + ephemeral: true, + }); + } else { + interaction.reply({ + content: + "It appears that you may not be a booster of this guild, contact <@207603534789738496> if you think this is a mistake.", + ephemeral: true, + }); + } + } + } +}