mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-05-18 17:04:15 +02:00
fix: remove accidentally given nv roles from vegans
This commit is contained in:
parent
7918f73e7d
commit
b4c8f0785c
@ -24,8 +24,6 @@ import { Listener } from '@sapphire/framework';
|
|||||||
import { DurationFormatter } from '@sapphire/time-utilities';
|
import { DurationFormatter } from '@sapphire/time-utilities';
|
||||||
import type { Client } from 'discord.js';
|
import type { Client } from 'discord.js';
|
||||||
import IDs from '#utils/ids';
|
import IDs from '#utils/ids';
|
||||||
import { fetchRoles } from '#utils/database/dbExistingUser';
|
|
||||||
import { checkActive } from '#utils/database/moderation/restriction';
|
|
||||||
|
|
||||||
export class FixRolesOnReady extends Listener {
|
export class FixRolesOnReady extends Listener {
|
||||||
public constructor(
|
public constructor(
|
||||||
@ -40,7 +38,7 @@ 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,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +57,7 @@ export class FixRolesOnReady extends Listener {
|
|||||||
|
|
||||||
// Fetching the channel for the logs
|
// Fetching the channel for the logs
|
||||||
// Leave the snowflake parameter empty for no logs
|
// Leave the snowflake parameter empty for no logs
|
||||||
const logChannel = await client.channels.fetch('');
|
const logChannel = await client.channels.fetch('1329152627312824320');
|
||||||
const sendLogs = logChannel !== null;
|
const sendLogs = logChannel !== null;
|
||||||
|
|
||||||
if (!sendLogs) {
|
if (!sendLogs) {
|
||||||
@ -79,8 +77,23 @@ export class FixRolesOnReady extends Listener {
|
|||||||
logChannel.send('Fetching all the users in ARA!');
|
logChannel.send('Fetching all the users in ARA!');
|
||||||
}
|
}
|
||||||
|
|
||||||
const members = await guild.members.fetch().catch(() => undefined);
|
await guild.members.fetch();
|
||||||
|
|
||||||
|
// const members = await guild.members.fetch().catch(() => undefined);
|
||||||
|
const role = await guild.roles
|
||||||
|
.fetch(IDs.roles.vegan.vegan)
|
||||||
|
.catch(() => null);
|
||||||
|
if (role === null) {
|
||||||
|
this.container.logger.error(
|
||||||
|
'FixRolesOnReady: Could fetch all the members, this function is stopping now.1',
|
||||||
|
);
|
||||||
|
if (sendLogs) {
|
||||||
|
logChannel.send("Never mind, something went wrong :'(1");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const members = role.members;
|
||||||
if (members === undefined) {
|
if (members === undefined) {
|
||||||
this.container.logger.error(
|
this.container.logger.error(
|
||||||
'FixRolesOnReady: Could fetch all the members, this function is stopping now.',
|
'FixRolesOnReady: Could fetch all the members, this function is stopping now.',
|
||||||
@ -105,11 +118,12 @@ export class FixRolesOnReady extends Listener {
|
|||||||
'FixRolesOnReady: Starting the process of fixing the roles for every member...',
|
'FixRolesOnReady: Starting the process of fixing the roles for every member...',
|
||||||
);
|
);
|
||||||
|
|
||||||
for (const [userId, member] of members) {
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
for (const [_, member] of members) {
|
||||||
// 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 % 100 === 0) {
|
||||||
const currentTime = new Date().getTime();
|
const currentTime = new Date().getTime();
|
||||||
const runningTime = currentTime - startTime;
|
const runningTime = currentTime - startTime;
|
||||||
|
|
||||||
@ -119,32 +133,39 @@ export class FixRolesOnReady extends Listener {
|
|||||||
const estimate = new DurationFormatter().format(eta);
|
const estimate = new DurationFormatter().format(eta);
|
||||||
|
|
||||||
logChannel.send(
|
logChannel.send(
|
||||||
`Given roles to ${count} out of ${totalMembers} members. Estimated time until completion: ${estimate}`,
|
`Removed roles from ${count} out of ${totalMembers} members. Estimated time until completion: ${estimate}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Fetch the roles for the member in the database
|
||||||
|
// const dbRoles = await fetchRoles(userId);
|
||||||
|
//
|
||||||
|
// // Filters out the roles that the member does not have
|
||||||
|
// const roles = dbRoles.filter((role) => !member.roles.cache.has(role));
|
||||||
|
//
|
||||||
|
// // Give the roles to the member
|
||||||
|
// if (roles.length > 0) {
|
||||||
|
// await member.roles.add(roles);
|
||||||
|
// }
|
||||||
|
|
||||||
if (restricted) {
|
if (
|
||||||
continue;
|
member.roles.cache.has(IDs.roles.vegan.vegan) &&
|
||||||
}
|
member.roles.cache.has(IDs.roles.nonvegan.nonvegan)
|
||||||
|
) {
|
||||||
// Fetch the roles for the member in the database
|
await member.roles.remove(IDs.roles.nonvegan.nonvegan);
|
||||||
const dbRoles = await fetchRoles(userId);
|
|
||||||
|
|
||||||
// Filters out the roles that the member does not have
|
|
||||||
const roles = dbRoles.filter((role) => !member.roles.cache.has(role));
|
|
||||||
|
|
||||||
// Give the roles to the member
|
|
||||||
if (roles.length > 0) {
|
|
||||||
await member.roles.add(roles);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log the completion
|
// Log the completion
|
||||||
count += 1;
|
count += 1;
|
||||||
this.container.logger.info(
|
this.container.logger.info(
|
||||||
`FixRolesOnReady: Given roles to ${count}/${totalMembers}.`,
|
`FixRolesOnReady: Removed roles from ${count}/${totalMembers}.`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user