Compare commits

...

5 Commits

Author SHA1 Message Date
Anthony Berg
616334f123 fix(arabot): counting for fixRoles
Some checks are pending
CodeQL / Analyze (javascript) (push) Waiting to run
ESLint / Run eslint scanning (push) Waiting to run
Prettier / Run prettier scanning (push) Waiting to run
2025-01-17 16:16:08 +01:00
Anthony Berg
cd319609b0 fix(arabot): add snowflake for channel logs 2025-01-17 16:14:09 +01:00
Anthony Berg
a1469e0596 feat(arabot): process non-vegan roles 2025-01-17 16:07:05 +01:00
Anthony Berg
ca0e43a70e feat(arabot): add role for restricted vegan 2025-01-17 15:59:54 +01:00
Anthony Berg
dc16dee92c fix(arabot): typo in fixRoles 2025-01-17 15:34:22 +01:00
3 changed files with 42 additions and 7 deletions

View File

@ -22,10 +22,11 @@
import { Listener } from '@sapphire/framework';
import { DurationFormatter } from '@sapphire/time-utilities';
import type { Client } from 'discord.js';
import { Client } from 'discord.js';
import IDs from '#utils/ids';
import { fetchRoles } from '#utils/database/dbExistingUser';
import { checkActive } from '#utils/database/moderation/restriction';
import { getUser } from '#utils/database/fun/xp';
export class FixRolesOnReady extends Listener {
public constructor(
@ -40,13 +41,13 @@ export class FixRolesOnReady extends Listener {
// THIS SHOULD BE DISABLED BY DEFAULT
// THIS IS ONLY USED FOR RESTORING ROLES TO THE SERVER!
// ENABLING THIS UNINTENTIONALLY WILL CAUSE SLOWDOWNS TO THE BOT DUE TO RATE LIMITING!
enabled: false,
enabled: true,
});
}
public async run(client: Client) {
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
@ -59,7 +60,9 @@ export class FixRolesOnReady extends Listener {
// Fetching the channel for the logs
// Leave the snowflake parameter empty for no logs
const logChannel = await client.channels.fetch('');
const logChannel = await client.channels
.fetch('1329152627312824320')
.catch(() => null);
const sendLogs = logChannel !== null;
if (!sendLogs) {
@ -83,7 +86,7 @@ export class FixRolesOnReady extends Listener {
if (members === undefined) {
this.container.logger.error(
'FixRolesOnReady: Could fetch all the members, this function is stopping now.',
'FixRolesOnReady: Could not fetch all the members, this function is stopping now.',
);
if (sendLogs) {
logChannel.send("Never mind, something went wrong :'(");
@ -109,7 +112,7 @@ export class FixRolesOnReady extends Listener {
// Send a message with an update for every 50 completions
// Checks if `channelLog` has been set to null
// 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 runningTime = currentTime - startTime;
@ -123,10 +126,22 @@ export class FixRolesOnReady extends Listener {
);
}
// Checks if the user is vegan
if (member.roles.cache.has(IDs.roles.vegan.vegan)) {
count++;
continue;
}
// Checks if the user is restricted, and skips over them if they are
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)
) {
count++;
continue;
}
@ -136,6 +151,17 @@ export class FixRolesOnReady extends Listener {
// Filters out the roles that the member does not have
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);
} else {
count++;
continue;
}
}
// Give the roles to the member
if (roles.length > 0) {
await member.roles.add(roles);
@ -146,6 +172,9 @@ export class FixRolesOnReady extends Listener {
this.container.logger.info(
`FixRolesOnReady: Given roles to ${count}/${totalMembers}.`,
);
// Add a delay so that there's around 4 users processed a second
await this.delay(500);
}
// Send the logs that the fix has finished.
@ -159,4 +188,8 @@ export class FixRolesOnReady extends Listener {
logChannel.send(finishMessage);
}
}
private delay(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
}

View File

@ -42,6 +42,7 @@ const devIDs = {
restricted2: '999431674997788676',
restricted3: '999431674997788675',
restricted4: '999431674997788674',
restrictedVegan: '1075952207091994726',
restricted: [
'999431674997788677', // Restricted 1
'999431674997788676', // Restricted 2

View File

@ -44,6 +44,7 @@ let IDs = {
restricted2: '872482843304001566',
restricted3: '1329126085207789658',
restricted4: '1329126181164945499',
restrictedVegan: '1075951477379567646',
restricted: [
'809769217477050369', // Restricted 1
'872482843304001566', // Restricted 2