mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-05-19 10:34:16 +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 { 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';
|
||||||
import { checkActive } from '#utils/database/restriction';
|
import { checkActive, getSection } from '#utils/database/restriction';
|
||||||
|
|
||||||
export class RolesJoinServerListener extends Listener {
|
export class RolesJoinServerListener extends Listener {
|
||||||
public constructor(context: Listener.Context, options: Listener.Options) {
|
public constructor(context: Listener.Context, options: Listener.Options) {
|
||||||
@ -39,13 +39,9 @@ export class RolesJoinServerListener extends Listener {
|
|||||||
|
|
||||||
// Check if the user is restricted
|
// Check if the user is restricted
|
||||||
if (await checkActive(member.id)) {
|
if (await checkActive(member.id)) {
|
||||||
if (roles.includes(IDs.roles.vegan.vegan)) {
|
const section = await getSection(member.id);
|
||||||
roles.length = 0;
|
roles.length = 0;
|
||||||
roles.push(IDs.roles.restrictions.restricted1);
|
roles.push(IDs.roles.restrictions.restricted[section - 1]);
|
||||||
} else {
|
|
||||||
roles.length = 0;
|
|
||||||
// TODO add role push for restricted roles
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the user has a verification block
|
// Check if the user has a verification block
|
||||||
|
@ -78,6 +78,26 @@ export async function checkActive(userId: Snowflake) {
|
|||||||
return restriction.endTime === null;
|
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
|
// This is only for restrictions created with the old bot
|
||||||
export async function unRestrictLegacy(userId: Snowflake, modId: Snowflake, section: number) {
|
export async function unRestrictLegacy(userId: Snowflake, modId: Snowflake, section: number) {
|
||||||
await container.database.restrict.create({
|
await container.database.restrict.create({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user