mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-05-19 23:54:15 +02:00
Compare commits
No commits in common. "616334f123539480527a97d3d2c0e04c4d957a9d" and "71f0ee9f0172904350b81378f8c5559957b7d9bf" have entirely different histories.
616334f123
...
71f0ee9f01
@ -22,11 +22,10 @@
|
|||||||
|
|
||||||
import { Listener } from '@sapphire/framework';
|
import { Listener } from '@sapphire/framework';
|
||||||
import { DurationFormatter } from '@sapphire/time-utilities';
|
import { DurationFormatter } from '@sapphire/time-utilities';
|
||||||
import { 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 { 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(
|
||||||
@ -41,13 +40,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: true,
|
enabled: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
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 nonvegans...',
|
'FixRolesOnReady: Preparation before starting to fix the roles for each user...',
|
||||||
);
|
);
|
||||||
|
|
||||||
// Fetching the Guild
|
// Fetching the Guild
|
||||||
@ -60,9 +59,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
|
const logChannel = await client.channels.fetch('');
|
||||||
.fetch('1329152627312824320')
|
|
||||||
.catch(() => null);
|
|
||||||
const sendLogs = logChannel !== null;
|
const sendLogs = logChannel !== null;
|
||||||
|
|
||||||
if (!sendLogs) {
|
if (!sendLogs) {
|
||||||
@ -86,7 +83,7 @@ export class FixRolesOnReady extends Listener {
|
|||||||
|
|
||||||
if (members === undefined) {
|
if (members === undefined) {
|
||||||
this.container.logger.error(
|
this.container.logger.error(
|
||||||
'FixRolesOnReady: Could not fetch all the members, this function is stopping now.',
|
'FixRolesOnReady: Could fetch all the members, this function is stopping now.',
|
||||||
);
|
);
|
||||||
if (sendLogs) {
|
if (sendLogs) {
|
||||||
logChannel.send("Never mind, something went wrong :'(");
|
logChannel.send("Never mind, something went wrong :'(");
|
||||||
@ -112,7 +109,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 % 50 === 0) {
|
if (sendLogs && count % 250 === 0) {
|
||||||
const currentTime = new Date().getTime();
|
const currentTime = new Date().getTime();
|
||||||
const runningTime = currentTime - startTime;
|
const runningTime = currentTime - startTime;
|
||||||
|
|
||||||
@ -126,22 +123,10 @@ 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
|
// Checks if the user is restricted, and skips over them if they are
|
||||||
const restricted = await checkActive(userId);
|
const restricted = await checkActive(userId);
|
||||||
|
|
||||||
if (
|
if (restricted) {
|
||||||
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,17 +136,6 @@ 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);
|
|
||||||
} else {
|
|
||||||
count++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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);
|
||||||
@ -172,9 +146,6 @@ 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(500);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the logs that the fix has finished.
|
// Send the logs that the fix has finished.
|
||||||
@ -188,8 +159,4 @@ export class FixRolesOnReady extends Listener {
|
|||||||
logChannel.send(finishMessage);
|
logChannel.send(finishMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private delay(ms: number) {
|
|
||||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,6 @@ const devIDs = {
|
|||||||
restricted2: '999431674997788676',
|
restricted2: '999431674997788676',
|
||||||
restricted3: '999431674997788675',
|
restricted3: '999431674997788675',
|
||||||
restricted4: '999431674997788674',
|
restricted4: '999431674997788674',
|
||||||
restrictedVegan: '1075952207091994726',
|
|
||||||
restricted: [
|
restricted: [
|
||||||
'999431674997788677', // Restricted 1
|
'999431674997788677', // Restricted 1
|
||||||
'999431674997788676', // Restricted 2
|
'999431674997788676', // Restricted 2
|
||||||
|
@ -44,7 +44,6 @@ let IDs = {
|
|||||||
restricted2: '872482843304001566',
|
restricted2: '872482843304001566',
|
||||||
restricted3: '1329126085207789658',
|
restricted3: '1329126085207789658',
|
||||||
restricted4: '1329126181164945499',
|
restricted4: '1329126181164945499',
|
||||||
restrictedVegan: '1075951477379567646',
|
|
||||||
restricted: [
|
restricted: [
|
||||||
'809769217477050369', // Restricted 1
|
'809769217477050369', // Restricted 1
|
||||||
'872482843304001566', // Restricted 2
|
'872482843304001566', // Restricted 2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user