Skip to content

Commit

Permalink
db: get started with prisma (schema will need updating)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwford committed Mar 24, 2024
1 parent 0a8ee54 commit 0254abc
Show file tree
Hide file tree
Showing 6 changed files with 249 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ dist
node_modules

config.ts
.env
80 changes: 80 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build-clear": "rm -rf dist && tsc -p .",
"dev": "tsc -p . && node dist/src/Steve.js",
"dev-clear": "rm -rf dist && tsc -p . && node dist/src/Steve.js",
"lint": "eslint src --ext .ts",
"lint": "eslint src --ext .ts",
"start": "node dist/src/Steve.js"
},
"repository": {
Expand All @@ -28,6 +28,7 @@
},
"homepage": "https://github.com/stevebot-project/steve#readme",
"dependencies": {
"@prisma/client": "^5.11.0",
"@sapphire/decorators": "^6.1.0",
"@sapphire/duration": "^1.1.2",
"@sapphire/framework": "^5.0.10",
Expand All @@ -41,6 +42,7 @@
"@sapphire/eslint-config": "^5.0.4",
"@sapphire/ts-config": "^5.0.1",
"eslint": "^8.57.0",
"prisma": "^5.11.0",
"typescript": "^5.4.3"
}
}
132 changes: 132 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "mongodb"
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
}

type ClientStorageSchedulesData {
channel String?
channelID String?
content String
user String?
userID String?
}

type GuildsChannels {
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 GuildsRoleAliases {
alias String
role 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?
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?
}
6 changes: 3 additions & 3 deletions src/Steve.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { SapphireClient } from "@sapphire/framework";
import { BotOptions, Tokens } from "#root/config";
import SteveClient from "#lib/SteveClient";
import { Tokens } from "#root/config";

import "@sapphire/plugin-i18next/register";

const steve = new SapphireClient(BotOptions);
const steve = new SteveClient();

steve.login(Tokens.BotToken).catch((err) => console.error(err));
30 changes: 30 additions & 0 deletions src/lib/SteveClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { PrismaClient } from "@prisma/client";
import { SapphireClient, container } from "@sapphire/framework";
import { GatewayIntentBits } from "discord.js";

export default class SteveClient extends SapphireClient {
public constructor() {
super({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages],
i18n: {
// eslint-disable-next-line @typescript-eslint/require-await
fetchLanguage: async () => {
return "en-US";
},
},
});
}

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

return super.login(token);
}
}

declare module "@sapphire/pieces" {
interface Container {
prisma: PrismaClient;
}
}

0 comments on commit 0254abc

Please sign in to comment.