From b1b3beaa11964a23fc43c8e648f01950a2274d94 Mon Sep 17 00:00:00 2001 From: "tokyo.sshx" Date: Wed, 12 Nov 2025 11:21:53 -0400 Subject: [PATCH 1/2] blacklist system now the bot will ignore users --- package.json | 2 +- prisma/schema.prisma | 7 +++ src/commands/mod/add-to-blacklist.ts | 57 +++++++++++++++++++++++ src/commands/mod/remove-from-blacklist.ts | 53 +++++++++++++++++++++ src/events/ai/ai.ts | 16 ++++++- 5 files changed, 132 insertions(+), 3 deletions(-) create mode 100644 src/commands/mod/add-to-blacklist.ts create mode 100644 src/commands/mod/remove-from-blacklist.ts diff --git a/package.json b/package.json index 231023f0..814aa502 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "date-fns": "^4.1.0", "dayjs": "^1.11.18", "deepl-node": "1.20.0", - "discord.js": "14.24.0", + "discord.js": "^14.24.0", "discordx": "^11.13.2", "elysia": "^1.4.13" }, diff --git a/prisma/schema.prisma b/prisma/schema.prisma index f2cd3dee..39c34d60 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -10,6 +10,13 @@ datasource db { url = env("DATABASE_URL") } + +model backList { + userID String @id @unique + AddedBy String + AddedAt String +} + model Guild { guildId String @id @unique guildName String diff --git a/src/commands/mod/add-to-blacklist.ts b/src/commands/mod/add-to-blacklist.ts new file mode 100644 index 00000000..8b110c5b --- /dev/null +++ b/src/commands/mod/add-to-blacklist.ts @@ -0,0 +1,57 @@ +// WHY? +// Well, i want that the bot ignore u. + +import type { CommandInteraction } from "discord.js"; +import { ApplicationCommandOptionType, PermissionFlagsBits } from "discord.js"; +import { Discord, Slash, SlashOption } from "discordx"; +import { LogService } from "../../lib/logs/log.service"; +import { prisma } from "../../prisma"; + +@Discord() +export class AddToBlacklist { + @Slash({ + name: "add-to-blacklist", + description: `Add a user to bot's blacklist`, + defaultMemberPermissions: PermissionFlagsBits.ManageRoles, + dmPermission: false, + }) + async addToBlacklist( + @SlashOption({ + name: "user_id", + description: "ID to add to blacklist", + required: true, + type: ApplicationCommandOptionType.String, + }) + userId: string, + interaction: CommandInteraction + ) { + // LogService.logCommandHistory(interaction, "add-to-blacklist"); + + + const existingEntry = await prisma.backList.findFirst({ + where: { + userID: userId, + }, + }); + + if (existingEntry) { + return await interaction.reply({ + content: `The user with ID \`${userId}\` is already blacklisted.`, + ephemeral: true, + }); + } + + await prisma.backList.create({ + data: { + userID: userId, + // AddedBy: interaction.user.id, + // AddedAt: new Date(), + }, + }); + + await interaction.reply({ + content: `Successfully added user with ID \`${userId}\` to the blacklist.`, + ephemeral: true, + }); + } +} diff --git a/src/commands/mod/remove-from-blacklist.ts b/src/commands/mod/remove-from-blacklist.ts new file mode 100644 index 00000000..bfc3de8e --- /dev/null +++ b/src/commands/mod/remove-from-blacklist.ts @@ -0,0 +1,53 @@ +import type { CommandInteraction } from "discord.js"; +import { ApplicationCommandOptionType, PermissionFlagsBits } from "discord.js"; +import { Discord, Slash, SlashOption } from "discordx"; +import { LogService } from "../../lib/logs/log.service"; +import { prisma } from "../../prisma"; + + +@Discord() +export class RemoveFromBlackList { + @Slash({ + name: "remove-from-blacklist", + description: `Add a user to bot's blacklist`, + defaultMemberPermissions: PermissionFlagsBits.ManageRoles, + dmPermission: false, + }) + async addToBlacklist( + @SlashOption({ + name: "user_id", + description: "user ID", + required: true, + type: ApplicationCommandOptionType.String, + }) + userId: string, + interaction: CommandInteraction + ) { + // LogService.logCommandHistory(interaction, "add-to-blacklist"); + + + const existingEntry = await prisma.backList.findUnique({ + where: { + userID: userId, + }, + }); + + if (existingEntry) { + return await interaction.reply({ + content: `The user with ID \`${userId}\` is already blacklisted.`, + ephemeral: true, + }); + } + + await prisma.backList.delete({ + where: { + userID: userId, + }, + }); + + await interaction.reply({ + content: `Successfully added user with ID \`${userId}\` to the blacklist.`, + ephemeral: true, + }); + } +} \ No newline at end of file diff --git a/src/events/ai/ai.ts b/src/events/ai/ai.ts index 25848e28..568a5ca8 100644 --- a/src/events/ai/ai.ts +++ b/src/events/ai/ai.ts @@ -6,6 +6,7 @@ import type { ArgsOf, Client } from "discordx"; import { Discord, On } from "discordx"; import { ConfigValidator } from "../../lib/config-validator"; import { StatsService } from "../../lib/stats/stats.service"; +import { prisma } from "../../prisma"; import { AI_SYSTEM_PROMPT } from "./prompt"; import { channelMessages, @@ -26,7 +27,18 @@ export class AiChat { async messageCreate( [message]: ArgsOf<"messageCreate">, client: Client - ): Promise { + ): Promise { + const isBlacklisted = await prisma.backList.findFirst({ + where: { + userID: message.author.id, + }, + }); + + if (isBlacklisted) { + // Si está en la blacklist, ignorar el mensaje y salir + return; + } + if ( message.author.bot || !ConfigValidator.isFeatureEnabled("GOOGLE_GENERATIVE_AI_API_KEY") @@ -295,4 +307,4 @@ export class AiChat { } return null; } -} +} \ No newline at end of file From 3de91d522fc626611f7c887a62793346441dc9b5 Mon Sep 17 00:00:00 2001 From: "tokyo.sshx" Date: Wed, 12 Nov 2025 13:45:40 -0400 Subject: [PATCH 2/2] prisma migration fixed i'll continue working on it --- prisma/migrations/20240211152331_init/migration.sql | 8 -------- prisma/migrations/20241101171530_init/migration.sql | 2 -- .../migration.sql | 13 +++++++++++++ prisma/migrations/migration_lock.toml | 4 ++-- prisma/schema.prisma | 1 - src/commands/mod/add-to-blacklist.ts | 4 ++-- 6 files changed, 17 insertions(+), 15 deletions(-) delete mode 100644 prisma/migrations/20240211152331_init/migration.sql delete mode 100644 prisma/migrations/20241101171530_init/migration.sql rename prisma/migrations/{20240211013345_init => 20251112173735_init}/migration.sql (95%) diff --git a/prisma/migrations/20240211152331_init/migration.sql b/prisma/migrations/20240211152331_init/migration.sql deleted file mode 100644 index 66bc400e..00000000 --- a/prisma/migrations/20240211152331_init/migration.sql +++ /dev/null @@ -1,8 +0,0 @@ -/* - Warnings: - - - Added the required column `channelId` to the `MemberCommandHistory` table without a default value. This is not possible if the table is not empty. - -*/ --- AlterTable -ALTER TABLE "MemberCommandHistory" ADD COLUMN "channelId" TEXT NOT NULL; diff --git a/prisma/migrations/20241101171530_init/migration.sql b/prisma/migrations/20241101171530_init/migration.sql deleted file mode 100644 index f78f9d5c..00000000 --- a/prisma/migrations/20241101171530_init/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterTable -ALTER TABLE "MemberRole" ADD COLUMN "name" TEXT; diff --git a/prisma/migrations/20240211013345_init/migration.sql b/prisma/migrations/20251112173735_init/migration.sql similarity index 95% rename from prisma/migrations/20240211013345_init/migration.sql rename to prisma/migrations/20251112173735_init/migration.sql index 4754670d..fc597fae 100644 --- a/prisma/migrations/20240211013345_init/migration.sql +++ b/prisma/migrations/20251112173735_init/migration.sql @@ -1,3 +1,11 @@ +-- CreateTable +CREATE TABLE "backList" ( + "userID" TEXT NOT NULL, + "AddedBy" TEXT NOT NULL, + + CONSTRAINT "backList_pkey" PRIMARY KEY ("userID") +); + -- CreateTable CREATE TABLE "Guild" ( "guildId" TEXT NOT NULL, @@ -77,6 +85,7 @@ CREATE TABLE "MemberRole" ( "roleId" TEXT NOT NULL, "guildId" TEXT NOT NULL, "memberId" TEXT NOT NULL, + "name" TEXT, CONSTRAINT "MemberRole_pkey" PRIMARY KEY ("id") ); @@ -86,6 +95,7 @@ CREATE TABLE "MemberCommandHistory" ( "id" SERIAL NOT NULL, "memberId" TEXT NOT NULL, "guildId" TEXT NOT NULL, + "channelId" TEXT NOT NULL, "command" TEXT NOT NULL, "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, @@ -106,6 +116,9 @@ CREATE TABLE "MemberDeletedMessages" ( CONSTRAINT "MemberDeletedMessages_pkey" PRIMARY KEY ("id") ); +-- CreateIndex +CREATE UNIQUE INDEX "backList_userID_key" ON "backList"("userID"); + -- CreateIndex CREATE UNIQUE INDEX "Guild_guildId_key" ON "Guild"("guildId"); diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml index fbffa92c..044d57cd 100644 --- a/prisma/migrations/migration_lock.toml +++ b/prisma/migrations/migration_lock.toml @@ -1,3 +1,3 @@ # Please do not edit this file manually -# It should be added in your version-control system (i.e. Git) -provider = "postgresql" \ No newline at end of file +# It should be added in your version-control system (e.g., Git) +provider = "postgresql" diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 39c34d60..602168dc 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -14,7 +14,6 @@ datasource db { model backList { userID String @id @unique AddedBy String - AddedAt String } model Guild { diff --git a/src/commands/mod/add-to-blacklist.ts b/src/commands/mod/add-to-blacklist.ts index 8b110c5b..b2464dec 100644 --- a/src/commands/mod/add-to-blacklist.ts +++ b/src/commands/mod/add-to-blacklist.ts @@ -44,8 +44,8 @@ export class AddToBlacklist { await prisma.backList.create({ data: { userID: userId, - // AddedBy: interaction.user.id, - // AddedAt: new Date(), + AddedBy: interaction.user.id, + AddedAt: '' }, });