feat(arabot): add better checking for giving roles to restricted users

This commit is contained in:
smyalygames 2023-03-08 00:25:01 +00:00
parent 21a53a1a75
commit 390af56fa5
2 changed files with 44 additions and 19 deletions

View File

@ -29,7 +29,7 @@ import { ChannelType } from 'discord.js';
import { fetchRoles, getLeaveRoles } from '#utils/database/dbExistingUser';
import { blockTime } from '#utils/database/verification';
import { checkActive, getSection } from '#utils/database/restriction';
import blockedRoles from '#utils/blockedRoles';
import { blockedRoles, blockedRestrictedRoles } from '#utils/blockedRoles';
import IDs from '#utils/ids';
export class RolesJoinServerListener extends Listener {
@ -41,19 +41,33 @@ export class RolesJoinServerListener extends Listener {
}
public async run(member: GuildMember) {
let roles: Snowflake[] = [];
let roles: Snowflake[];
const logRoles = await getLeaveRoles(member.id);
const privateCategory = member.guild.channels.cache.get(IDs.categories.private);
if (privateCategory !== undefined
&& privateCategory.type === ChannelType.GuildCategory) {
await this.privateRun(member.id, privateCategory, member.guild);
// Add roles if not restricted
if (logRoles === null) {
roles = await fetchRoles(member.id);
} else {
roles = logRoles.roles.filter(this.blockedRole);
}
// Check if the user is restricted
if (await checkActive(member.id)) {
const section = await getSection(member.id);
roles.push(IDs.roles.restrictions.restricted[section - 1]);
roles = roles.filter(this.blockedRestrictedRole);
let includesRestricted = false;
roles.forEach((role) => {
for (let i = 0; i < IDs.roles.restrictions.restricted.length; i += 1) {
if (role === IDs.roles.restrictions.restricted[i]) {
includesRestricted = true;
}
}
});
if (!includesRestricted) {
roles.push(IDs.roles.restrictions.restricted[section - 1]);
}
// Add user to the restricted vegan channel
if (section === 5) {
@ -63,15 +77,6 @@ export class RolesJoinServerListener extends Listener {
await this.restrictRun(member.id, restrictedCategory, member.guild);
}
}
} else {
const logRoles = await getLeaveRoles(member.id);
// Add roles if not restricted
if (logRoles === null) {
roles = await fetchRoles(member.id);
} else {
roles = logRoles.roles.filter(this.blockedRole);
}
}
// Check if the user has a verification block
@ -87,6 +92,13 @@ export class RolesJoinServerListener extends Listener {
if (roles.length > 0) {
await member.roles.add(roles);
}
const privateCategory = member.guild.channels.cache.get(IDs.categories.private);
if (privateCategory !== undefined
&& privateCategory.type === ChannelType.GuildCategory) {
await this.privateRun(member.id, privateCategory, member.guild);
}
}
private async restrictRun(userId: Snowflake, category: CategoryChannel, guild: Guild) {
@ -134,4 +146,8 @@ export class RolesJoinServerListener extends Listener {
private blockedRole(role: Snowflake) {
return !blockedRoles.includes(role);
}
private blockedRestrictedRole(role: Snowflake) {
return !blockedRestrictedRoles.includes(role);
}
}

View File

@ -19,7 +19,7 @@
import IDs from '#utils/ids';
const blockedRoles = [
export const blockedRoles = [
IDs.roles.staff.verifierCoordinator,
IDs.roles.staff.mentorCoordinator,
IDs.roles.staff.moderator,
@ -30,4 +30,13 @@ const blockedRoles = [
IDs.roles.stageHost,
];
export default blockedRoles;
export const blockedRestrictedRoles = [
IDs.roles.vegan.vegan,
IDs.roles.vegan.plus,
IDs.roles.vegan.activist,
IDs.roles.vegan.nvAccess,
IDs.roles.trusted,
IDs.roles.nonvegan.nonvegan,
IDs.roles.nonvegan.convinced,
IDs.roles.nonvegan.vegCurious,
];