fix(arabot): make adding roles more efficient and stable

This commit is contained in:
smyalygames 2023-02-26 01:57:32 +00:00
parent b6bd3c6e80
commit e1fd0eed83

View File

@ -18,7 +18,7 @@
*/ */
import { Listener } from '@sapphire/framework'; import { Listener } from '@sapphire/framework';
import type { GuildMember } from 'discord.js'; import type { GuildMember, Snowflake } from 'discord.js';
import { fetchRoles } from '#utils/database/dbExistingUser'; import { fetchRoles } from '#utils/database/dbExistingUser';
import IDs from '#utils/ids'; import IDs from '#utils/ids';
import { blockTime } from '#utils/database/verification'; import { blockTime } from '#utils/database/verification';
@ -33,17 +33,15 @@ export class RolesJoinServerListener extends Listener {
} }
public async run(member: GuildMember) { public async run(member: GuildMember) {
// Add basic roles let roles: Snowflake[] = [];
const roles = await fetchRoles(member.id);
// Check if the user is restricted // Check if the user is restricted
if (await checkActive(member.id)) { if (await checkActive(member.id)) {
const section = await getSection(member.id); const section = await getSection(member.id);
for (let i = 0; i < roles.length; i += 1) {
roles.pop();
}
roles.push(IDs.roles.restrictions.restricted[section - 1]); roles.push(IDs.roles.restrictions.restricted[section - 1]);
} else {
// Add roles if not restricted
roles = await fetchRoles(member.id);
} }
// Check if the user has a verification block // Check if the user has a verification block