generated from lucxjo/template
(#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:
parent
ae2dbc6c70
commit
faca0b2fda
|
@ -8,12 +8,13 @@
|
|||
"scripts": {
|
||||
"build": "tsc",
|
||||
"build:changelog": "npx @discordx/changelog --src src",
|
||||
"dev": "ts-node-esm src/main.ts",
|
||||
"dev": "node --loader ts-node/esm src/main.ts",
|
||||
"start": "node build/main.js",
|
||||
"watch": "nodemon --exec ts-node-esm src/main.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@discordx/importer": "^1.2.2",
|
||||
"@prisma/client": "4.15.0",
|
||||
"discord.js": "^14.11.0",
|
||||
"discordx": "^11.7.6",
|
||||
"dotenv": "16.0.3"
|
||||
|
@ -22,6 +23,7 @@
|
|||
"@types/node": "^18.16.5",
|
||||
"nodemon": "^2.0.22",
|
||||
"prettier": "^2.8.8",
|
||||
"prisma": "^4.15.0",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "4.9.5"
|
||||
},
|
||||
|
|
|
@ -1,9 +1,16 @@
|
|||
lockfileVersion: '6.0'
|
||||
lockfileVersion: '6.1'
|
||||
|
||||
settings:
|
||||
autoInstallPeers: true
|
||||
excludeLinksFromLockfile: false
|
||||
|
||||
dependencies:
|
||||
'@discordx/importer':
|
||||
specifier: ^1.2.2
|
||||
version: 1.2.2
|
||||
'@prisma/client':
|
||||
specifier: 4.15.0
|
||||
version: 4.15.0(prisma@4.15.0)
|
||||
discord.js:
|
||||
specifier: ^14.11.0
|
||||
version: 14.11.0
|
||||
|
@ -24,6 +31,9 @@ devDependencies:
|
|||
prettier:
|
||||
specifier: ^2.8.8
|
||||
version: 2.8.8
|
||||
prisma:
|
||||
specifier: ^4.15.0
|
||||
version: 4.15.0
|
||||
ts-node:
|
||||
specifier: ^10.9.1
|
||||
version: 10.9.1(@types/node@18.16.5)(typescript@4.9.5)
|
||||
|
@ -159,6 +169,28 @@ packages:
|
|||
dev: false
|
||||
optional: true
|
||||
|
||||
/@prisma/client@4.15.0(prisma@4.15.0):
|
||||
resolution: {integrity: sha512-xnROvyABcGiwqRNdrObHVZkD9EjkJYHOmVdlKy1yGgI+XOzvMzJ4tRg3dz1pUlsyhKxXGCnjIQjWW+2ur+YXuw==}
|
||||
engines: {node: '>=14.17'}
|
||||
requiresBuild: true
|
||||
peerDependencies:
|
||||
prisma: '*'
|
||||
peerDependenciesMeta:
|
||||
prisma:
|
||||
optional: true
|
||||
dependencies:
|
||||
'@prisma/engines-version': 4.15.0-28.8fbc245156db7124f997f4cecdd8d1219e360944
|
||||
prisma: 4.15.0
|
||||
dev: false
|
||||
|
||||
/@prisma/engines-version@4.15.0-28.8fbc245156db7124f997f4cecdd8d1219e360944:
|
||||
resolution: {integrity: sha512-sVOig4tjGxxlYaFcXgE71f/rtFhzyYrfyfNFUsxCIEJyVKU9rdOWIlIwQ2NQ7PntvGnn+x0XuFo4OC1jvPJKzg==}
|
||||
dev: false
|
||||
|
||||
/@prisma/engines@4.15.0:
|
||||
resolution: {integrity: sha512-FTaOCGs0LL0OW68juZlGxFtYviZa4xdQj/rQEdat2txw0s3Vu/saAPKjNVXfIgUsGXmQ72HPgNr6935/P8FNAA==}
|
||||
requiresBuild: true
|
||||
|
||||
/@sapphire/async-queue@1.5.0:
|
||||
resolution: {integrity: sha512-JkLdIsP8fPAdh9ZZjrbHWR/+mZj0wvKS5ICibcLrRI1j84UmLMshx5n9QmL8b95d4onJ2xxiyugTgSAX7AalmA==}
|
||||
engines: {node: '>=v14.0.0', npm: '>=7.0.0'}
|
||||
|
@ -623,6 +655,14 @@ packages:
|
|||
hasBin: true
|
||||
dev: true
|
||||
|
||||
/prisma@4.15.0:
|
||||
resolution: {integrity: sha512-iKZZpobPl48gTcSZVawLMQ3lEy6BnXwtoMj7hluoGFYu2kQ6F9LBuBrUyF95zRVnNo8/3KzLXJXJ5TEnLSJFiA==}
|
||||
engines: {node: '>=14.17'}
|
||||
hasBin: true
|
||||
requiresBuild: true
|
||||
dependencies:
|
||||
'@prisma/engines': 4.15.0
|
||||
|
||||
/pstree.remy@1.1.8:
|
||||
resolution: {integrity: sha512-77DZwxQmxKnu3aR542U+X8FypNzbfJ+C5XQDk3uWjWxn6151aIMGthWYRXTqT1E5oJvg+ljaa2OJi+VfvCOQ8w==}
|
||||
dev: true
|
||||
|
|
14
prisma/schema.prisma
Normal file
14
prisma/schema.prisma
Normal file
|
@ -0,0 +1,14 @@
|
|||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
model guild {
|
||||
id String @id @unique
|
||||
name String
|
||||
reports_channel_id String?
|
||||
}
|
21
src/main.ts
21
src/main.ts
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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"
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue