feat(build): add leave logs and giving roles on join from that

This commit is contained in:
smyalygames 2023-03-01 15:50:00 +00:00
parent 005c190582
commit e39812649a
3 changed files with 63 additions and 3 deletions

View File

@ -19,10 +19,11 @@
import { Listener } from '@sapphire/framework';
import type { GuildMember, Snowflake } from 'discord.js';
import { fetchRoles } from '#utils/database/dbExistingUser';
import IDs from '#utils/ids';
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 IDs from '#utils/ids';
export class RolesJoinServerListener extends Listener {
public constructor(context: Listener.Context, options: Listener.Options) {
@ -40,8 +41,14 @@ export class RolesJoinServerListener extends Listener {
const section = await getSection(member.id);
roles.push(IDs.roles.restrictions.restricted[section - 1]);
} else {
const logRoles = await getLeaveRoles(member.id);
// Add roles if not restricted
roles = await fetchRoles(member.id);
if (logRoles === null) {
roles = await fetchRoles(member.id);
} else {
roles = logRoles.roles.filter(this.blockedRole);
}
}
// Check if the user has a verification block
@ -55,4 +62,8 @@ export class RolesJoinServerListener extends Listener {
await member.roles.add(roles);
}
}
private blockedRole(role: Snowflake) {
return !blockedRoles.includes(role);
}
}

33
src/utils/blockedRoles.ts Normal file
View File

@ -0,0 +1,33 @@
// SPDX-License-Identifier: GPL-3.0-or-later
/*
Animal Rights Advocates Discord Bot
Copyright (C) 2023 Anthony Berg
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import IDs from '#utils/ids';
const blockedRoles = [
IDs.roles.staff.verifierCoordinator,
IDs.roles.staff.mentorCoordinator,
IDs.roles.staff.moderator,
IDs.roles.staff.trialModerator,
IDs.roles.staff.verifier,
IDs.roles.staff.trialVerifier,
IDs.roles.staff.mentor,
IDs.roles.stageHost,
];
export default blockedRoles;

View File

@ -201,3 +201,19 @@ export async function logLeaving(member: GuildMember) {
},
});
}
export async function getLeaveRoles(userId: Snowflake) {
const roles = container.database.leaveLog.findFirst({
where: {
userId,
},
orderBy: {
id: 'desc',
},
select: {
roles: true,
},
});
return roles;
}