Switch case makeover (probably pretty (I think (hopefully)))

This commit is contained in:
Nahokey
2024-04-28 19:39:26 +00:00
parent 3f332f7eb1
commit 365cdfb327
+24 -87
View File
@@ -116,21 +116,13 @@ module.exports = {
async function verifyUser(captcha) {
attempts++;
switch (attempts) {
case attempts > maxAttempts:
const isExceeded = attempts > maxAttempts;
switch (isExceeded) {
case true:
await interaction.user.send(cfg.messages.maxAttemptsExceeded);
return;
}
}
/*
if (attempts > maxAttempts) {
await interaction.user.send(cfg.messages.maxAttemptsExceeded);
return;
}
*/
const captcha = await generateCaptcha(cfg.captchaCount);
switch (attempts) {
case 1:
@@ -138,13 +130,12 @@ module.exports = {
.then(result => {
console.log('Verification result:', result);
switch (result) {
case 1: {
console.log(`${interaction.user.id} is not blacklisted at dangercord, lets continue with the verification process`)
case 1:
console.log(`${interaction.user.id} is not blacklisted at DangerCord, let's continue with the verification process`)
// Proceed with further actions
break;
}
default: {
console.log(`${interaction.user.id} is blacklisted at dangercord, we will not continue with the verification process`);
default:
console.log(`${interaction.user.id} is blacklisted at DangerCord, we will not continue with the verification process`);
blacklisted = true; // Set blacklisted to true
// Handle the case when user is blacklisted
interaction.editReply({
@@ -155,44 +146,11 @@ module.exports = {
return;
}).catch(error => {
console.error('Error:', error);
});
})
break;
}
}
})
.catch(error => {
console.error('Error:', error);
});
}
/*
if (attempts == 1) {
// Check the Dangercord API using our custom library function
await dangercordcheckVerification(interaction.user.id)
.then(result => {
console.log('Verification result:', result);
if (result === 1) {
console.log(`${interaction.user.id} is not blacklisted at dangercord, lets continue with the verification process`)
// Proceed with further actions
} else {
console.log(`${interaction.user.id} is blacklisted at dangercord, we will not continue with the verification process`);
blacklisted = true; // Set blacklisted to true
// Handle the case when user is blacklisted
interaction.editReply({
content: cfg.messages.cannotContinue,
ephemeral: true
}).then(() => {
// Stop execution here
return;
}).catch(error => {
console.error('Error:', error);
});
}
})
.catch(error => {
console.error('Error:', error);
});
}
*/
if (blacklisted == true) return
@@ -218,68 +176,45 @@ module.exports = {
collector.on('collect', async (m) => {
//if member left the server before the verification is done
switch (!interaction.guild.members.cache.has(interaction.user.id)) {
case true: {
switch (interaction.guild.members.cache.has(interaction.user.id)) {
case false:
await interaction.user.send(cfg.messages.userLeft);
collector.stop();
break;
}
default: {
switch (m.content === captcha) {
case true: {
case true:
switch (m.content) {
case captcha:
validated = true;
await interaction.member.roles.add(cfg.guilds[guildId].roleToAdd);
await interaction.member.roles.remove(cfg.guilds[guildId].firstRole);
await interaction.user.send(cfg.messages.success);
return;
}
default: {
default:
// If the content doesn't match captcha
collector.stop();
break;
}
}
}
}
});
/*
if (!interaction.guild.members.cache.has(interaction.user.id)) {
await interaction.user.send(cfg.messages.userLeft);
collector.stop();
} else {
if (m.content === captcha) {
validated = true;
await interaction.member.roles.add(cfg.guilds[guildId].roleToAdd);
await interaction.member.roles.remove(cfg.guilds[guildId].firstRole);
await interaction.user.send(cfg.messages.success);
return
} else {
// If the content doesn't match captcha
collector.stop();
}
}
*/
collector.on('end', async (collected, reason) => {
switch (reason) {
case 'time':
switch (validated) {
case false: case null:
case false:
await interaction.user.send(cfg.messages.tookTooLong);
break;
case true:
break;
}
break;
case
}
/*
if (reason === 'time' && !validated) { // Send timeout message only if not already validated
await interaction.user.send(cfg.messages.tookTooLong);
} else if (!validated) {
// Only generate a new captcha and attempt verification if attempts < maxAttempts
default:
switch (validated) {
case false:
const newCaptcha = await generateCaptcha(cfg.captchaCount);
await verifyUser(newCaptcha);
}
*/
}
});
}).catch(async (err) => {
await interaction.editReply({
@@ -287,7 +222,9 @@ module.exports = {
ephemeral: true
});
});
}
const captcha = await generateCaptcha(cfg.captchaCount);
verifyUser(captcha);
}
}