Now role auto creation on boost can be disabled

Signed-off-by: Louis Hollingworth <louis@hollingworth.ch>
This commit is contained in:
Louis Hollingworth 2023-06-22 20:40:29 +01:00
parent 9f53ee668c
commit a37a8a6935
Signed by: lucxjo
GPG key ID: A11415CB3DC7809B
4 changed files with 89 additions and 48 deletions

View file

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "guild" ADD COLUMN "auto_create_booster_roles" BOOLEAN NOT NULL DEFAULT true;

View file

@ -12,6 +12,7 @@ model guild {
id String @id @unique
name String
reports_channel_id String?
auto_create_booster_roles Boolean @default(true)
}
model member {

View file

@ -133,4 +133,34 @@ export class AdminCmds {
ephemeral: true,
});
}
@Slash({
description: "Enable or disable auto perk roles",
defaultMemberPermissions: PermissionsBitField.Flags.Administrator,
})
async toggle_perk_role_creation(interaction: CommandInteraction) {
if (interaction.guildId) {
const g = await prisma.guild.findUnique({
where: {
id: interaction.guildId,
},
});
await prisma.guild.update({
where: {
id: interaction.guildId,
},
data: {
auto_create_booster_roles: !g?.auto_create_booster_roles,
},
});
interaction.reply({
content: `Booster role creation is now ${
g?.auto_create_booster_roles ? "disabled" : "enabled"
}`,
ephemeral: true,
});
}
}
}

View file

@ -28,6 +28,13 @@ export class MemberEvent {
@On({ event: "guildMemberUpdate" })
async memberUpdate([oldM, newM]: ArgsOf<"guildMemberUpdate">) {
const g = await prisma.guild.findUnique({
where: {
id: newM.guild.id,
},
});
if (g?.auto_create_booster_roles) {
if (oldM.premiumSince !== newM.premiumSince) {
if (newM != null) {
const m = await prisma.member.findUnique({
@ -96,4 +103,5 @@ export class MemberEvent {
}
}
}
}
}