(#2) Booster roles can now be linked to members.

Next steps:
 * Remove booster roles from the DB and Guild when someone stops
   boosting
 * Add booster roles to the DB and Guild when someone starts boosting

Signed-off-by: Louis Hollingworth <louis@hollingworth.ch>
This commit is contained in:
Louis Hollingworth 2023-06-18 12:34:31 +01:00
parent 6e1e54da1b
commit e8f797d1e0
Signed by: lucxjo
GPG key ID: A11415CB3DC7809B
7 changed files with 111 additions and 45 deletions

View file

@ -4,6 +4,7 @@ import {
CommandInteraction,
GuildMember,
PermissionsBitField,
Role,
} from "discord.js";
import {
Discord,
@ -15,24 +16,14 @@ import {
} from "discordx";
import { prisma } from "../main.js";
const AdminOnly: GuardFunction<CommandInteraction> = async (
arg,
client,
next
) => {
const argObj = arg instanceof Array ? arg[0] : arg;
const user = argObj.user as GuildMember;
if (user.permissions.has(PermissionsBitField.Flags.Administrator))
await next();
};
@Discord()
@SlashGroup({ name: "admin", description: "Admin commands" })
@SlashGroup("admin")
@Guard(AdminOnly)
class AdminCmds {
@Slash({ description: "Set or get the configured channel for reports" })
export class AdminCmds {
@Slash({
description: "Set or get the configured channel for reports",
defaultMemberPermissions: PermissionsBitField.Flags.Administrator,
})
async reports(
@SlashOption({
description: "Set where the reports should be sent",
@ -92,4 +83,57 @@ class AdminCmds {
});
}
}
@Slash({
description: "Link a user to their booster role",
name: "link_role",
defaultMemberPermissions: PermissionsBitField.Flags.ManageRoles,
})
async link_role(
@SlashOption({
description: "The user account to link",
name: "member",
required: true,
type: ApplicationCommandOptionType.User,
})
member: GuildMember,
@SlashOption({
description: "The role to link",
name: "role",
required: true,
type: ApplicationCommandOptionType.Role,
})
role: Role,
interaction: CommandInteraction
) {
let mem = await prisma.member.findUnique({
where: {
id: member.id,
},
});
if (mem) {
await prisma.member.update({
where: {
id: member.id,
},
data: {
name: mem.name != member.displayName ? member.displayName : undefined,
booster_role_id: role.id,
},
});
} else {
await prisma.member.create({
data: {
id: member.id,
name: member.displayName,
booster_role_id: role.id,
},
});
}
interaction.reply({
content: "Member booster role updated!",
ephemeral: true,
});
}
}