Adding in a more complex captcha with noise and random generated lines
This commit is contained in:
@@ -35,16 +35,44 @@ module.exports = {
|
|||||||
async function createCaptcha(captcha) {
|
async function createCaptcha(captcha) {
|
||||||
const canvas = createCanvas(200, 75);
|
const canvas = createCanvas(200, 75);
|
||||||
const ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
||||||
|
|
||||||
|
// Background color
|
||||||
|
ctx.fillStyle = '#000000';
|
||||||
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||||
|
|
||||||
|
// Text
|
||||||
ctx.font = '30px Arial';
|
ctx.font = '30px Arial';
|
||||||
ctx.textBaseline = 'middle';
|
ctx.textBaseline = 'middle';
|
||||||
ctx.textAlign = 'center';
|
ctx.textAlign = 'center';
|
||||||
ctx.fillStyle = 'white';
|
ctx.fillStyle = '#ffffff';
|
||||||
ctx.fillText(captcha, 100, 37.5);
|
ctx.fillText(captcha, 100, 37.5);
|
||||||
|
|
||||||
|
// 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 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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');
|
const buffer = canvas.toBuffer('image/png');
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (interaction.channel.id !== cfg.guilds[guildId].channelId) {
|
if (interaction.channel.id !== cfg.guilds[guildId].channelId) {
|
||||||
return interaction.reply({ content: cfg.messages.wrongChannel, ephemeral: true })
|
return interaction.reply({ content: cfg.messages.wrongChannel, ephemeral: true })
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user