mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-05-18 17:14:15 +02:00
feat(build): add leave logs
This commit is contained in:
parent
158c76c17e
commit
005c190582
12
prisma/migrations/20230301144406_leave_logs/migration.sql
Normal file
12
prisma/migrations/20230301144406_leave_logs/migration.sql
Normal file
@ -0,0 +1,12 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "LeaveLog" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"userId" TEXT NOT NULL,
|
||||
"time" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"roles" TEXT[],
|
||||
|
||||
CONSTRAINT "LeaveLog_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "LeaveLog" ADD CONSTRAINT "LeaveLog_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
@ -37,6 +37,7 @@ model User {
|
||||
muted Boolean @default(false)
|
||||
VerifyUser Verify[] @relation("verUser")
|
||||
VerifyVerifier Verify[] @relation("verVerifier")
|
||||
LeaveLog LeaveLog[]
|
||||
EventLeader Event[] @relation("eventLeader")
|
||||
StatLeader Stat[] @relation("statLeader")
|
||||
OutreachParticipation ParticipantStat[] @relation("participantUser")
|
||||
@ -87,6 +88,14 @@ model Verify {
|
||||
notes String?
|
||||
}
|
||||
|
||||
model LeaveLog {
|
||||
id Int @id @default(autoincrement())
|
||||
user User @relation(fields: [userId], references: [id])
|
||||
userId String
|
||||
time DateTime @default(now())
|
||||
roles String[]
|
||||
}
|
||||
|
||||
model Event {
|
||||
id Int @id @default(autoincrement())
|
||||
type EventType @relation(fields: [eventType], references: [type])
|
||||
|
@ -20,10 +20,12 @@
|
||||
import { Listener } from '@sapphire/framework';
|
||||
import type { GuildMember } from 'discord.js';
|
||||
import IDs from '#utils/ids';
|
||||
import { updateUser } from '#utils/database/dbExistingUser';
|
||||
import { checkBan } from '#utils/database/ban';
|
||||
import { checkTempBan } from '#utils/database/tempBan';
|
||||
import { checkActive } from '#utils/database/restriction';
|
||||
import {
|
||||
addEmptyUser,
|
||||
logLeaving,
|
||||
updateUser,
|
||||
userExists,
|
||||
} from '#utils/database/dbExistingUser';
|
||||
|
||||
export class DbLeaveServerListener extends Listener {
|
||||
public constructor(context: Listener.Context, options: Listener.Options) {
|
||||
@ -37,14 +39,12 @@ export class DbLeaveServerListener extends Listener {
|
||||
if (!member.roles.cache.hasAny(
|
||||
IDs.roles.vegan.vegan,
|
||||
IDs.roles.nonvegan.nonvegan,
|
||||
)
|
||||
|| await checkBan(member.id)
|
||||
|| await checkTempBan(member.id)
|
||||
|| await checkActive(member.id)
|
||||
) {
|
||||
return;
|
||||
)) {
|
||||
await updateUser(member);
|
||||
} else if (await userExists(member.id)) {
|
||||
await addEmptyUser(member.id);
|
||||
}
|
||||
|
||||
await updateUser(member);
|
||||
await logLeaving(member);
|
||||
}
|
||||
}
|
||||
|
@ -181,3 +181,23 @@ export async function fetchRoles(userId: Snowflake) {
|
||||
|
||||
return roles;
|
||||
}
|
||||
|
||||
export async function logLeaving(member: GuildMember) {
|
||||
const roles: Snowflake[] = [];
|
||||
member.roles.cache.forEach((role) => {
|
||||
if (role.id !== member.guild.id) {
|
||||
roles.push(role.id);
|
||||
}
|
||||
});
|
||||
|
||||
await container.database.leaveLog.create({
|
||||
data: {
|
||||
user: {
|
||||
connect: {
|
||||
id: member.id,
|
||||
},
|
||||
},
|
||||
roles,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user