Pre-Flight Verification check via DangerCord. Enabled API Blacklist with custom client
This commit is contained in:
@@ -24,6 +24,7 @@ module.exports = {
|
||||
'alreadyVerified': 'You are already verified.',
|
||||
'tookTooLong': 'You took too long to respond. Please try again.',
|
||||
'unableToDM': 'I was unable to send you a DM. Please make sure "Allow Direct Message" for this guild is enabled.',
|
||||
'maxAttemptsExceeded': 'You have run out of attempts!'
|
||||
'maxAttemptsExceeded': 'You have run out of attempts!',
|
||||
'cannotContinue': 'Sorry, you have been blacklisted within an abuse database and we cannot continue verification at this time.'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
async function dangercordcheckVerification(userId, accessToken) {
|
||||
const url = `https://dangercord.com/api/v1/user/${userId}`;
|
||||
const headers = {
|
||||
'Authorization': `Bearer dd._rUgw7Soro2u7SedNRGEmW0J6NkDQ8X3r`
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await fetch(url, { headers });
|
||||
const userData = await response.json();
|
||||
|
||||
// Assuming badges are always present
|
||||
const { blacklisted, whitelisted, admin } = userData.badges;
|
||||
|
||||
// Check badge status and report level
|
||||
if (blacklisted || admin) {
|
||||
return 0; // Not allowed to continue
|
||||
} else if (whitelisted) {
|
||||
return 1; // Allowed to continue
|
||||
} else {
|
||||
// Determine if report level is acceptable
|
||||
if (userData.reports <= 5 || userData.last_reported < Date.now() - (30 * 24 * 60 * 60 * 1000)) {
|
||||
return 1; // Allowed to continue
|
||||
} else {
|
||||
return 0; // Not allowed to continue
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching user data:', error);
|
||||
return 0; // Not allowed to continue on error
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { dangercordcheckVerification };
|
||||
@@ -2,6 +2,8 @@ const { EmbedBuilder, ApplicationCommandType, Collection, AttachmentBuilder } =
|
||||
const { createCanvas, loadImage } = require('canvas');
|
||||
const cfg = require('../../config/config.js');
|
||||
const captchaUser = new Collection();
|
||||
const { dangercordcheckVerification } = require('../../functions/dangercord_verificationUtils');
|
||||
|
||||
module.exports = {
|
||||
name: 'verify',
|
||||
description: 'To verify yourself.',
|
||||
@@ -35,36 +37,36 @@ module.exports = {
|
||||
async function createCaptcha(captcha) {
|
||||
const canvas = createCanvas(200, 75);
|
||||
const ctx = canvas.getContext('2d');
|
||||
|
||||
|
||||
// Background color
|
||||
ctx.fillStyle = '#000000';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
|
||||
// Text
|
||||
ctx.font = '30px Arial';
|
||||
ctx.textBaseline = 'middle';
|
||||
ctx.textAlign = 'center';
|
||||
ctx.fillStyle = '#ffffff';
|
||||
|
||||
|
||||
// Calculate spacing between characters to fit within canvas width
|
||||
const charWidth = 30;
|
||||
const totalWidth = captcha.length * charWidth;
|
||||
const startX = (canvas.width - totalWidth) / 2;
|
||||
|
||||
|
||||
// Draw each character with random y-offset
|
||||
for (let i = 0; i < captcha.length; i++) {
|
||||
const x = startX + i * charWidth + charWidth / 2; // Adjust x-position for each character
|
||||
const y = 37.5 + Math.random() * 30 - 15; // Random y-offset
|
||||
ctx.fillText(captcha[i], x, y);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Adding noise
|
||||
for (let i = 0; i < 50; i++) {
|
||||
ctx.fillStyle = `rgba(255,255,255,${Math.random() * 0.9})`;
|
||||
ctx.fillRect(Math.random() * canvas.width, Math.random() * canvas.height, 1, 1);
|
||||
}
|
||||
|
||||
|
||||
// Adding white lines
|
||||
for (let i = 0; i < 30; i++) {
|
||||
ctx.strokeStyle = `rgba(255,255,255,${Math.random() * 1.8})`;
|
||||
@@ -73,7 +75,7 @@ module.exports = {
|
||||
ctx.lineTo(Math.random() * canvas.width, Math.random() * canvas.height);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
|
||||
// Adding blue lines
|
||||
for (let i = 0; i < 30; i++) {
|
||||
ctx.strokeStyle = `rgba(0, 0, 255, ${Math.random() * 0.9})`;
|
||||
@@ -82,17 +84,17 @@ module.exports = {
|
||||
ctx.lineTo(Math.random() * canvas.width, Math.random() * canvas.height);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
|
||||
// Rotation
|
||||
const rotation = Math.random() * 0.2 - 0.1; // Random rotation between -0.1 and 0.1 radians
|
||||
ctx.translate(canvas.width / 2, canvas.height / 2);
|
||||
ctx.rotate(rotation);
|
||||
ctx.translate(-canvas.width / 2, -canvas.height / 2);
|
||||
|
||||
|
||||
const buffer = canvas.toBuffer('image/png');
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (interaction.channel.id !== cfg.guilds[guildId].channelId) {
|
||||
return interaction.reply({ content: cfg.messages.wrongChannel, ephemeral: true })
|
||||
@@ -106,13 +108,41 @@ module.exports = {
|
||||
const maxAttempts = cfg.maxAttempts;
|
||||
let validated = false; // Flag to track if user is already validated
|
||||
|
||||
|
||||
|
||||
|
||||
async function verifyUser(captcha) {
|
||||
|
||||
attempts++;
|
||||
if (attempts > maxAttempts) {
|
||||
await interaction.user.send(cfg.messages.maxAttemptsExceeded);
|
||||
return;
|
||||
}
|
||||
|
||||
if (attempts == 1 ){
|
||||
// Check the Dangercord API using our custom library function
|
||||
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`)
|
||||
} else {
|
||||
(async () => {
|
||||
await interaction.reply({
|
||||
content: cfg.messages.cannotContinue,
|
||||
ephemeral: true
|
||||
});
|
||||
})();
|
||||
console.log(`${interaction.user.id} is blacklisted at dangercord, we will not continue with the verification process`)
|
||||
return;
|
||||
}
|
||||
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
});
|
||||
}
|
||||
|
||||
const buff = await createCaptcha(captcha);
|
||||
const attachment = new AttachmentBuilder(buff, { name: 'captcha.png' });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user