generated from lucxjo/template
(maint) Formatted files with prettier.
Signed-off-by: Louis Hollingworth <louis@hollingworth.ch>
This commit is contained in:
parent
715d04ef9b
commit
6e1e54da1b
|
@ -1,5 +1,18 @@
|
||||||
import { ApplicationCommandOptionType, Channel, CommandInteraction, GuildMember, PermissionsBitField } from "discord.js";
|
import {
|
||||||
import { Discord, Guard, GuardFunction, Slash, SlashGroup, SlashOption } from "discordx";
|
ApplicationCommandOptionType,
|
||||||
|
Channel,
|
||||||
|
CommandInteraction,
|
||||||
|
GuildMember,
|
||||||
|
PermissionsBitField,
|
||||||
|
} from "discord.js";
|
||||||
|
import {
|
||||||
|
Discord,
|
||||||
|
Guard,
|
||||||
|
GuardFunction,
|
||||||
|
Slash,
|
||||||
|
SlashGroup,
|
||||||
|
SlashOption,
|
||||||
|
} from "discordx";
|
||||||
import { prisma } from "../main.js";
|
import { prisma } from "../main.js";
|
||||||
|
|
||||||
const AdminOnly: GuardFunction<CommandInteraction> = async (
|
const AdminOnly: GuardFunction<CommandInteraction> = async (
|
||||||
|
@ -8,10 +21,11 @@ const AdminOnly: GuardFunction<CommandInteraction> = async (
|
||||||
next
|
next
|
||||||
) => {
|
) => {
|
||||||
const argObj = arg instanceof Array ? arg[0] : arg;
|
const argObj = arg instanceof Array ? arg[0] : arg;
|
||||||
const user = argObj.user as GuildMember
|
const user = argObj.user as GuildMember;
|
||||||
|
|
||||||
if (user.permissions.has(PermissionsBitField.Flags.Administrator)) await next();
|
if (user.permissions.has(PermissionsBitField.Flags.Administrator))
|
||||||
}
|
await next();
|
||||||
|
};
|
||||||
|
|
||||||
@Discord()
|
@Discord()
|
||||||
@SlashGroup({ name: "admin", description: "Admin commands" })
|
@SlashGroup({ name: "admin", description: "Admin commands" })
|
||||||
|
@ -24,52 +38,58 @@ class AdminCmds {
|
||||||
description: "Set where the reports should be sent",
|
description: "Set where the reports should be sent",
|
||||||
name: "reports_channel",
|
name: "reports_channel",
|
||||||
required: false,
|
required: false,
|
||||||
type: ApplicationCommandOptionType.Channel
|
type: ApplicationCommandOptionType.Channel,
|
||||||
})
|
})
|
||||||
channel: Channel,
|
channel: Channel,
|
||||||
interaction: CommandInteraction
|
interaction: CommandInteraction
|
||||||
) {
|
) {
|
||||||
if (channel) {
|
if (channel) {
|
||||||
await prisma.guild.findUnique({
|
await prisma.guild
|
||||||
|
.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: interaction.guildId!
|
id: interaction.guildId!,
|
||||||
}
|
},
|
||||||
}).then(async (data) => {
|
})
|
||||||
|
.then(async (data) => {
|
||||||
if (data) {
|
if (data) {
|
||||||
await prisma.guild.update({
|
await prisma.guild.update({
|
||||||
where: {
|
where: {
|
||||||
id: data.id
|
id: data.id,
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
reports_channel_id: channel.id,
|
reports_channel_id: channel.id,
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
} else {
|
} else {
|
||||||
await prisma.guild.create({
|
await prisma.guild.create({
|
||||||
data: {
|
data: {
|
||||||
id: interaction.guildId!,
|
id: interaction.guildId!,
|
||||||
name: interaction.guild!.name,
|
name: interaction.guild!.name,
|
||||||
reports_channel_id: channel.id
|
reports_channel_id: channel.id,
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
interaction.reply(`<#${channel.id}> is now setup to receive reports.`)
|
interaction.reply(
|
||||||
})
|
`<#${channel.id}> is now setup to receive reports.`
|
||||||
|
);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
await prisma.guild.findUnique({
|
await prisma.guild
|
||||||
|
.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: interaction.guildId!
|
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")
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
.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");
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,28 +6,30 @@ export class Threads {
|
||||||
@Slash({ description: "Display current threads", name: "threads" })
|
@Slash({ description: "Display current threads", name: "threads" })
|
||||||
async threads(interaction: CommandInteraction) {
|
async threads(interaction: CommandInteraction) {
|
||||||
if (interaction.guild) {
|
if (interaction.guild) {
|
||||||
const threads = await fetch(`https://discord.com/api/v10/guilds/${interaction.guildId}/threads/active`, {
|
const threads = await fetch(
|
||||||
|
`https://discord.com/api/v10/guilds/${interaction.guildId}/threads/active`,
|
||||||
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"Authorization": `Bot ${process.env.DISCORD_TOKEN}`
|
Authorization: `Bot ${process.env.DISCORD_TOKEN}`,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
})
|
);
|
||||||
|
|
||||||
|
|
||||||
const body = (await threads.json()).threads as Array<{
|
const body = (await threads.json()).threads as Array<{
|
||||||
flags: number,
|
flags: number;
|
||||||
guild_id: string,
|
guild_id: string;
|
||||||
id: string,
|
id: string;
|
||||||
parent_id: string
|
parent_id: string;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
let threadMsg = "The current active threads are:"
|
let threadMsg = "The current active threads are:";
|
||||||
|
|
||||||
body.forEach((thread) => {
|
body.forEach((thread) => {
|
||||||
threadMsg += `\n- <#${thread.id}>`
|
threadMsg += `\n- <#${thread.id}>`;
|
||||||
})
|
});
|
||||||
|
|
||||||
interaction.reply({ content: threadMsg, ephemeral: true })
|
interaction.reply({ content: threadMsg, ephemeral: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ export class Report {
|
||||||
new ActionRowBuilder<TextInputBuilder>().addComponents(reason)
|
new ActionRowBuilder<TextInputBuilder>().addComponents(reason)
|
||||||
);
|
);
|
||||||
|
|
||||||
interaction.showModal(modal)
|
interaction.showModal(modal);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
interaction.reply({
|
interaction.reply({
|
||||||
|
@ -81,23 +81,23 @@ export class Report {
|
||||||
|
|
||||||
@ModalComponent()
|
@ModalComponent()
|
||||||
async report_user(interaction: ModalSubmitInteraction, client: Client) {
|
async report_user(interaction: ModalSubmitInteraction, client: Client) {
|
||||||
const [user_id, reason] = ['user-id', 'reason'].map((id) => interaction.fields.getTextInputValue(id))
|
const [user_id, reason] = ["user-id", "reason"].map((id) =>
|
||||||
|
interaction.fields.getTextInputValue(id)
|
||||||
|
);
|
||||||
const data = await prisma.guild.findUnique({
|
const data = await prisma.guild.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: interaction.guildId!
|
id: interaction.guildId!,
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
client.channels.fetch(data!.reports_channel_id!).then((channel) => {
|
client.channels.fetch(data!.reports_channel_id!).then((channel) => {
|
||||||
if (channel?.isTextBased()) {
|
if (channel?.isTextBased()) {
|
||||||
let ct = channel as TextChannel;
|
let ct = channel as TextChannel;
|
||||||
ct.send({
|
ct.send({
|
||||||
content: `<@${interaction.user.id}> reported <@${
|
content: `<@${interaction.user.id}> reported <@${user_id}> for: ${reason}`,
|
||||||
user_id
|
|
||||||
}> for: ${reason}`,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
interaction.reply({content: "Reported user.", ephemeral: true})
|
interaction.reply({ content: "Reported user.", ephemeral: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue