Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
Warnings:

- You are about to drop the `Punishment` table. If the table is not empty, all the data it contains will be lost.

*/
-- DropForeignKey
ALTER TABLE "Punishment" DROP CONSTRAINT "Punishment_guildId_fkey";

-- DropForeignKey
ALTER TABLE "Punishment" DROP CONSTRAINT "Punishment_referenceId_fkey";

-- DropTable
DROP TABLE "Punishment";

-- CreateTable
CREATE TABLE "Infraction" (
"id" SERIAL NOT NULL,
"caseId" INTEGER NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"duration" INTEGER,
"guildId" TEXT NOT NULL,
"moderatorId" TEXT NOT NULL DEFAULT '934121887829737562',
"moderatorName" TEXT NOT NULL DEFAULT 'Sentry',
"moderatorIconUrl" TEXT NOT NULL DEFAULT 'https://github.com/PenPow/Sentry/blob/main/branding/SquareLogoNoText.png?raw=true',
"reason" TEXT NOT NULL,
"modLogMessageId" TEXT,
"action" "CaseAction" NOT NULL,
"userId" TEXT NOT NULL,
"referenceId" INTEGER,
"userName" TEXT NOT NULL,
"frozen" BOOLEAN NOT NULL DEFAULT false,

CONSTRAINT "Infraction_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "Infraction_id_key" ON "Infraction"("id");

-- CreateIndex
CREATE UNIQUE INDEX "Infraction_guildId_caseId_key" ON "Infraction"("guildId", "caseId");

-- AddForeignKey
ALTER TABLE "Infraction" ADD CONSTRAINT "Infraction_guildId_fkey" FOREIGN KEY ("guildId") REFERENCES "Guild"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Infraction" ADD CONSTRAINT "Infraction_referenceId_fkey" FOREIGN KEY ("referenceId") REFERENCES "Infraction"("id") ON DELETE SET NULL ON UPDATE CASCADE;
10 changes: 5 additions & 5 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ datasource db {

model Guild {
id String @id @unique
cases Punishment[]
cases Infraction[]
}

enum CaseAction {
Expand All @@ -27,7 +27,7 @@ enum CaseAction {
VDeafen
}

model Punishment {
model Infraction {
id Int @id @unique @default(autoincrement())
caseId Int
createdAt DateTime @default(now())
Expand All @@ -42,9 +42,9 @@ model Punishment {
action CaseAction
userId String
referenceId Int?
caseReference Punishment? @relation("CaseReference", fields: [referenceId], references: [id])
references Punishment[] @relation("CaseReference")
userName String /// Username at time of punishment
caseReference Infraction? @relation("CaseReference", fields: [referenceId], references: [id])
references Infraction[] @relation("CaseReference")
userName String /// Username at time of infraction
frozen Boolean @default(false)

@@unique([guildId, caseId])
Expand Down
14 changes: 7 additions & 7 deletions src/commands/moderation/Ban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import { Command, PreconditionOption } from "../../lib/framework/structures/Comm
import { PermissionsValidator } from "../../utilities/Permissions.js";
import { permissionsV1 } from "../../preconditions/SentryRequiresModerationPermissions.js";
import { Option } from "@sapphire/result";
import { PunishmentLock, createCase } from "../../utilities/Punishments.js";
import { InfractionLock, createCase } from "../../utilities/Infractions.js";
import { reasonAutocompleteHandler } from "../../handlers/Reason.js";
import { referenceAutocompleteHandler } from "../../handlers/Reference.js";
import { createTimedPunishment } from "../../functions/createTimedPunishment.js";
import { createTimedInfraction } from "../../functions/createTimedInfraction.js";
import { PreconditionValidationError } from "../../lib/framework/structures/errors/PreconditionValidationError.js";

export default class BanCommand implements Command {
Expand All @@ -38,7 +38,7 @@ export default class BanCommand implements Command {
}

public chatInputRun(interaction: ChatInputCommandInteraction<"cached">) {
return createTimedPunishment(interaction, "Ban");
return createTimedInfraction(interaction, "Ban");
}

public async userContextMenuRun(interaction: UserContextMenuCommandInteraction<"cached">) {
Expand Down Expand Up @@ -67,7 +67,7 @@ export default class BanCommand implements Command {

await interaction.deferReply();

await PunishmentLock.acquire(`punishment-${userId}`, async () => {
await InfractionLock.acquire(`infraction-${userId}`, async () => {
const [, embed] = await createCase(interaction.guild, {
guildId: interaction.guildId,
reason: interaction.fields.getTextInputValue("reason"),
Expand Down Expand Up @@ -111,20 +111,20 @@ export default class BanCommand implements Command {
},
{
name: 'reason',
description: 'The reason for adding this punishment',
description: 'The reason for adding this infraction',
type: ApplicationCommandOptionType.String,
max_length: 500,
autocomplete: true,
required: true,
},
{
name: 'dm',
description: 'Message the user with details of their punishment',
description: 'Message the user with details of their infraction',
type: ApplicationCommandOptionType.Boolean,
},
{
name: 'reference',
description: 'Reference another case in this punishment',
description: 'Reference another case in this infraction',
type: ApplicationCommandOptionType.Integer,
min_value: 1,
autocomplete: true,
Expand Down
30 changes: 15 additions & 15 deletions src/commands/moderation/Case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import { Option } from "@sapphire/result";
import { reasonAutocompleteHandler } from "../../handlers/Reason.js";
import { prisma } from "../../utilities/Prisma.js";
import { createEmbed, postModLogMessage } from "../../utilities/Logging.js";
import { PunishmentLock } from "../../utilities/Punishments.js";
import { InfractionLock } from "../../utilities/Infractions.js";
import { Duration, Time } from "@sapphire/time-utilities";
import { redis } from "../../utilities/Redis.js";
import { PunishmentScheduledTaskManager } from "../../tasks/PunishmentExpiration.js";
import { InfractionScheduledTaskManager } from "../../tasks/InfractionExpiration.js";
import { Job } from "bullmq";
import { referenceAutocompleteHandler } from "../../handlers/Reference.js";
import { UserLike } from "../../types/Punishment.js";
import { UserLike } from "../../types/Infraction.js";
import { InternalError } from "../../lib/framework/structures/errors/InternalError.js";
import { PreconditionValidationError } from "../../lib/framework/structures/errors/PreconditionValidationError.js";

Expand Down Expand Up @@ -148,7 +148,7 @@ export default class CaseCommand implements Command {
const caseNo = interaction.options.getInteger("case", true);

// eslint-disable-next-line max-len
const modCase = await prisma.punishment.findUnique({ where: { guildId_caseId: { guildId: interaction.guildId, caseId: caseNo }}, include: { caseReference: true }});
const modCase = await prisma.infraction.findUnique({ where: { guildId_caseId: { guildId: interaction.guildId, caseId: caseNo }}, include: { caseReference: true }});

if (!modCase) {
const embed: APIEmbed = {
Expand All @@ -169,7 +169,7 @@ export default class CaseCommand implements Command {
const caseNo = interaction.options.getInteger("case", true);

// eslint-disable-next-line max-len
const modCase = await prisma.punishment.findUnique({ where: { guildId_caseId: { guildId: interaction.guildId, caseId: caseNo }}, include: { caseReference: true }});
const modCase = await prisma.infraction.findUnique({ where: { guildId_caseId: { guildId: interaction.guildId, caseId: caseNo }}, include: { caseReference: true }});

if (!modCase) {
const embed: APIEmbed = {
Expand Down Expand Up @@ -198,8 +198,8 @@ export default class CaseCommand implements Command {

modCase.reason = reason;

return PunishmentLock.acquire(`punishment-${modCase.userId}`, async () => {
await prisma.punishment.update({ where: { guildId_caseId: { guildId: interaction.guildId, caseId: caseNo }}, data: { reason } });
return InfractionLock.acquire(`infraction-${modCase.userId}`, async () => {
await prisma.infraction.update({ where: { guildId_caseId: { guildId: interaction.guildId, caseId: caseNo }}, data: { reason } });

const moderator: UserLike = { username: modCase.moderatorName, id: modCase.moderatorId, iconUrl: modCase.moderatorIconUrl };
const embed = await postModLogMessage(interaction.guild, moderator, modCase);
Expand Down Expand Up @@ -235,22 +235,22 @@ export default class CaseCommand implements Command {

modCase.duration = expiration.offset / Time.Second;

const key = `punishment-jid-${modCase.action === "VMute" ? "VDeafen" : modCase.action}-${modCase.userId}`;
const key = `infraction-jid-${modCase.action === "VMute" ? "VDeafen" : modCase.action}-${modCase.userId}`;

let jobId = await redis.get(key);
const job = jobId ? await Job.fromId(PunishmentScheduledTaskManager.queue, jobId) : null;
const job = jobId ? await Job.fromId(InfractionScheduledTaskManager.queue, jobId) : null;

if(job) {
await job.changeDelay(modCase.duration * Time.Second);
await job.updateData(modCase);
}
else jobId = (await PunishmentScheduledTaskManager.schedule(modCase, { delay: modCase.duration * Time.Second })).id!;
else jobId = (await InfractionScheduledTaskManager.schedule(modCase, { delay: modCase.duration * Time.Second })).id!;

await redis.setex(key, modCase.duration, jobId!);

return PunishmentLock.acquire(`punishment-${modCase.userId}`, async () => {
return InfractionLock.acquire(`infraction-${modCase.userId}`, async () => {
// eslint-disable-next-line max-len
await prisma.punishment.update({ where: { guildId_caseId: { guildId: interaction.guildId, caseId: caseNo }}, data: { duration: modCase.duration } });
await prisma.infraction.update({ where: { guildId_caseId: { guildId: interaction.guildId, caseId: caseNo }}, data: { duration: modCase.duration } });

if(modCase.action === "Timeout") {
// eslint-disable-next-line max-len
Expand All @@ -270,7 +270,7 @@ export default class CaseCommand implements Command {
const caseNo = interaction.options.getInteger("case", true);

// eslint-disable-next-line max-len
const modCase = await prisma.punishment.findUnique({ where: { guildId_caseId: { guildId: interaction.guildId, caseId: caseNo }}, include: { caseReference: true }});
const modCase = await prisma.infraction.findUnique({ where: { guildId_caseId: { guildId: interaction.guildId, caseId: caseNo }}, include: { caseReference: true }});

if (!modCase) {
const embed: APIEmbed = {
Expand All @@ -292,8 +292,8 @@ export default class CaseCommand implements Command {

modCase.frozen = true;

return PunishmentLock.acquire(`punishment-${modCase.userId}`, async () => {
await prisma.punishment.update({ where: { guildId_caseId: { guildId: interaction.guildId, caseId: caseNo }}, data: { frozen: true } });
return InfractionLock.acquire(`infraction-${modCase.userId}`, async () => {
await prisma.infraction.update({ where: { guildId_caseId: { guildId: interaction.guildId, caseId: caseNo }}, data: { frozen: true } });

const moderator: UserLike = { username: modCase.moderatorName, id: modCase.moderatorId, iconUrl: modCase.moderatorIconUrl };
const embed = await postModLogMessage(interaction.guild, moderator, modCase);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/moderation/History.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { prisma } from "../../utilities/Prisma.js";
import { PaginatedMessage } from "@sapphire/discord.js-utilities";
import { clamp } from "../../utilities/Clamp.js";
import { createEmbed } from "../../utilities/Logging.js";
import { UserLike } from "../../types/Punishment.js";
import { UserLike } from "../../types/Infraction.js";
import { PreconditionValidationError } from "../../lib/framework/structures/errors/PreconditionValidationError.js";

export default class HistoryCommand implements Command {
Expand Down
14 changes: 7 additions & 7 deletions src/commands/moderation/Kick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import { Command, PreconditionOption } from "../../lib/framework/structures/Comm
import { PermissionsValidator } from "../../utilities/Permissions.js";
import { permissionsV1 } from "../../preconditions/SentryRequiresModerationPermissions.js";
import { Option } from "@sapphire/result";
import { PunishmentLock, createCase } from "../../utilities/Punishments.js";
import { InfractionLock, createCase } from "../../utilities/Infractions.js";
import { reasonAutocompleteHandler } from "../../handlers/Reason.js";
import { referenceAutocompleteHandler } from "../../handlers/Reference.js";
import { createPunishment } from "../../functions/createPunishment.js";
import { createInfraction } from "../../functions/createInfraction.js";
import { PreconditionValidationError } from "../../lib/framework/structures/errors/PreconditionValidationError.js";

export default class KickCommand implements Command {
Expand All @@ -38,7 +38,7 @@ export default class KickCommand implements Command {
}

public chatInputRun(interaction: ChatInputCommandInteraction<"cached">) {
return createPunishment(interaction, "Kick");
return createInfraction(interaction, "Kick");
}

public async userContextMenuRun(interaction: UserContextMenuCommandInteraction<"cached">) {
Expand Down Expand Up @@ -67,7 +67,7 @@ export default class KickCommand implements Command {

await interaction.deferReply();

await PunishmentLock.acquire(`punishment-${userId}`, async () => {
await InfractionLock.acquire(`infraction-${userId}`, async () => {
const [, embed] = await createCase(interaction.guild, {
guildId: interaction.guildId,
reason: interaction.fields.getTextInputValue("reason"),
Expand Down Expand Up @@ -111,20 +111,20 @@ export default class KickCommand implements Command {
},
{
name: 'reason',
description: 'The reason for adding this punishment',
description: 'The reason for adding this infraction',
type: ApplicationCommandOptionType.String,
max_length: 500,
autocomplete: true,
required: true,
},
{
name: 'dm',
description: 'Message the user with details of their punishment',
description: 'Message the user with details of their infraction',
type: ApplicationCommandOptionType.Boolean,
},
{
name: 'reference',
description: 'Reference another case in this punishment',
description: 'Reference another case in this infraction',
type: ApplicationCommandOptionType.Integer,
min_value: 1,
autocomplete: true,
Expand Down
14 changes: 7 additions & 7 deletions src/commands/moderation/Softban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import { Command, PreconditionOption } from "../../lib/framework/structures/Comm
import { PermissionsValidator } from "../../utilities/Permissions.js";
import { permissionsV1 } from "../../preconditions/SentryRequiresModerationPermissions.js";
import { Option } from "@sapphire/result";
import { PunishmentLock, createCase } from "../../utilities/Punishments.js";
import { InfractionLock, createCase } from "../../utilities/Infractions.js";
import { reasonAutocompleteHandler } from "../../handlers/Reason.js";
import { referenceAutocompleteHandler } from "../../handlers/Reference.js";
import { createPunishment } from "../../functions/createPunishment.js";
import { createInfraction } from "../../functions/createInfraction.js";
import { PreconditionValidationError } from "../../lib/framework/structures/errors/PreconditionValidationError.js";

export default class SoftbanCommand implements Command {
Expand All @@ -38,7 +38,7 @@ export default class SoftbanCommand implements Command {
}

public chatInputRun(interaction: ChatInputCommandInteraction<"cached">) {
return createPunishment(interaction, "Softban");
return createInfraction(interaction, "Softban");
}

public async userContextMenuRun(interaction: UserContextMenuCommandInteraction<"cached">) {
Expand Down Expand Up @@ -67,7 +67,7 @@ export default class SoftbanCommand implements Command {

await interaction.deferReply();

await PunishmentLock.acquire(`punishment-${userId}`, async () => {
await InfractionLock.acquire(`infraction-${userId}`, async () => {
const [, embed] = await createCase(interaction.guild, {
guildId: interaction.guildId,
reason: interaction.fields.getTextInputValue("reason"),
Expand Down Expand Up @@ -111,20 +111,20 @@ export default class SoftbanCommand implements Command {
},
{
name: 'reason',
description: 'The reason for adding this punishment',
description: 'The reason for adding this infraction',
type: ApplicationCommandOptionType.String,
max_length: 500,
autocomplete: true,
required: true,
},
{
name: 'dm',
description: 'Message the user with details of their punishment',
description: 'Message the user with details of their infraction',
type: ApplicationCommandOptionType.Boolean,
},
{
name: 'reference',
description: 'Reference another case in this punishment',
description: 'Reference another case in this infraction',
type: ApplicationCommandOptionType.Integer,
min_value: 1,
autocomplete: true,
Expand Down
Loading