feat(arabot): add specific restrict role on joining server

This commit is contained in:
smyalygames 2023-02-14 01:30:13 +00:00
parent c60ba056ff
commit 7d54976cfd
2 changed files with 24 additions and 8 deletions

View File

@ -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)) {
const section = await getSection(member.id);
roles.length = 0;
roles.push(IDs.roles.restrictions.restricted1);
} else {
roles.length = 0;
// TODO add role push for restricted roles
}
roles.push(IDs.roles.restrictions.restricted[section - 1]);
}
// Check if the user has a verification block

View File

@ -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({