diff --git a/src/listeners/verification/joinVC.ts b/src/listeners/verification/joinVC.ts index 000a0b4..0dd6c36 100644 --- a/src/listeners/verification/joinVC.ts +++ b/src/listeners/verification/joinVC.ts @@ -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: [ diff --git a/src/listeners/verification/leaveVC.ts b/src/listeners/verification/leaveVC.ts index 0675291..392f34e 100644 --- a/src/listeners/verification/leaveVC.ts +++ b/src/listeners/verification/leaveVC.ts @@ -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', { diff --git a/src/listeners/verification/start.ts b/src/listeners/verification/start.ts new file mode 100644 index 0000000..2410702 --- /dev/null +++ b/src/listeners/verification/start.ts @@ -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 . +*/ + +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;