Skip to content

Commit dfaedc0

Browse files
itzwamAntoine 'toinux' Wam
authored andcommitted
feat: add per-category blocked roles-list
1 parent d07f69d commit dfaedc0

File tree

10 files changed

+16
-2
lines changed

10 files changed

+16
-2
lines changed

db/mysql/migrations/20230309144248_4_0_0/migration.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ CREATE TABLE `archivedUsers` (
5353

5454
-- CreateTable
5555
CREATE TABLE `categories` (
56+
`blockedRoles` JSON NOT NULL,
5657
`channelName` VARCHAR(191) NOT NULL,
5758
`claiming` BOOLEAN NOT NULL DEFAULT false,
5859
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

db/mysql/schema.prisma

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ model ArchivedMessage {
3737

3838
model ArchivedRole {
3939
archivedUsers ArchivedUser[]
40-
colour String @default("5865F2") @db.Char(6) // 7289DA
40+
colour String @default("5865F2") @db.Char(6) // 7289DA
4141
createdAt DateTime @default(now())
4242
name String
4343
roleId String @db.VarChar(19)
@@ -69,6 +69,7 @@ model ArchivedUser {
6969
}
7070

7171
model Category {
72+
blockedRoles Json @default("[]")
7273
channelName String
7374
claiming Boolean @default(false)
7475
createdAt DateTime @default(now())

db/postgresql/migrations/20230309132703_4_0_0/migration.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ CREATE TABLE "archivedUsers" (
5656

5757
-- CreateTable
5858
CREATE TABLE "categories" (
59+
"blockedRoles" JSONB NOT NULL DEFAULT '[]',
5960
"channelName" TEXT NOT NULL,
6061
"claiming" BOOLEAN NOT NULL DEFAULT false,
6162
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

db/postgresql/schema.prisma

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ model ArchivedMessage {
3636

3737
model ArchivedRole {
3838
archivedUsers ArchivedUser[]
39-
colour String @default("5865F2") @db.Char(6) // 7289DA
39+
colour String @default("5865F2") @db.Char(6) // 7289DA
4040
createdAt DateTime @default(now())
4141
name String
4242
roleId String @db.VarChar(19)
@@ -68,6 +68,7 @@ model ArchivedUser {
6868
}
6969

7070
model Category {
71+
blockedRoles Json @default("[]")
7172
channelName String
7273
claiming Boolean @default(false)
7374
createdAt DateTime @default(now())

db/sqlite/migrations/20230309142817_4_0_0/migration.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ CREATE TABLE "archivedUsers" (
5454

5555
-- CreateTable
5656
CREATE TABLE "categories" (
57+
"blockedRoles" TEXT NOT NULL DEFAULT '[]',
5758
"channelName" TEXT NOT NULL,
5859
"claiming" BOOLEAN NOT NULL DEFAULT false,
5960
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,

db/sqlite/schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ model ArchivedUser {
6868
}
6969

7070
model Category {
71+
blockedRoles String @default("[]")
7172
channelName String
7273
claiming Boolean @default(false)
7374
createdAt DateTime @default(now())

src/lib/middleware/prisma-sqlite.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const jsonFields = [
22
'pingRoles',
33
'requiredRoles',
4+
'blockedRoles',
45
'staffRoles',
56
'autoTag',
67
'blocklist',

src/lib/tickets/manager.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,11 @@ module.exports = class TicketManager {
227227
if (blocked) return await sendError('blocked');
228228
}
229229

230+
if (category.blockedRoles.length !== 0) {
231+
const blocked = category.blockedRoles.some(r => member.roles.cache.has(r));
232+
if (blocked) return await sendError('blocked');
233+
}
234+
230235
if (category.requiredRoles.length !== 0) {
231236
const missing = category.requiredRoles.some(r => !member.roles.cache.has(r));
232237
if (missing) return await sendError('missing_roles');

src/routes/api/admin/guilds/[guild]/categories/[category]/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ module.exports.patch = fastify => ({
7676
const data = req.body;
7777

7878
const select = {
79+
blockedRoles: true,
7980
channelName: true,
8081
claiming: true,
8182
// createdAt: true,

src/routes/api/admin/guilds/[guild]/categories/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module.exports.get = fastify => ({
2020
select: {
2121
categories: {
2222
select: {
23+
blockedRoles: true,
2324
createdAt: true,
2425
description: true,
2526
discordCategory: true,

0 commit comments

Comments
 (0)