(#2) Added perk management for members.

Closes #2

Signed-off-by: Louis Hollingworth <louis@hollingworth.ch>
This commit is contained in:
Louis Hollingworth 2023-06-18 17:59:48 +01:00
parent e9bc78e9ff
commit 06e42b61e3
Signed by: lucxjo
GPG key ID: A11415CB3DC7809B

70
src/commands/perks.ts Normal file
View file

@ -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,
});
}
}
}
}