Advertisement
spiralvibes

Made By ZayDocs | CubeCloud Team

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