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": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"build:changelog": "npx @discordx/changelog --src src",
|
"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",
|
"start": "node build/main.js",
|
||||||
"watch": "nodemon --exec ts-node-esm src/main.ts"
|
"watch": "nodemon --exec ts-node-esm src/main.ts"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@discordx/importer": "^1.2.2",
|
"@discordx/importer": "^1.2.2",
|
||||||
|
"@prisma/client": "4.15.0",
|
||||||
"discord.js": "^14.11.0",
|
"discord.js": "^14.11.0",
|
||||||
"discordx": "^11.7.6",
|
"discordx": "^11.7.6",
|
||||||
"dotenv": "16.0.3"
|
"dotenv": "16.0.3"
|
||||||
|
@ -22,6 +23,7 @@
|
||||||
"@types/node": "^18.16.5",
|
"@types/node": "^18.16.5",
|
||||||
"nodemon": "^2.0.22",
|
"nodemon": "^2.0.22",
|
||||||
"prettier": "^2.8.8",
|
"prettier": "^2.8.8",
|
||||||
|
"prisma": "^4.15.0",
|
||||||
"ts-node": "^10.9.1",
|
"ts-node": "^10.9.1",
|
||||||
"typescript": "4.9.5"
|
"typescript": "4.9.5"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,9 +1,16 @@
|
||||||
lockfileVersion: '6.0'
|
lockfileVersion: '6.1'
|
||||||
|
|
||||||
|
settings:
|
||||||
|
autoInstallPeers: true
|
||||||
|
excludeLinksFromLockfile: false
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
'@discordx/importer':
|
'@discordx/importer':
|
||||||
specifier: ^1.2.2
|
specifier: ^1.2.2
|
||||||
version: 1.2.2
|
version: 1.2.2
|
||||||
|
'@prisma/client':
|
||||||
|
specifier: 4.15.0
|
||||||
|
version: 4.15.0(prisma@4.15.0)
|
||||||
discord.js:
|
discord.js:
|
||||||
specifier: ^14.11.0
|
specifier: ^14.11.0
|
||||||
version: 14.11.0
|
version: 14.11.0
|
||||||
|
@ -24,6 +31,9 @@ devDependencies:
|
||||||
prettier:
|
prettier:
|
||||||
specifier: ^2.8.8
|
specifier: ^2.8.8
|
||||||
version: 2.8.8
|
version: 2.8.8
|
||||||
|
prisma:
|
||||||
|
specifier: ^4.15.0
|
||||||
|
version: 4.15.0
|
||||||
ts-node:
|
ts-node:
|
||||||
specifier: ^10.9.1
|
specifier: ^10.9.1
|
||||||
version: 10.9.1(@types/node@18.16.5)(typescript@4.9.5)
|
version: 10.9.1(@types/node@18.16.5)(typescript@4.9.5)
|
||||||
|
@ -159,6 +169,28 @@ packages:
|
||||||
dev: false
|
dev: false
|
||||||
optional: true
|
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:
|
/@sapphire/async-queue@1.5.0:
|
||||||
resolution: {integrity: sha512-JkLdIsP8fPAdh9ZZjrbHWR/+mZj0wvKS5ICibcLrRI1j84UmLMshx5n9QmL8b95d4onJ2xxiyugTgSAX7AalmA==}
|
resolution: {integrity: sha512-JkLdIsP8fPAdh9ZZjrbHWR/+mZj0wvKS5ICibcLrRI1j84UmLMshx5n9QmL8b95d4onJ2xxiyugTgSAX7AalmA==}
|
||||||
engines: {node: '>=v14.0.0', npm: '>=7.0.0'}
|
engines: {node: '>=v14.0.0', npm: '>=7.0.0'}
|
||||||
|
@ -623,6 +655,14 @@ packages:
|
||||||
hasBin: true
|
hasBin: true
|
||||||
dev: 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:
|
/pstree.remy@1.1.8:
|
||||||
resolution: {integrity: sha512-77DZwxQmxKnu3aR542U+X8FypNzbfJ+C5XQDk3uWjWxn6151aIMGthWYRXTqT1E5oJvg+ljaa2OJi+VfvCOQ8w==}
|
resolution: {integrity: sha512-77DZwxQmxKnu3aR542U+X8FypNzbfJ+C5XQDk3uWjWxn6151aIMGthWYRXTqT1E5oJvg+ljaa2OJi+VfvCOQ8w==}
|
||||||
dev: true
|
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 { 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 { IntentsBitField } from "discord.js";
|
||||||
import * as dotenv from "dotenv";
|
import * as dotenv from "dotenv";
|
||||||
import { Client } from "discordx";
|
import { Client } from "discordx";
|
||||||
|
import { PrismaClient } from "@prisma/client";
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
export const prisma = new PrismaClient();
|
||||||
|
|
||||||
export const bot = new Client({
|
export const bot = new Client({
|
||||||
// To use only guild command
|
// To use only guild command
|
||||||
|
@ -54,6 +56,15 @@ bot.on("messageCreate", (message: Message) => {
|
||||||
bot.executeCommand(message);
|
bot.executeCommand(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
bot.on("guildCreate", (guild: Guild) => {
|
||||||
|
prisma.guild.create({
|
||||||
|
data: {
|
||||||
|
id: guild.id,
|
||||||
|
name: guild.name,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
// The following syntax should be used in the commonjs environment
|
// The following syntax should be used in the commonjs environment
|
||||||
//
|
//
|
||||||
|
@ -71,4 +82,10 @@ async function run() {
|
||||||
await bot.login(process.env.DISCORD_TOKEN);
|
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 { ContextMenu, Discord } from "discordx";
|
||||||
|
import { prisma } from "../main.js";
|
||||||
|
|
||||||
@Discord()
|
@Discord()
|
||||||
export class Report {
|
export class Report {
|
||||||
|
@ -7,8 +8,69 @@ export class Report {
|
||||||
name: "Report user",
|
name: "Report user",
|
||||||
type: ApplicationCommandType.User,
|
type: ApplicationCommandType.User,
|
||||||
})
|
})
|
||||||
reportUser(interaction: MessageContextMenuCommandInteraction) {
|
async reportUser(interaction: MessageContextMenuCommandInteraction, client: Client) {
|
||||||
interaction.reply({content: "Reported user " + interaction.targetId, ephemeral: true});
|
|
||||||
|
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