From 7d54976cfd07e18f9c14fec2f25e3837a69f3cbb Mon Sep 17 00:00:00 2001 From: smyalygames Date: Tue, 14 Feb 2023 01:30:13 +0000 Subject: [PATCH] feat(arabot): add specific restrict role on joining server --- src/listeners/rolesJoinServer.ts | 12 ++++-------- src/utils/database/restriction.ts | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/listeners/rolesJoinServer.ts b/src/listeners/rolesJoinServer.ts index 8448b67..0c2871c 100644 --- a/src/listeners/rolesJoinServer.ts +++ b/src/listeners/rolesJoinServer.ts @@ -22,7 +22,7 @@ import type { GuildMember } from 'discord.js'; import { fetchRoles } from '#utils/database/dbExistingUser'; import IDs from '#utils/ids'; import { blockTime } from '#utils/database/verification'; -import { checkActive } from '#utils/database/restriction'; +import { checkActive, getSection } from '#utils/database/restriction'; export class RolesJoinServerListener extends Listener { public constructor(context: Listener.Context, options: Listener.Options) { @@ -39,13 +39,9 @@ export class RolesJoinServerListener extends Listener { // Check if the user is restricted if (await checkActive(member.id)) { - if (roles.includes(IDs.roles.vegan.vegan)) { - roles.length = 0; - roles.push(IDs.roles.restrictions.restricted1); - } else { - roles.length = 0; - // TODO add role push for restricted roles - } + const section = await getSection(member.id); + roles.length = 0; + roles.push(IDs.roles.restrictions.restricted[section - 1]); } // Check if the user has a verification block diff --git a/src/utils/database/restriction.ts b/src/utils/database/restriction.ts index e7c37ff..5117401 100644 --- a/src/utils/database/restriction.ts +++ b/src/utils/database/restriction.ts @@ -78,6 +78,26 @@ export async function checkActive(userId: Snowflake) { return restriction.endTime === null; } +export async function getSection(userId: Snowflake) { + const restriction = await container.database.restrict.findFirst({ + where: { + userId, + }, + select: { + section: true, + }, + orderBy: { + id: 'desc', + }, + }); + + if (restriction === null) { + return 0; + } + + return restriction.section; +} + // This is only for restrictions created with the old bot export async function unRestrictLegacy(userId: Snowflake, modId: Snowflake, section: number) { await container.database.restrict.create({