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) { async function verifyUser(captcha) {
attempts++; attempts++;
switch (attempts) { const isExceeded = attempts > maxAttempts;
case attempts > maxAttempts:
switch (isExceeded) {
case true:
await interaction.user.send(cfg.messages.maxAttemptsExceeded); await interaction.user.send(cfg.messages.maxAttemptsExceeded);
return; return;
} }
}
/*
if (attempts > maxAttempts) {
await interaction.user.send(cfg.messages.maxAttemptsExceeded);
return;
}
*/
const captcha = await generateCaptcha(cfg.captchaCount);
switch (attempts) { switch (attempts) {
case 1: case 1:
@@ -138,13 +130,12 @@ module.exports = {
.then(result => { .then(result => {
console.log('Verification result:', result); console.log('Verification result:', result);
switch (result) { switch (result) {
case 1: { case 1:
console.log(`${interaction.user.id} is not blacklisted at dangercord, lets continue with the verification process`) console.log(`${interaction.user.id} is not blacklisted at DangerCord, let's continue with the verification process`)
// Proceed with further actions // Proceed with further actions
break; break;
} default:
default: { console.log(`${interaction.user.id} is blacklisted at DangerCord, we will not continue with the verification process`);
console.log(`${interaction.user.id} is blacklisted at dangercord, we will not continue with the verification process`);
blacklisted = true; // Set blacklisted to true blacklisted = true; // Set blacklisted to true
// Handle the case when user is blacklisted // Handle the case when user is blacklisted
interaction.editReply({ interaction.editReply({
@@ -155,44 +146,11 @@ module.exports = {
return; return;
}).catch(error => { }).catch(error => {
console.error('Error:', error); console.error('Error:', error);
}); })
break; 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 if (blacklisted == true) return
@@ -218,68 +176,45 @@ module.exports = {
collector.on('collect', async (m) => { collector.on('collect', async (m) => {
//if member left the server before the verification is done //if member left the server before the verification is done
switch (!interaction.guild.members.cache.has(interaction.user.id)) { switch (interaction.guild.members.cache.has(interaction.user.id)) {
case true: { case false:
await interaction.user.send(cfg.messages.userLeft); await interaction.user.send(cfg.messages.userLeft);
collector.stop(); collector.stop();
break; break;
} case true:
default: { switch (m.content) {
switch (m.content === captcha) { case captcha:
case true: {
validated = true; validated = true;
await interaction.member.roles.add(cfg.guilds[guildId].roleToAdd); await interaction.member.roles.add(cfg.guilds[guildId].roleToAdd);
await interaction.member.roles.remove(cfg.guilds[guildId].firstRole); await interaction.member.roles.remove(cfg.guilds[guildId].firstRole);
await interaction.user.send(cfg.messages.success); await interaction.user.send(cfg.messages.success);
return; return;
} default:
default: {
// If the content doesn't match captcha // If the content doesn't match captcha
collector.stop(); collector.stop();
break; 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) => { collector.on('end', async (collected, reason) => {
switch (reason) { switch (reason) {
case 'time': case 'time':
switch (validated) { switch (validated) {
case false: case null: case false:
await interaction.user.send(cfg.messages.tookTooLong); await interaction.user.send(cfg.messages.tookTooLong);
break; break;
case true:
break;
} }
break; break;
case default:
} switch (validated) {
/* case false:
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
const newCaptcha = await generateCaptcha(cfg.captchaCount); const newCaptcha = await generateCaptcha(cfg.captchaCount);
await verifyUser(newCaptcha); await verifyUser(newCaptcha);
} }
*/ }
}); });
}).catch(async (err) => { }).catch(async (err) => {
await interaction.editReply({ await interaction.editReply({
@@ -287,7 +222,9 @@ module.exports = {
ephemeral: true ephemeral: true
}); });
}); });
}
const captcha = await generateCaptcha(cfg.captchaCount);
verifyUser(captcha); verifyUser(captcha);
} }
} }