feat(verification): add a check if the joinable vc will be deleted

This commit is contained in:
Anthony 2022-08-08 01:59:07 +01:00
parent 0ebf6af089
commit e4cb0bdfdc
2 changed files with 37 additions and 11 deletions

View File

@ -64,10 +64,10 @@ export class VerificationJoinVCListener extends Listener {
const currentChannel = guild.channels.cache.get(newState.channel.id) as VoiceChannel;
// Check if the user has the verifiers role
if (newState.member?.roles.cache.has('999431675123597406')) {
await channel.setName('Verifiers Only');
if (newState.member?.roles.cache.has('999431675123597406')) { // TODO add check if they are trial-verifiers
await channel.setName('Verifier Meeting');
} else {
await channel.setName(`Verification - ${newState.member?.displayName}`);
await channel.setName(`${newState.member?.displayName} - Verification`);
await currentChannel.send(`Hiya ${newState.member?.user}, please be patient as a verifier has been called out to verify you.\n\nIf you leave this voice channel, you will automatically be given the non-vegan role where you gain access to this server and if you'd like to verify as a vegan again, you'd have to contact a Mod, which could be done via ModMail.`);
}
@ -77,7 +77,6 @@ export class VerificationJoinVCListener extends Listener {
// Create a new channel for others to join
// TODO add a global max size
// Checks if there are more than 10 voice channels
if (listVoiceChannels.size > maxVCs - 1) {
await guild.channels.create('Verification', {

View File

@ -44,24 +44,51 @@ export class VerificationLeaveVCListener extends Listener {
const user = guild.members.cache.get(oldState.member!.id)!;
// Remove verify as vegan and give non vegan role
await user.roles.remove('999431675081666597'); // Verify-as-vegan
await user.roles.add('999431675081666598'); // Not vegan
// Delete the channel
await oldState.channel!.delete();
if (!user.roles.cache.has('999431675098447937')) { // If the user does not have vegan role
await user.roles.remove('999431675081666597'); // Verify-as-vegan
await user.roles.add('999431675081666598'); // Not vegan
}
// Check how many voice channels there are
const category = guild.channels.cache.get('999431677006860409') as CategoryChannel;
const listVoiceChannels = category.children.filter((c) => c.type === 'GUILD_VOICE');
console.log(listVoiceChannels.size);
// Check that it is not deleting the 'Verification' channel (in case bot crashes)
if (oldState.channel.name !== 'Verification') {
// Delete the channel
await oldState.channel!.delete();
}
// If there are no VCs left in verification after having the channel deleted
if (listVoiceChannels.size === 0) {
// Create a verification channel
await guild.channels.create('Verification', {
type: 'GUILD_VOICE',
parent: '999431677006860409', // Verification topic
userLimit: 1,
permissionOverwrites: [
{
id: guild.roles.everyone,
deny: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
},
{
id: '999431675081666597', // verify-as-vegan
allow: ['VIEW_CHANNEL'],
},
{
id: '999431675123597406', // Verifiers
allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
},
],
});
}
// If there are less than 10, stop
if (listVoiceChannels.size < maxVCs) {
return;
}
const verification = listVoiceChannels.last() as VoiceChannel;
console.log(verification?.name);
await verification!.permissionOverwrites.set([
{