Merging...
This commit is contained in:
@@ -15,6 +15,7 @@ module.exports = {
|
||||
'captchaCount': '7',
|
||||
'captchaTimeout': '120000', //in milliseconds (seconds multiplied by 1000)
|
||||
'maxAttempts': '3', // max attemps to verify
|
||||
'dangerCordAPIKey': 'KEYHERE', // dangercord api key here
|
||||
'messages': {
|
||||
//literally messages lmao
|
||||
'toVerify': 'Please verify that you are not a robot.',
|
||||
@@ -24,6 +25,6 @@ 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': 'Verification failed. You have run out of attempts!'
|
||||
'maxAttemptsExceeded': 'You have run out of attempts!'
|
||||
}
|
||||
}
|
||||
|
||||
+16
-1
@@ -4,4 +4,19 @@ const chalk = require('chalk');
|
||||
|
||||
client.on('ready', () => {
|
||||
console.log(chalk.green(`Logged in as ${client.user.tag}!`));
|
||||
});
|
||||
setInterval(() => {
|
||||
let activities = [
|
||||
{ type: "Playing", name: "/verify" },
|
||||
{ type: "Playing", name: "Securing our servers" },
|
||||
{ type: "Watching", name: `Watching bans...` },
|
||||
];
|
||||
|
||||
const status = activities[Math.floor(Math.random() * activities.length)];
|
||||
|
||||
if (status.type === "Watching") {
|
||||
client.user.setPresence({ activities: [{ name: `${status.name}`, type: ActivityType.Watching }] });
|
||||
} else {
|
||||
client.user.setPresence({ activities: [{ name: `${status.name}`, type: ActivityType.Playing }] });
|
||||
}
|
||||
}, 300000); // update every 5 mins
|
||||
});
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
const fetch = require('node-fetch');
|
||||
const cfg = require('../config/config.js');
|
||||
|
||||
async function dangercordcheckVerification(userId, accessToken) {
|
||||
const url = `https://dangercord.com/api/v1/user/${userId}`;
|
||||
const headers = {
|
||||
'Authorization': `Bearer ${cfg.dangerCordAPIKey}`
|
||||
};
|
||||
|
||||
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 >= 1 && userData.last_reported >= Date.now() - (30 * 24 * 60 * 60 * 1000)) {
|
||||
return 0; // Not allowed to continue
|
||||
} else {
|
||||
return 1; // Allowed to continue
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching user data:', error);
|
||||
return 0; // Not allowed to continue on error
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { dangercordcheckVerification };
|
||||
@@ -1,7 +1,8 @@
|
||||
const { EmbedBuilder, ApplicationCommandType, Collection, AttachmentBuilder } = require('discord.js');
|
||||
const { dangercordcheckVerification } = require('../../functions/dangercord_verificationUtils');
|
||||
const { createCanvas, loadImage } = require('canvas');
|
||||
const cfg = require('../../config/config.js');
|
||||
|
||||
const captchaUser = new Collection();
|
||||
module.exports = {
|
||||
name: 'verify',
|
||||
description: 'To verify yourself.',
|
||||
@@ -10,10 +11,13 @@ module.exports = {
|
||||
const guildId = interaction.guild.id;
|
||||
|
||||
async function generateCaptcha(count) {
|
||||
// Setting up the variables for generation
|
||||
var upchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
var lowchars = "abcdefghijklmnopqrstuvwxyz";
|
||||
var nums = "0123456789";
|
||||
|
||||
//get a random letter/number from upchars, lowchars, and nums
|
||||
var chars = upchars + lowchars + nums;
|
||||
var captcha = "";
|
||||
|
||||
for (var i = 0; i < count; i++) {
|
||||
@@ -33,18 +37,64 @@ 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 = 'white';
|
||||
ctx.fillText(captcha, 100, 37.5);
|
||||
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})`;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(Math.random() * canvas.width, Math.random() * canvas.height);
|
||||
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})`;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(Math.random() * canvas.width, Math.random() * canvas.height);
|
||||
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;
|
||||
}
|
||||
|
||||
await interaction.deferReply({ ephemeral: true });
|
||||
|
||||
if (interaction.channel.id !== cfg.guilds[guildId].channelId) {
|
||||
return interaction.editReply({ content: cfg.messages.wrongChannel, ephemeral: true })
|
||||
}
|
||||
@@ -54,9 +104,13 @@ module.exports = {
|
||||
}
|
||||
|
||||
let attempts = 0;
|
||||
let blacklisted = false;
|
||||
const maxAttempts = cfg.maxAttempts;
|
||||
let validated = false; // Flag to track if user is already validated
|
||||
|
||||
|
||||
|
||||
|
||||
async function verifyUser(captcha) {
|
||||
attempts++;
|
||||
if (attempts > maxAttempts) {
|
||||
@@ -64,6 +118,36 @@ module.exports = {
|
||||
return;
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
const buff = await createCaptcha(captcha);
|
||||
const attachment = new AttachmentBuilder(buff, { name: 'captcha.png' });
|
||||
|
||||
@@ -102,8 +186,8 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
collector.on('end', async (collected, reason) => {
|
||||
|
||||
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) {
|
||||
@@ -111,10 +195,9 @@ module.exports = {
|
||||
const newCaptcha = await generateCaptcha(cfg.captchaCount);
|
||||
await verifyUser(newCaptcha);
|
||||
}
|
||||
|
||||
});
|
||||
}).catch(async (err) => {
|
||||
await interaction.editReply({
|
||||
await interaction.reply({
|
||||
content: cfg.messages.unableToDM,
|
||||
ephemeral: true
|
||||
});
|
||||
@@ -122,6 +205,10 @@ module.exports = {
|
||||
}
|
||||
|
||||
const captcha = await generateCaptcha(cfg.captchaCount);
|
||||
await interaction.reply({
|
||||
content: cfg.messages.toVerify,
|
||||
ephemeral: true
|
||||
});
|
||||
verifyUser(captcha);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user