er/src/commands/admin.ts
Louis Hollingworth a37a8a6935
Now role auto creation on boost can be disabled
Signed-off-by: Louis Hollingworth <louis@hollingworth.ch>
2023-06-22 20:40:29 +01:00

166 lines
4 KiB
TypeScript

import {
ApplicationCommandOptionType,
Channel,
CommandInteraction,
GuildMember,
PermissionsBitField,
Role,
} from "discord.js";
import { Discord, Slash, SlashGroup, SlashOption } from "discordx";
import { prisma } from "../main.js";
@Discord()
@SlashGroup({ name: "admin", description: "Admin commands" })
@SlashGroup("admin")
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",
name: "reports_channel",
required: false,
type: ApplicationCommandOptionType.Channel,
})
channel: Channel,
interaction: CommandInteraction
) {
if (channel) {
await prisma.guild
.findUnique({
where: {
id: interaction.guildId!,
},
})
.then(async (data) => {
if (data) {
await prisma.guild.update({
where: {
id: data.id,
},
data: {
reports_channel_id: channel.id,
},
});
} else {
await prisma.guild.create({
data: {
id: interaction.guildId!,
name: interaction.guild!.name,
reports_channel_id: channel.id,
},
});
}
interaction.reply(
`<#${channel.id}> is now setup to receive reports.`
);
});
} else {
await prisma.guild
.findUnique({
where: {
id: interaction.guildId!,
},
})
.then((data) => {
if (data) {
interaction.reply(
`<#${data.reports_channel_id}> is currently receiving reports for this guild.`
);
} else {
interaction.reply("Reports are currently disabled for this guild");
}
});
}
}
@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: {
dgid_duid: {
duid: member.id,
dgid: member.guild.id,
},
},
});
if (mem) {
await prisma.member.update({
where: {
id: mem.id,
},
data: {
booster_role_id: role.id,
name: member.displayName,
},
});
} else {
await prisma.member.create({
data: {
duid: member.id,
dgid: interaction.guildId!,
name: member.displayName,
booster_role_id: role.id,
},
});
}
interaction.reply({
content: "Member booster role updated!",
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,
});
}
}
}