mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-05-19 08:34:15 +02:00
feat(arabot): add specific restrict role on joining server
This commit is contained in:
parent
c60ba056ff
commit
7d54976cfd
@ -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
|
||||
|
@ -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({
|
||||
|
Loading…
x
Reference in New Issue
Block a user