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
|
-- CreateTable
|
||||||
CREATE TABLE "member" (
|
CREATE TABLE "member" (
|
||||||
"id" TEXT NOT NULL,
|
"id" UUID NOT NULL DEFAULT gen_random_uuid(),
|
||||||
"name" TEXT NOT NULL,
|
"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")
|
CONSTRAINT "member_pkey" PRIMARY KEY ("id")
|
||||||
);
|
);
|
||||||
|
@ -20,7 +23,4 @@ CREATE TABLE "member" (
|
||||||
CREATE UNIQUE INDEX "guild_id_key" ON "guild"("id");
|
CREATE UNIQUE INDEX "guild_id_key" ON "guild"("id");
|
||||||
|
|
||||||
-- CreateIndex
|
-- CreateIndex
|
||||||
CREATE UNIQUE INDEX "member_id_key" ON "member"("id");
|
CREATE UNIQUE INDEX "member_dgid_duid_key" ON "member"("dgid", "duid");
|
||||||
|
|
||||||
-- CreateIndex
|
|
||||||
CREATE UNIQUE INDEX "member_booster_role_id_key" ON "member"("booster_role_id");
|
|
|
@ -1,5 +1,6 @@
|
||||||
generator client {
|
generator client {
|
||||||
provider = "prisma-client-js"
|
provider = "prisma-client-js"
|
||||||
|
previewFeatures = ["postgresqlExtensions"]
|
||||||
}
|
}
|
||||||
|
|
||||||
datasource db {
|
datasource db {
|
||||||
|
@ -14,7 +15,14 @@ model guild {
|
||||||
}
|
}
|
||||||
|
|
||||||
model member {
|
model member {
|
||||||
id String @id @unique
|
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
||||||
name String
|
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,
|
PermissionsBitField,
|
||||||
Role,
|
Role,
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
import {
|
import { Discord, Slash, SlashGroup, SlashOption } from "discordx";
|
||||||
Discord,
|
|
||||||
Guard,
|
|
||||||
GuardFunction,
|
|
||||||
Slash,
|
|
||||||
SlashGroup,
|
|
||||||
SlashOption,
|
|
||||||
} from "discordx";
|
|
||||||
import { prisma } from "../main.js";
|
import { prisma } from "../main.js";
|
||||||
|
|
||||||
@Discord()
|
@Discord()
|
||||||
|
@ -108,24 +101,28 @@ export class AdminCmds {
|
||||||
) {
|
) {
|
||||||
let mem = await prisma.member.findUnique({
|
let mem = await prisma.member.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: member.id,
|
dgid_duid: {
|
||||||
|
duid: member.id,
|
||||||
|
dgid: member.guild.id,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (mem) {
|
if (mem) {
|
||||||
await prisma.member.update({
|
await prisma.member.update({
|
||||||
where: {
|
where: {
|
||||||
id: member.id,
|
id: mem.id,
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
name: mem.name != member.displayName ? member.displayName : undefined,
|
|
||||||
booster_role_id: role.id,
|
booster_role_id: role.id,
|
||||||
|
name: member.displayName,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
await prisma.member.create({
|
await prisma.member.create({
|
||||||
data: {
|
data: {
|
||||||
id: member.id,
|
duid: member.id,
|
||||||
|
dgid: interaction.guildId!,
|
||||||
name: member.displayName,
|
name: member.displayName,
|
||||||
booster_role_id: role.id,
|
booster_role_id: role.id,
|
||||||
},
|
},
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"emitDecoratorMetadata": true,
|
"emitDecoratorMetadata": true,
|
||||||
|
"noImplicitAny": false,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"forceConsistentCasingInFileNames": true
|
"forceConsistentCasingInFileNames": true
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue