mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-05-19 08:34:15 +02:00
feat(verify): add checks on startup
This commit is contained in:
parent
bb19a17522
commit
24afe3c4b2
@ -137,7 +137,7 @@ class VerificationJoinVCListener extends Listener {
|
||||
this.container.tasks.create('verifyTimeout', {
|
||||
channelId: channel.id,
|
||||
userId: member.id,
|
||||
}, 30_000);
|
||||
}, 30_000); // TODO change before production to 15 mins
|
||||
}
|
||||
|
||||
// Check how many voice channels there are
|
||||
@ -148,7 +148,7 @@ class VerificationJoinVCListener extends Listener {
|
||||
if (!verifier) {
|
||||
const verificationText = await guild.channels.create(`✅┃${member.displayName}-verification`, {
|
||||
type: 'GUILD_TEXT',
|
||||
topic: `Channel for verifiers only. ${member.id} (Please do not change this)`,
|
||||
topic: `Channel for verifiers only. ${member.id} ${channel.id} (Please do not change this)`,
|
||||
parent: category.id,
|
||||
userLimit: 1,
|
||||
permissionOverwrites: [
|
||||
|
@ -73,7 +73,6 @@ class VerificationLeaveVCListener extends Listener {
|
||||
// Allow more people to join VC if there are less than 10 VCs
|
||||
|
||||
if (!verifier) {
|
||||
console.log(userSnowflake);
|
||||
const user = guild.members.cache.get(userSnowflake!)!;
|
||||
|
||||
// Remove verify as vegan and give non vegan role
|
||||
@ -88,7 +87,7 @@ class VerificationLeaveVCListener extends Listener {
|
||||
// Counts the recent times they have incomplete verifications
|
||||
const incompleteCount = await countIncomplete(user.id) % (leaveBan + 1);
|
||||
// Creates the length of the time for the ban
|
||||
const banLength = fibonacci(incompleteCount) * 10000; // * 3600 commented because development
|
||||
const banLength = fibonacci(incompleteCount) * 10000; // TODO * 3600 commented because development
|
||||
|
||||
// @ts-ignore
|
||||
this.container.tasks.create('verifyUnblock', {
|
||||
|
111
src/listeners/verification/start.ts
Normal file
111
src/listeners/verification/start.ts
Normal file
@ -0,0 +1,111 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
/*
|
||||
Animal Rights Advocates Discord Bot
|
||||
Copyright (C) 2022 Anthony Berg
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Listener } from '@sapphire/framework';
|
||||
import type {
|
||||
Client,
|
||||
CategoryChannel,
|
||||
TextChannel,
|
||||
VoiceChannel,
|
||||
} from 'discord.js';
|
||||
import IDs from '../../utils/ids';
|
||||
|
||||
class VerificationReady extends Listener {
|
||||
public constructor(context: Listener.Context, options: Listener.Options) {
|
||||
super(context, {
|
||||
...options,
|
||||
once: true,
|
||||
event: 'ready',
|
||||
});
|
||||
}
|
||||
|
||||
public async run(client: Client) {
|
||||
// Get verification category
|
||||
let category = client.channels.cache.get(IDs.categories.verification) as CategoryChannel | undefined;
|
||||
if (category === undefined) {
|
||||
category = await client.channels.fetch(IDs.categories.verification) as CategoryChannel | undefined;
|
||||
if (category === undefined) {
|
||||
console.error('verifyStart: Channel not found');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Check how many voice channels there are
|
||||
let voiceChannels = category.children.filter((c) => c.type === 'GUILD_VOICE');
|
||||
const emptyVC: string[] = [];
|
||||
// Delete voice channels
|
||||
voiceChannels.forEach((c) => {
|
||||
const voiceChannel = c as VoiceChannel;
|
||||
if (voiceChannel.members.size === 0) {
|
||||
emptyVC.push(voiceChannel.id);
|
||||
voiceChannel.delete();
|
||||
}
|
||||
});
|
||||
|
||||
// Delete text channels
|
||||
const textChannels = category.children.filter((c) => c.type === 'GUILD_TEXT');
|
||||
textChannels.forEach((c) => {
|
||||
const textChannel = c as TextChannel;
|
||||
// Checks if the channel topic has the user's snowflake
|
||||
emptyVC.forEach((snowflake) => {
|
||||
if (textChannel.topic!.includes(snowflake)) {
|
||||
textChannel.delete();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Check if there is no voice channels, create verification
|
||||
voiceChannels = category.children.filter((c) => c.type === 'GUILD_VOICE');
|
||||
if (voiceChannels.size === emptyVC.length) {
|
||||
await category.guild.channels.create('Verification', {
|
||||
type: 'GUILD_VOICE',
|
||||
parent: IDs.categories.verification,
|
||||
userLimit: 1,
|
||||
permissionOverwrites: [
|
||||
{
|
||||
id: category.guild.roles.everyone,
|
||||
deny: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
|
||||
},
|
||||
{
|
||||
id: IDs.roles.verifyBlock,
|
||||
deny: ['VIEW_CHANNEL', 'CONNECT', 'SEND_MESSAGES'],
|
||||
},
|
||||
{
|
||||
id: IDs.roles.nonvegan.nonvegan,
|
||||
allow: ['VIEW_CHANNEL'],
|
||||
},
|
||||
{
|
||||
id: IDs.roles.vegan.vegan,
|
||||
allow: ['VIEW_CHANNEL'],
|
||||
},
|
||||
{
|
||||
id: IDs.roles.vegan.activist,
|
||||
deny: ['VIEW_CHANNEL', 'CONNECT'],
|
||||
},
|
||||
{
|
||||
id: IDs.roles.staff.verifier,
|
||||
allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default VerificationReady;
|
Loading…
x
Reference in New Issue
Block a user