mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-05-19 01:24:14 +02:00
Compare commits
5 Commits
71f0ee9f01
...
616334f123
Author | SHA1 | Date | |
---|---|---|---|
![]() |
616334f123 | ||
![]() |
cd319609b0 | ||
![]() |
a1469e0596 | ||
![]() |
ca0e43a70e | ||
![]() |
dc16dee92c |
@ -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
|
||||||
@ -59,7 +60,9 @@ 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')
|
||||||
|
.catch(() => null);
|
||||||
const sendLogs = logChannel !== null;
|
const sendLogs = logChannel !== null;
|
||||||
|
|
||||||
if (!sendLogs) {
|
if (!sendLogs) {
|
||||||
@ -83,7 +86,7 @@ export class FixRolesOnReady extends Listener {
|
|||||||
|
|
||||||
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 not 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 :'(");
|
||||||
@ -109,7 +112,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 +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
|
// 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)
|
||||||
|
) {
|
||||||
|
count++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,6 +151,17 @@ 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);
|
||||||
@ -146,6 +172,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(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the logs that the fix has finished.
|
// Send the logs that the fix has finished.
|
||||||
@ -159,4 +188,8 @@ export class FixRolesOnReady extends Listener {
|
|||||||
logChannel.send(finishMessage);
|
logChannel.send(finishMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private delay(ms: number) {
|
||||||
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ 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,6 +44,7 @@ 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