generated from lucxjo/template
(#2) Members can now be in multiple guilds
Signed-off-by: Louis Hollingworth <louis@hollingworth.ch>
This commit is contained in:
parent
e8f797d1e0
commit
530e99a7d0
|
@ -9,9 +9,12 @@ CREATE TABLE "guild" (
|
|||
|
||||
-- CreateTable
|
||||
CREATE TABLE "member" (
|
||||
"id" TEXT NOT NULL,
|
||||
"id" UUID NOT NULL DEFAULT gen_random_uuid(),
|
||||
"name" TEXT NOT NULL,
|
||||
"booster_role_id" TEXT NOT NULL,
|
||||
"booster_role_id" TEXT,
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"dgid" TEXT NOT NULL,
|
||||
"duid" TEXT NOT NULL,
|
||||
|
||||
CONSTRAINT "member_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
@ -20,7 +23,4 @@ CREATE TABLE "member" (
|
|||
CREATE UNIQUE INDEX "guild_id_key" ON "guild"("id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "member_id_key" ON "member"("id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "member_booster_role_id_key" ON "member"("booster_role_id");
|
||||
CREATE UNIQUE INDEX "member_dgid_duid_key" ON "member"("dgid", "duid");
|
|
@ -1,5 +1,6 @@
|
|||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
previewFeatures = ["postgresqlExtensions"]
|
||||
}
|
||||
|
||||
datasource db {
|
||||
|
@ -14,7 +15,14 @@ model guild {
|
|||
}
|
||||
|
||||
model member {
|
||||
id String @id @unique
|
||||
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
||||
name String
|
||||
booster_role_id String @unique
|
||||
booster_role_id String?
|
||||
created_at DateTime @default(now())
|
||||
/// Discord Guild ID
|
||||
dgid String
|
||||
/// Discord User ID
|
||||
duid String
|
||||
|
||||
@@unique([dgid, duid])
|
||||
}
|
||||
|
|
|
@ -6,14 +6,7 @@ import {
|
|||
PermissionsBitField,
|
||||
Role,
|
||||
} from "discord.js";
|
||||
import {
|
||||
Discord,
|
||||
Guard,
|
||||
GuardFunction,
|
||||
Slash,
|
||||
SlashGroup,
|
||||
SlashOption,
|
||||
} from "discordx";
|
||||
import { Discord, Slash, SlashGroup, SlashOption } from "discordx";
|
||||
import { prisma } from "../main.js";
|
||||
|
||||
@Discord()
|
||||
|
@ -108,24 +101,28 @@ export class AdminCmds {
|
|||
) {
|
||||
let mem = await prisma.member.findUnique({
|
||||
where: {
|
||||
id: member.id,
|
||||
dgid_duid: {
|
||||
duid: member.id,
|
||||
dgid: member.guild.id,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (mem) {
|
||||
await prisma.member.update({
|
||||
where: {
|
||||
id: member.id,
|
||||
id: mem.id,
|
||||
},
|
||||
data: {
|
||||
name: mem.name != member.displayName ? member.displayName : undefined,
|
||||
booster_role_id: role.id,
|
||||
name: member.displayName,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
await prisma.member.create({
|
||||
data: {
|
||||
id: member.id,
|
||||
duid: member.id,
|
||||
dgid: interaction.guildId!,
|
||||
name: member.displayName,
|
||||
booster_role_id: role.id,
|
||||
},
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
|
||||
"noImplicitAny": false,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue