(#1) Now backed with a DB for configuration.

Now just need to check that configuration has been set.

Signed-off-by: Louis Hollingworth <louis@hollingworth.ch>
This commit is contained in:
Louis Hollingworth 2023-06-11 13:09:45 +01:00
parent ae2dbc6c70
commit faca0b2fda
Signed by: lucxjo
GPG key ID: A11415CB3DC7809B
5 changed files with 142 additions and 7 deletions

View file

@ -1,10 +1,12 @@
import { dirname, importx } from "@discordx/importer";
import type { Interaction, Message } from "discord.js";
import type { Guild, Interaction, Message } from "discord.js";
import { IntentsBitField } from "discord.js";
import * as dotenv from "dotenv";
import { Client } from "discordx";
import { PrismaClient } from "@prisma/client";
dotenv.config();
export const prisma = new PrismaClient();
export const bot = new Client({
// To use only guild command
@ -54,6 +56,15 @@ bot.on("messageCreate", (message: Message) => {
bot.executeCommand(message);
});
bot.on("guildCreate", (guild: Guild) => {
prisma.guild.create({
data: {
id: guild.id,
name: guild.name,
}
})
})
async function run() {
// The following syntax should be used in the commonjs environment
//
@ -71,4 +82,10 @@ async function run() {
await bot.login(process.env.DISCORD_TOKEN);
}
run();
run().then(async () => {
await prisma.$disconnect();
}).catch(async (e) => {
console.error(e);
await prisma.$disconnect();
process.exit(1);
});

View file

@ -1,5 +1,6 @@
import { ApplicationCommandType, MessageContextMenuCommandInteraction } from "discord.js";
import { ActionRowBuilder, ApplicationCommandType, Client, MessageContextMenuCommandInteraction, ModalBuilder, TextChannel, TextInputBuilder, TextInputStyle } from "discord.js";
import { ContextMenu, Discord } from "discordx";
import { prisma } from "../main.js";
@Discord()
export class Report {
@ -7,8 +8,69 @@ export class Report {
name: "Report user",
type: ApplicationCommandType.User,
})
reportUser(interaction: MessageContextMenuCommandInteraction) {
interaction.reply({content: "Reported user " + interaction.targetId, ephemeral: true});
async reportUser(interaction: MessageContextMenuCommandInteraction, client: Client) {
if (interaction.guildId) {
let data = await prisma.guild.findUnique({
where: {
id: interaction.guildId!
}
})
if (!data) {
await prisma.guild.create({
data: {
id: interaction.guildId!,
name: interaction.guild!.name
}
})
data = await prisma.guild.findUnique({
where: {
id: interaction.guildId!
}
})
}
const modal = new ModalBuilder()
.setTitle("Report user")
.setCustomId("report-user");
const userId = new TextInputBuilder()
.setCustomId("user-id")
.setValue(interaction.targetId)
.setLabel("User ID")
.setStyle(TextInputStyle.Short);
const reason = new TextInputBuilder()
.setCustomId("reason")
.setLabel("Reason")
.setStyle(TextInputStyle.Paragraph);
modal.addComponents(
new ActionRowBuilder<TextInputBuilder>().addComponents(userId),
new ActionRowBuilder<TextInputBuilder>().addComponents(reason),
);
interaction.showModal(modal).then(() => {
interaction.editReply({
content: "Reported user.",
});
// client.channels.fetch("channel-id").then((channel) => {
// if (channel?.isTextBased()) {
// let ct = channel as TextChannel;
// ct.send({
// content: `User <@${interaction.user.id}> reported <@${interaction.targetId}> for: ${reason.data.value ?? ""}`,
// });
// }
//})
})
} else {
interaction.reply({
content: "It looks like you aren't in a guild, you can only report within guilds"
})
}
}
}