Unfinished, do not pull.
This commit is contained in:
+163
-80
@@ -1,13 +1,16 @@
|
||||
const { EmbedBuilder, ApplicationCommandType, AttachmentBuilder } = require('discord.js');
|
||||
const { dangercordcheckVerification } = require('../../functions/dangerCordUtils.js');
|
||||
const { createCanvas } = require('canvas');
|
||||
const GuildSettings = require('../../database/models/GuildSettings');
|
||||
const cfg = require('../../config/config.js');
|
||||
const { moderationUtilities } = require('../../functions/utils.js');
|
||||
|
||||
module.exports = {
|
||||
name: 'verify',
|
||||
description: 'To verify yourself.',
|
||||
type: ApplicationCommandType.ChatInput,
|
||||
run: async (client, interaction) => {
|
||||
const guildSettings = await GuildSettings.findOne({ guildId: interaction.guild.id });
|
||||
await interaction.deferReply({ ephemeral: true });
|
||||
const guildId = interaction.guild.id;
|
||||
|
||||
@@ -16,7 +19,7 @@ module.exports = {
|
||||
var upchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
var lowchars = "abcdefghijklmnopqrstuvwxyz";
|
||||
var nums = "0123456789";
|
||||
|
||||
|
||||
var captcha = "";
|
||||
|
||||
for (var i = 0; i < count; i++) {
|
||||
@@ -98,7 +101,7 @@ module.exports = {
|
||||
return interaction.editReply({ content: cfg.messages.wrongChannel, ephemeral: true })
|
||||
}
|
||||
|
||||
if (await client.db.get(`settings-${guildId}.verification`) === false) {
|
||||
if (guildSettings?.verifyEnabled === false || !guildSettings?.verifyEnabled) {
|
||||
return interaction.editReply({ content: cfg.messages.verifyDisabled, ephemeral: true })
|
||||
}
|
||||
|
||||
@@ -113,98 +116,178 @@ module.exports = {
|
||||
|
||||
async function verifyUser(captcha) {
|
||||
attempts++;
|
||||
if (attempts > maxAttempts) {
|
||||
await interaction.user.send(cfg.messages.maxAttemptsExceeded);
|
||||
return;
|
||||
switch (attempts) {
|
||||
case attempts > maxAttempts:
|
||||
await interaction.user.send(cfg.messages.maxAttemptsExceeded);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (attempts == 1) {
|
||||
// Check the Dangercord API using our custom library function
|
||||
/*
|
||||
if (attempts > maxAttempts) {
|
||||
await interaction.user.send(cfg.messages.maxAttemptsExceeded);
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
const captcha = await generateCaptcha(cfg.captchaCount);
|
||||
|
||||
switch (attempts) {
|
||||
case 1:
|
||||
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);
|
||||
});
|
||||
switch (result) {
|
||||
case 1: {
|
||||
console.log(`${interaction.user.id} is not blacklisted at dangercord, lets 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`);
|
||||
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);
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
});
|
||||
}
|
||||
|
||||
if (blacklisted == true) return
|
||||
|
||||
const buff = await createCaptcha(captcha);
|
||||
const attachment = new AttachmentBuilder(buff, { name: 'captcha.png' });
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle("Captcha Verification")
|
||||
.setDescription(`Please type the captcha below. You have ${cfg.captchaTimeout / 1000} seconds to respond. Attempt ${attempts}/${maxAttempts}`)
|
||||
.setColor('Green')
|
||||
.setImage('attachment://captcha.png')
|
||||
.setTimestamp();
|
||||
|
||||
await interaction.user.send({
|
||||
embeds: [embed], files: [attachment]
|
||||
}).then(async (msg) => {
|
||||
await interaction.editReply({ content: cfg.messages.toVerify, ephemeral: true });
|
||||
const filter = m => !m.author.bot && m.author.id === interaction.user.id && m.channel.id === msg.channel.id;
|
||||
const collector = msg.channel.createMessageCollector({
|
||||
filter,
|
||||
time: cfg.captchaTimeout
|
||||
});
|
||||
|
||||
collector.on('collect', async (m) => {
|
||||
//if member left the server before the verification is done
|
||||
if (!interaction.guild.members.cache.has(interaction.user.id)) {
|
||||
await interaction.user.send(cfg.messages.userLeft);
|
||||
collector.stop();
|
||||
}
|
||||
/*
|
||||
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 {
|
||||
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();
|
||||
}
|
||||
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);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
collector.on('end', async (collected, reason) => {
|
||||
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);
|
||||
await verifyUser(newCaptcha);
|
||||
}
|
||||
});
|
||||
}).catch(async (err) => {
|
||||
await interaction.editReply({
|
||||
content: cfg.messages.unableToDM,
|
||||
ephemeral: true
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
});
|
||||
}
|
||||
*/
|
||||
|
||||
if (blacklisted == true) return
|
||||
|
||||
const buff = await createCaptcha(captcha);
|
||||
const attachment = new AttachmentBuilder(buff, { name: 'captcha.png' });
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle("Captcha Verification")
|
||||
.setDescription(`Please type the captcha below. You have ${cfg.captchaTimeout / 1000} seconds to respond. Attempt ${attempts}/${maxAttempts}`)
|
||||
.setColor('Green')
|
||||
.setImage('attachment://captcha.png')
|
||||
.setTimestamp();
|
||||
|
||||
await interaction.user.send({
|
||||
embeds: [embed], files: [attachment]
|
||||
}).then(async (msg) => {
|
||||
await interaction.editReply({ content: cfg.messages.toVerify, ephemeral: true });
|
||||
const filter = m => !m.author.bot && m.author.id === interaction.user.id && m.channel.id === msg.channel.id;
|
||||
const collector = msg.channel.createMessageCollector({
|
||||
filter,
|
||||
time: cfg.captchaTimeout
|
||||
});
|
||||
|
||||
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: {
|
||||
await interaction.user.send(cfg.messages.userLeft);
|
||||
collector.stop();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
switch (m.content === captcha) {
|
||||
case true: {
|
||||
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: {
|
||||
// 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:
|
||||
await interaction.user.send(cfg.messages.tookTooLong);
|
||||
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
|
||||
const newCaptcha = await generateCaptcha(cfg.captchaCount);
|
||||
await verifyUser(newCaptcha);
|
||||
}
|
||||
*/
|
||||
});
|
||||
}).catch(async (err) => {
|
||||
await interaction.editReply({
|
||||
content: cfg.messages.unableToDM,
|
||||
ephemeral: true
|
||||
});
|
||||
});
|
||||
|
||||
const captcha = await generateCaptcha(cfg.captchaCount);
|
||||
verifyUser(captcha);
|
||||
}
|
||||
}
|
||||
@@ -216,4 +299,4 @@ Canvas is driving me nuts due to how hard to work with it.
|
||||
Had to StackOverFlow-ed it to get it to work.
|
||||
I'm not sure if this is the best way to do it but it works.
|
||||
Big shoutout to StackOverFlow and the people I got the code from.
|
||||
*/
|
||||
*/
|
||||
Reference in New Issue
Block a user