generated from lucxjo/template
(#1) User reporting now complete
closes #1 Signed-off-by: Louis Hollingworth <louis@hollingworth.ch>
This commit is contained in:
parent
faca0b2fda
commit
6770bd8d35
7 changed files with 856 additions and 349 deletions
75
src/commands/admin.ts
Normal file
75
src/commands/admin.ts
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
import { ApplicationCommandOptionType, Channel, CommandInteraction, GuildMember, PermissionsBitField } from "discord.js";
|
||||
import { Discord, Guard, GuardFunction, Slash, SlashGroup, SlashOption } 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"})
|
||||
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")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue