mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-05-18 13:14:15 +02:00
feat(arabot): process non-vegan roles
This commit is contained in:
parent
ca0e43a70e
commit
a1469e0596
@ -22,10 +22,11 @@
|
|||||||
|
|
||||||
import { Listener } from '@sapphire/framework';
|
import { Listener } from '@sapphire/framework';
|
||||||
import { DurationFormatter } from '@sapphire/time-utilities';
|
import { DurationFormatter } from '@sapphire/time-utilities';
|
||||||
import type { Client } from 'discord.js';
|
import { Client } from 'discord.js';
|
||||||
import IDs from '#utils/ids';
|
import IDs from '#utils/ids';
|
||||||
import { fetchRoles } from '#utils/database/dbExistingUser';
|
import { fetchRoles } from '#utils/database/dbExistingUser';
|
||||||
import { checkActive } from '#utils/database/moderation/restriction';
|
import { checkActive } from '#utils/database/moderation/restriction';
|
||||||
|
import { getUser } from '#utils/database/fun/xp';
|
||||||
|
|
||||||
export class FixRolesOnReady extends Listener {
|
export class FixRolesOnReady extends Listener {
|
||||||
public constructor(
|
public constructor(
|
||||||
@ -40,13 +41,13 @@ export class FixRolesOnReady extends Listener {
|
|||||||
// THIS SHOULD BE DISABLED BY DEFAULT
|
// THIS SHOULD BE DISABLED BY DEFAULT
|
||||||
// THIS IS ONLY USED FOR RESTORING ROLES TO THE SERVER!
|
// THIS IS ONLY USED FOR RESTORING ROLES TO THE SERVER!
|
||||||
// ENABLING THIS UNINTENTIONALLY WILL CAUSE SLOWDOWNS TO THE BOT DUE TO RATE LIMITING!
|
// ENABLING THIS UNINTENTIONALLY WILL CAUSE SLOWDOWNS TO THE BOT DUE TO RATE LIMITING!
|
||||||
enabled: false,
|
enabled: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async run(client: Client) {
|
public async run(client: Client) {
|
||||||
this.container.logger.info(
|
this.container.logger.info(
|
||||||
'FixRolesOnReady: Preparation before starting to fix the roles for each user...',
|
'FixRolesOnReady: Preparation before starting to fix the roles for nonvegans...',
|
||||||
);
|
);
|
||||||
|
|
||||||
// Fetching the Guild
|
// Fetching the Guild
|
||||||
@ -109,7 +110,7 @@ export class FixRolesOnReady extends Listener {
|
|||||||
// Send a message with an update for every 50 completions
|
// Send a message with an update for every 50 completions
|
||||||
// Checks if `channelLog` has been set to null
|
// Checks if `channelLog` has been set to null
|
||||||
// The RHS of the modulo should be around 100
|
// The RHS of the modulo should be around 100
|
||||||
if (sendLogs && count % 250 === 0) {
|
if (sendLogs && count % 50 === 0) {
|
||||||
const currentTime = new Date().getTime();
|
const currentTime = new Date().getTime();
|
||||||
const runningTime = currentTime - startTime;
|
const runningTime = currentTime - startTime;
|
||||||
|
|
||||||
@ -123,10 +124,20 @@ export class FixRolesOnReady extends Listener {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Checks if the user is vegan
|
||||||
|
if (member.roles.cache.has(IDs.roles.vegan.vegan)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Checks if the user is restricted, and skips over them if they are
|
// Checks if the user is restricted, and skips over them if they are
|
||||||
const restricted = await checkActive(userId);
|
const restricted = await checkActive(userId);
|
||||||
|
|
||||||
if (restricted) {
|
if (
|
||||||
|
restricted ||
|
||||||
|
member.roles.cache.has(IDs.roles.restrictions.restricted1) ||
|
||||||
|
member.roles.cache.has(IDs.roles.restrictions.restricted2) ||
|
||||||
|
member.roles.cache.has(IDs.roles.restrictions.restrictedVegan)
|
||||||
|
) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,6 +147,14 @@ export class FixRolesOnReady extends Listener {
|
|||||||
// Filters out the roles that the member does not have
|
// Filters out the roles that the member does not have
|
||||||
const roles = dbRoles.filter((role) => !member.roles.cache.has(role));
|
const roles = dbRoles.filter((role) => !member.roles.cache.has(role));
|
||||||
|
|
||||||
|
if (!roles.includes(IDs.roles.nonvegan.nonvegan)) {
|
||||||
|
const xp = await getUser(userId);
|
||||||
|
|
||||||
|
if (xp !== null && xp.xp > 0) {
|
||||||
|
roles.push(IDs.roles.nonvegan.nonvegan);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Give the roles to the member
|
// Give the roles to the member
|
||||||
if (roles.length > 0) {
|
if (roles.length > 0) {
|
||||||
await member.roles.add(roles);
|
await member.roles.add(roles);
|
||||||
@ -146,6 +165,9 @@ export class FixRolesOnReady extends Listener {
|
|||||||
this.container.logger.info(
|
this.container.logger.info(
|
||||||
`FixRolesOnReady: Given roles to ${count}/${totalMembers}.`,
|
`FixRolesOnReady: Given roles to ${count}/${totalMembers}.`,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Add a delay so that there's around 4 users processed a second
|
||||||
|
await this.delay(250);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the logs that the fix has finished.
|
// Send the logs that the fix has finished.
|
||||||
@ -159,4 +181,8 @@ export class FixRolesOnReady extends Listener {
|
|||||||
logChannel.send(finishMessage);
|
logChannel.send(finishMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private delay(ms: number) {
|
||||||
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user