Advertisement
spiralvibes

Made By ZayDocs | CubeCloud Team

Nov 9th, 2024
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const CountingChannel = require(`${process.cwd()}/src/database/CountingChannel.js`);
  2. let activeCounts = {};
  3.  
  4. client.on('messageCreate', async (message) => {
  5.     if (message.author.bot) return;
  6.  
  7.     const guildId = message.guild.id;
  8.     const countingData = await CountingChannel.findOne({ guildId });
  9.  
  10.     if (!countingData || message.channel.id !== countingData.countingChannelId) return;
  11.  
  12.     const nextCount = countingData.lastCount + 1;
  13.  
  14.     if (countingData.imageVerificationActive) {
  15.         return message.reply(`An image verification is currently active. Please solve it to continue counting.`);
  16.     }
  17.  
  18.     const messageContent = message.content.trim();
  19.     if (/^\d+(\+|\-|\*|\/)\d+$/.test(messageContent)) {
  20.         try {
  21.             const mathResult = eval(messageContent);
  22.             if (mathResult === nextCount && message.author.id !== countingData.lastUserId) {
  23.                 activeCounts[guildId] = { lastCount: nextCount, expectedNumber: nextCount, verificationActive: false };
  24.  
  25.                 await CountingChannel.findOneAndUpdate(
  26.                     { guildId },
  27.                     { lastCount: nextCount, lastUserId: message.author.id }
  28.                 );
  29.  
  30.                 message.react('✅');
  31.                 return;
  32.             }
  33.         } catch (err) {
  34.             return;
  35.         }
  36.     }
  37.  
  38.     if (message.content === nextCount.toString() && message.author.id !== countingData.lastUserId) {
  39.         activeCounts[guildId] = { lastCount: nextCount, expectedNumber: nextCount, verificationActive: false };
  40.  
  41.         await CountingChannel.findOneAndUpdate(
  42.             { guildId },
  43.             { lastCount: nextCount, lastUserId: message.author.id }
  44.         );
  45.  
  46.         message.react('✅');
  47.         return;
  48.     }
  49.  
  50.     const captchaKey = Math.floor(Math.random() * 9000) + 1000;
  51.     const incorrectCaptcha1 = Math.floor(Math.random() * 9000) + 1000;
  52.     const incorrectCaptcha2 = Math.floor(Math.random() * 9000) + 1000;
  53.  
  54.     const choices = [captchaKey, incorrectCaptcha1, incorrectCaptcha2];
  55.     const shuffledChoices = choices.sort(() => Math.random() - 0.5);
  56.  
  57.     const canvas = createCanvas(500, 200);
  58.     const ctx = canvas.getContext('2d');
  59.  
  60.     const background = await loadImage('https://i.imgur.com/kA8vjHa.jpeg');
  61.     ctx.drawImage(background, 0, 0, canvas.width, canvas.height);
  62.  
  63.     const gradient = ctx.createLinearGradient(0, 0, canvas.width, 0);
  64.     gradient.addColorStop(0, '#ffffff');
  65.     gradient.addColorStop(1, '#0000ff');
  66.     ctx.fillStyle = gradient;
  67.     ctx.font = '30px Arial';
  68.     ctx.fillText(`What is the number shown in the image?`, 50, 50);
  69.  
  70.     ctx.fillStyle = gradient;
  71.     ctx.font = '40px Arial';
  72.     ctx.fillText(captchaKey, 200, 150);
  73.  
  74.     const attachment = new AttachmentBuilder(canvas.toBuffer(), { name: `captcha-${message.member.id}.png` });
  75.  
  76.     const verificationEmbed = new EmbedBuilder()
  77.         .setColor('#FF0000')
  78.         .setAuthor({ name: '❌ Incorrect Count! Solve the Image Verification', iconURL: client.user.displayAvatarURL() })
  79.         .setDescription(`**Please view the image below and select the correct number to continue counting. The next number is: ${nextCount}**\n\n**Question: What number is shown in the image?**`)
  80.         .setImage(`attachment://captcha-${message.member.id}.png`)
  81.         .setFooter({ text: 'Counting | Powered by CubeCloud', iconURL: client.user.displayAvatarURL() })
  82.         .setTimestamp();
  83.  
  84.     const nextButton = new ActionRowBuilder().addComponents(
  85.         new ButtonBuilder()
  86.             .setCustomId(`captcha-${shuffledChoices[0]}`)
  87.             .setLabel(`${shuffledChoices[0]}`)
  88.             .setStyle(ButtonStyle.Primary),
  89.         new ButtonBuilder()
  90.             .setCustomId(`captcha-${shuffledChoices[1]}`)
  91.             .setLabel(`${shuffledChoices[1]}`)
  92.             .setStyle(ButtonStyle.Secondary),
  93.         new ButtonBuilder()
  94.             .setCustomId(`captcha-${shuffledChoices[2]}`)
  95.             .setLabel(`${shuffledChoices[2]}`)
  96.             .setStyle(ButtonStyle.Danger)
  97.     );
  98.  
  99.     const imageQuestionMessage = await message.channel.send({
  100.         embeds: [verificationEmbed],
  101.         files: [attachment],
  102.         components: [nextButton],
  103.     });
  104.  
  105.     activeCounts[guildId] = { lastCount: countingData.lastCount, expectedNumber: nextCount, verificationActive: true };
  106.  
  107.     const filter = (interaction) => interaction.user.id === message.author.id && interaction.isButton();
  108.     const collector = message.channel.createMessageComponentCollector({ filter, time: 60000 });
  109.  
  110.     collector.on('collect', async (interaction) => {
  111.         const selectedCaptcha = interaction.customId.split('-')[1];
  112.         if (selectedCaptcha === captchaKey.toString()) {
  113.             activeCounts[guildId] = { lastCount: nextCount, expectedNumber: nextCount, verificationActive: false };
  114.  
  115.             await CountingChannel.findOneAndUpdate(
  116.                 { guildId },
  117.                 { lastCount: nextCount, lastUserId: interaction.user.id }
  118.             );
  119.  
  120.             interaction.reply(`✅ Correct! You've saved the count at ${nextCount}. Continue from here!`);
  121.            await imageQuestionMessage.delete();
  122.            message.react('');
  123.        } else {
  124.            interaction.reply(`❌ Incorrect CAPTCHA. Try again by selecting the correct number.`);
  125.            message.react('');
  126.            const saveEmbed = new EmbedBuilder()
  127.                .setColor('#FF0000')
  128.                .setAuthor({ name: '❌ Save the Count', iconURL: client.user.displayAvatarURL() })
  129.                .setDescription(`**You have selected the wrong CAPTCHA number. The count has been reset to ${nextCount}.**`)
  130.                .setFooter({ text: 'Counting | Powered by CubeCloud', iconURL: client.user.displayAvatarURL() })
  131.                .setTimestamp();
  132.  
  133.            message.channel.send({ embeds: [saveEmbed] });
  134.        }
  135.    });
  136.  
  137.    collector.on('end', async (_, reason) => {
  138.        if (reason === 'time') {
  139.            activeCounts[guildId] = { lastCount: countingData.lastCount, expectedNumber: nextCount, verificationActive: false };
  140.  
  141.            const timeoutEmbed = new EmbedBuilder()
  142.                .setColor('#FF0000')
  143.                .setAuthor({ name: '❌ Verification Timeout', iconURL: client.user.displayAvatarURL() })
  144.                .setDescription('The counting system has been reset due to no response or incorrect input. Please enter the next correct count to resume.')
  145.                .setFooter({ text: 'Counting | Powered by CubeCloud', iconURL: client.user.displayAvatarURL() })
  146.                .setTimestamp();
  147.  
  148.            await imageQuestionMessage.delete();
  149.            message.channel.send({ embeds: [timeoutEmbed] });
  150.        }
  151.    });
  152. });
  153.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement