Skip to content
This repository was archived by the owner on Apr 6, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,14 @@ dist
.env.local
coverage
.DS_Store

# Ignore JS files compiled from TS (except in node_modules)
*.js
!node_modules/**/*.js

# Temporary files
*.cjs

# Auto-generated files
tests/auto-imports.d.ts
tests/imports.d.ts
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,9 @@ type Context = {
```

## License
Distributed under the GPLv3 License. See [LICENSE](https://github.com/RigbyHost/RigbyCore/blob/main/LICENSE) for more information.
Distributed under the GPLv3 License. See [LICENSE](https://github.com/RigbyHost/RigbyCore/blob/main/LICENSE) for more information.

## maintainers mental health
gone 💀

![gone](https://media1.tenor.com/m/XGouDAiIKn4AAAAC/bocchi-the-rock-hitori-gotoh.gif)
693 changes: 213 additions & 480 deletions bun.lock

Large diffs are not rendered by default.

33 changes: 27 additions & 6 deletions controller/ActionController.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
import {ActionData, actionsTable, ActionVariant} from "~~/drizzle";
/**
* NitroCore - GDPS (Geometry Dash Private Server) implementation
* Copyright (C) 2025 M41den <https://m41den.dev> and Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import {actionsTable, type ActionData, type ActionVariant} from "~~/drizzle";
import {UserController} from "~~/controller/UserController";
import {and, eq} from "drizzle-orm";
import {MakeOptional} from "~/utils/types";
import {type MakeOptional} from "~/utils/types";
import {type H3Event} from "nitro/h3";
import {type Database} from "~/utils/useDrizzle";

/**
* Controller for action logging
Expand All @@ -28,6 +48,7 @@ export class ActionController {
* Register a new action. Used internally by routes and controllers
*/
registerAction = async (
event: H3Event,
action: AvailableActions,
uid: number,
targetId: number,
Expand Down Expand Up @@ -122,7 +143,7 @@ export class ActionController {
// Fully async
useSDK().events.emitAction(action, uid, targetId, data as ActionData, {
drizzle: this.db,
config: useEvent().context.config.config!,
config: event.context.config.config!,
})
}

Expand Down Expand Up @@ -157,9 +178,9 @@ export class ActionController {
}

const count = await this.db.$count(actionsTable, and(
eq(actionsTable.uid, uid),
eq(actionsTable.actionType, type),
eq(actionsTable.targetId, targetId),
eq(actionsTable?.uid, uid),
eq(actionsTable?.actionType, type),
eq(actionsTable?.targetId, targetId),
))
return count > 0
}
Expand Down
90 changes: 53 additions & 37 deletions controller/CommentController.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
import {Database} from "~/utils/useDrizzle";
/**
* NitroCore - GDPS (Geometry Dash Private Server) implementation
* Copyright (C) 2025 M41den <https://m41den.dev> and Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import type {Database} from "~/utils/useDrizzle";
import {accountCommentsTable, commentsTable} from "~~/drizzle";
import {and, eq, sql} from "drizzle-orm";
import {ActionController} from "~~/controller/ActionController";
import {type H3Event} from 'nitro/h3';

/**
* Controller for comment management
Expand All @@ -25,22 +44,22 @@ export class CommentController {
}

countLevelComments = async (levelId?: number) =>
this.db.$count(commentsTable, levelId ? eq(commentsTable.levelId, levelId) : undefined)
this.db.$count(commentsTable, levelId ? eq(commentsTable?.levelId, levelId) : undefined)

countUserComments = async (uid?: number) =>
this.db.$count(accountCommentsTable, uid ? eq(accountCommentsTable.uid, uid) : undefined)
this.db.$count(accountCommentsTable, uid ? eq(accountCommentsTable?.uid, uid) : undefined)

countCommentHistory = async (uid: number) =>
this.db.$count(commentsTable, eq(commentsTable.uid, uid))
this.db.$count(commentsTable, eq(commentsTable?.uid, uid))

/**
* Get a single level comment by ID
*
* @param id
*/
getOneLevelComment = async (id: number) => {
const comment = await this.db.query.commentsTable.findFirst({
where: (comment, {eq}) => eq(comment.id, id)
const comment = await this.db.query?.commentsTable.findFirst({
where: (comment, {eq}) => eq(comment?.id, id)
})
return comment || null
}
Expand All @@ -51,8 +70,8 @@ export class CommentController {
* @param id
*/
getOneAccountComment = async (id: number) => {
const comment = await this.db.query.accountCommentsTable.findFirst({
where: (comment, {eq}) => eq(comment.id, id)
const comment = await this.db.query?.accountCommentsTable.findFirst({
where: (comment, {eq}) => eq(comment?.id, id)
})
return comment || null
}
Expand All @@ -64,9 +83,9 @@ export class CommentController {
* @param page
*/
getAllAccountComments = async (uid: number, page = 0) =>
this.db.query.accountCommentsTable.findMany({
where: (comment, {eq}) => eq(comment.uid, uid),
orderBy: (comment, {desc}) => [desc(comment.postedTime)],
this.db.query?.accountCommentsTable.findMany({
where: (comment, {eq}) => eq(comment?.uid, uid),
orderBy: (comment, {desc}) => [desc(comment?.postedTime)],
limit: 10,
offset: page * 10
})
Expand All @@ -83,9 +102,9 @@ export class CommentController {
sortBy: "likes" | "postedTime" = "postedTime",
page = 0,
) =>
this.db.query.commentsTable.findMany({
where: (comment, {eq}) => eq(comment.levelId, levelId),
orderBy: (comment, {desc}) => [desc(sortBy === "likes" ? comment.likes : comment.postedTime)],
this.db.query?.commentsTable.findMany({
where: (comment, {eq}) => eq(comment?.levelId, levelId),
orderBy: (comment, {desc}) => [desc(sortBy === "likes" ? comment.likes : comment?.postedTime)],
with: {
author: {
with: {role: true}
Expand All @@ -107,9 +126,9 @@ export class CommentController {
sortBy: "likes" | "postedTime" = "postedTime",
page = 0
) =>
this.db.query.commentsTable.findMany({
where: (comment, {eq}) => eq(comment.uid, uid),
orderBy: (comment, {desc}) => [desc(sortBy === "likes" ? comment.likes : comment.postedTime)],
this.db.query?.commentsTable.findMany({
where: (comment, {eq}) => eq(comment?.uid, uid),
orderBy: (comment, {desc}) => [desc(sortBy === "likes" ? comment.likes : comment?.postedTime)],
limit: 10,
offset: page * 10
})
Expand Down Expand Up @@ -154,64 +173,61 @@ export class CommentController {

deleteLevelComment = async (commentId: number, uid: number) => {
await this.db.delete(commentsTable).where(and(
eq(commentsTable.id, commentId),
eq(commentsTable.uid, uid)
eq(commentsTable?.id, commentId),
eq(commentsTable?.uid, uid)
))
}

deleteAccountComment = async (commentId: number, uid: number) => {
await this.db.delete(accountCommentsTable).where(and(
eq(accountCommentsTable.id, commentId),
eq(accountCommentsTable.uid, uid)
eq(accountCommentsTable?.id, commentId),
eq(accountCommentsTable?.uid, uid)
))
}

deleteLevelCommentByOwner = async (commentId: number, levelId: number) => {
await this.db.delete(commentsTable).where(and(
eq(commentsTable.id, commentId),
eq(commentsTable.levelId, levelId)
eq(commentsTable?.id, commentId),
eq(commentsTable?.levelId, levelId)
))
}

likeAccountComment = async (commentId: number, uid: number, action: "like" | "dislike") => {
likeAccountComment = async (event: H3Event, commentId: number, uid: number, action: "like" | "dislike") => {
const actionController = new ActionController(this.db)
if (await actionController.isItemLiked("account_comment", uid, commentId))
return false

await this.db.update(accountCommentsTable)
.set({
likes: action === "like"
? sql`${accountCommentsTable.likes} + 1`
: sql`${accountCommentsTable.likes} - 1`
? sql`${accountCommentsTable?.likes} + 1`
: sql`${accountCommentsTable?.likes} - 1`
})
.where(eq(accountCommentsTable.id, commentId))
.where(eq(accountCommentsTable?.id, commentId))

await actionController.registerAction(
event,
"like_account_comment",
uid,
commentId,
{action: action[0].toUpperCase() + action.slice(1)}
{action: action.charAt(0).toUpperCase() + action.slice(1)}
)
}

likeLevelComment = async (commentId: number, uid: number, action: "like" | "dislike") => {
likeLevelComment = async (event: H3Event, commentId: number, uid: number, action: "like" | "dislike") => {
const actionController = new ActionController(this.db)
if (await actionController.isItemLiked("comment", uid, commentId))
return false

await this.db.update(commentsTable)
.set({
likes: action === "like"
? sql`${commentsTable.likes} + 1`
: sql`${commentsTable.likes} - 1`
? sql`${commentsTable?.likes} + 1`
: sql`${commentsTable?.likes} - 1`
})
.where(eq(commentsTable.id, commentId))
.where(eq(commentsTable?.id, commentId))

await actionController.registerAction(
"like_comment",
uid,
commentId,
{action: action[0].toUpperCase() + action.slice(1)}
await actionController.registerAction(event, "like_comment", uid, commentId, {action: action.charAt(0).toUpperCase() + action.slice(1)}
)
}
}
Loading
Loading