Skip to content

Commit

Permalink
db(guild settings): update schema and add create/delete guild methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jwford committed Mar 29, 2024
1 parent 4001493 commit f27d268
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 117 deletions.
151 changes: 42 additions & 109 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -7,126 +7,59 @@ datasource db {
url = env("DATABASE_URL")
}

type ClientStorageSchedules {
catchUp Boolean
data ClientStorageSchedulesData
id String
/// Could not determine type: the field only had null or empty values in the sample set.
recurring Json?
running Boolean
taskName String
time DateTime @db.Date
}
model Guild {
id String @id @default(auto()) @map("_id") @db.ObjectId
id_ String @unique @map("id") // snowflake
channels Channels?
deletePinMessages Boolean @default(false)
logEvents LogEvents
roles Roles?
snippets Snippet[]
type ClientStorageSchedulesData {
channel String?
channelID String?
content String
user String?
userID String?
// TODO: investigate creating an index on Atlas for this
@@unique([id_, snippets.name])
@@map("guilds")
}

type GuildsChannels {
type Channels {
memberlog String?
modlog String?
reminderChannel String?
serverlog String?
}

type GuildsLogEvents {
channelCreate Boolean?
channelUpdate Boolean?
guildMemberAdd Boolean?
guildMemberRemove Boolean?
messageDelete Boolean?
roleCreate Boolean?
roleUpdate Boolean?
}

type GuildsModeration {
cases GuildsModerationCases[]
}

type GuildsModerationCases {
action String
duration String
moderator String
number Int
reason String
target String
task String?
timestamp Float
type LogEvents {
channelCreate Boolean @default(true)
channelDelete Boolean @default(true)
channelUpdate Boolean @default(true)
emojiCreate Boolean @default(true)
emojiDelete Boolean @default(true)
emojiUpdate Boolean @default(true)
guildBanAdd Boolean @default(true)
guildBanRemove Boolean @default(true)
guildMemberAdd Boolean @default(true)
guildMemberRemove Boolean @default(true)
guildMemberUpdate Boolean @default(true)
inviteCreate Boolean @default(true)
inviteDelete Boolean @default(true)
messageDelete Boolean @default(true)
messageDeleteBulk Boolean @default(true)
roleCreate Boolean @default(true)
roleDelete Boolean @default(true)
roleUpdate Boolean @default(true)
}

type GuildsRoleAliases {
alias String
role String
type Roles {
administrator String?
assignable String[]
deafened String?
moderator String?
muted String?
restricted String[]
trusted String?
}

type GuildsRoles {
administrator String?
assignable String[]
deafened String?
dj String?
giveTrustedRoleOn String?
moderator String?
muted String?
private String[]
requireTrustedRoleForSelfAssign Boolean?
restricted String[]
trusted String?
}

type GuildsSnippets {
content String
embed Boolean?
type Snippet {
name String
}

type GuildsWordBlacklist {
wordList String[]
}

type UsersPomodoro {
currentSegment String?
longBreakTime Int?
running Boolean
shortBreakTime Int?
workRoundNumber Int
workTime Int?
}

model clientStorage {
id String @id @default(auto()) @map("_id") @db.ObjectId
/// Could not determine type: the field only had null or empty values in the sample set.
guildBlacklist Json?
id_ String @map("id")
schedules ClientStorageSchedules[]
userBlacklist String[]
wordBlacklist String[]
}

model guilds {
id String @id @default(auto()) @map("_id") @db.ObjectId
channels GuildsChannels?
deletePinMessages Boolean?
disabledCommands String[]
id_ String @map("id")
ignoredChannels String[]
logEvents GuildsLogEvents?
maxMentions Int?
moderation GuildsModeration?
moderationCases GuildsModerationCases[]
prefix String?
roleAliases GuildsRoleAliases[]
roles GuildsRoles?
snippets GuildsSnippets[]
wordBlacklist GuildsWordBlacklist?
}

model users {
id String @id @default(auto()) @map("_id") @db.ObjectId
embedColor String?
id_ String @map("id")
pomodoro UsersPomodoro?
content String
embed Boolean @default(false)
}
6 changes: 1 addition & 5 deletions src/lib/SteveClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { PrismaClient } from "@prisma/client";
import { SapphireClient, container } from "@sapphire/framework";
import { GatewayIntentBits } from "discord.js";
import SettingsProvider from "./database/SettingsProvider.js";
Expand All @@ -17,9 +16,7 @@ export default class SteveClient extends SapphireClient {
}

public override async login(token: string) {
// connect to database
container.prisma = new PrismaClient();
container.settings = new SettingsProvider(container.prisma);
container.settings = new SettingsProvider();

return super.login(token);
}
Expand All @@ -28,6 +25,5 @@ export default class SteveClient extends SapphireClient {
declare module "@sapphire/pieces" {
interface Container {
settings: SettingsProvider;
prisma: PrismaClient;
}
}
13 changes: 13 additions & 0 deletions src/lib/database/GuildSettings.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
import { PrismaClient } from "@prisma/client";
import { Snowflake } from "discord.js";

export default class GuildSettings {
private prisma: PrismaClient;

public constructor(prisma: PrismaClient) {
this.prisma = prisma;
}

public createGuild(guildSnowflake: Snowflake) {
return this.prisma.guild.create({
data: { id_: guildSnowflake, logEvents: {} },
});
}

public deleteGuild(guildSnowflake: Snowflake) {
return this.prisma.guild.delete({
where: { id_: guildSnowflake },
});
}
}
6 changes: 3 additions & 3 deletions src/lib/database/SettingsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export default class SettingsProvider {

private prisma: PrismaClient;

public constructor(prisma: PrismaClient) {
this.guilds = new GuildSettings(prisma);
this.prisma = prisma;
public constructor() {
this.prisma = new PrismaClient();
this.guilds = new GuildSettings(this.prisma);
}
}

0 comments on commit f27d268

Please sign in to comment.