Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const CountingChannel = require(`${process.cwd()}/src/database/CountingChannel.js`);
- const { createCanvas, loadImage } = require('canvas');
- let activeCounts = {};
- client.on('messageCreate', async (message) => {
- if (message.author.bot) return;
- const guildId = message.guild.id;
- const countingData = await CountingChannel.findOne({ guildId });
- if (!countingData || message.channel.id !== countingData.countingChannelId) return;
- const nextCount = countingData.lastCount + 1;
- if (countingData.imageVerificationActive) {
- return message.reply(`An image verification is currently active. Please solve it to continue counting.`);
- }
- const messageContent = message.content.trim();
- if (/^\d+(\+|\-|\*|\/)\d+$/.test(messageContent)) {
- try {
- const mathResult = eval(messageContent);
- if (mathResult === nextCount && message.author.id !== countingData.lastUserId) {
- activeCounts[guildId] = { lastCount: nextCount, expectedNumber: nextCount, verificationActive: false };
- await CountingChannel.findOneAndUpdate(
- { guildId },
- { lastCount: nextCount, lastUserId: message.author.id }
- );
- message.react('β ');
- if (nextCount % 100 === 0) {
- const milestoneEmbed = new EmbedBuilder()
- .setColor('#FFD700')
- .setAuthor({ name: `π Milestone Reached!`, iconURL: message.guild.iconURL() })
- .setDescription(`**Congratulations! The count has reached ${nextCount}! Keep it going!**`)
- .setFooter({ text: 'Counting | Powered by CubeCloud', iconURL: client.user.displayAvatarURL() })
- .setTimestamp();
- message.channel.send({ embeds: [milestoneEmbed] });
- message.react('π');
- }
- }
- } catch (err) {
- return;
- }
- } else if (message.content === nextCount.toString() && message.author.id !== countingData.lastUserId) {
- activeCounts[guildId] = { lastCount: nextCount, expectedNumber: nextCount, verificationActive: false };
- await CountingChannel.findOneAndUpdate(
- { guildId },
- { lastCount: nextCount, lastUserId: message.author.id }
- );
- message.react('β ');
- } else {
- const captchaKey = Math.floor(Math.random() * 9000) + 1000;
- const incorrectCaptcha1 = Math.floor(Math.random() * 9000) + 1000;
- const incorrectCaptcha2 = Math.floor(Math.random() * 9000) + 1000;
- const choices = [captchaKey, incorrectCaptcha1, incorrectCaptcha2];
- const shuffledChoices = choices.sort(() => Math.random() - 0.5);
- const canvas = createCanvas(500, 200);
- const ctx = canvas.getContext('2d');
- const background = await loadImage('https://i.imgur.com/kA8vjHa.jpeg');
- ctx.drawImage(background, 0, 0, canvas.width, canvas.height);
- const gradient = ctx.createLinearGradient(0, 0, canvas.width, 0);
- gradient.addColorStop(0, '#ffffff');
- gradient.addColorStop(1, '#0000ff');
- ctx.fillStyle = gradient;
- ctx.font = '30px Arial';
- ctx.fillText(`What is the number shown in the image?`, 50, 50);
- ctx.fillStyle = gradient;
- ctx.font = '40px Arial';
- ctx.fillText(captchaKey, 200, 150);
- const attachment = new AttachmentBuilder(canvas.toBuffer(), { name: `captcha-${message.member.id}.png` });
- const verificationEmbed = new EmbedBuilder()
- .setColor('#FF0000')
- .setAuthor({ name: 'β Incorrect Count! Solve the Image Verification', iconURL: client.user.displayAvatarURL() })
- .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?**`)
- .setImage('attachment://captcha-${message.member.id}.png')
- .setFooter({ text: 'Counting | Powered by CubeCloud', iconURL: client.user.displayAvatarURL() })
- .setTimestamp();
- const nextButton = new ActionRowBuilder().addComponents(
- new ButtonBuilder()
- .setCustomId(`captcha-${shuffledChoices[0]}`)
- .setLabel(`${shuffledChoices[0]}`)
- .setStyle(ButtonStyle.Primary),
- new ButtonBuilder()
- .setCustomId(`captcha-${shuffledChoices[1]}`)
- .setLabel(`${shuffledChoices[1]}`)
- .setStyle(ButtonStyle.Secondary),
- new ButtonBuilder()
- .setCustomId(`captcha-${shuffledChoices[2]}`)
- .setLabel(`${shuffledChoices[2]}`)
- .setStyle(ButtonStyle.Danger)
- );
- const imageQuestionMessage = await message.channel.send({
- embeds: [verificationEmbed],
- files: [attachment],
- components: [nextButton],
- });
- activeCounts[guildId] = { lastCount: countingData.lastCount, expectedNumber: nextCount, verificationActive: true };
- const filter = (interaction) => interaction.user.id === message.author.id && interaction.isButton();
- const collector = message.channel.createMessageComponentCollector({ filter, time: 60000 });
- collector.on('collect', async (interaction) => {
- const selectedCaptcha = interaction.customId.split('-')[1];
- if (selectedCaptcha === captchaKey.toString()) {
- activeCounts[guildId] = { lastCount: nextCount, expectedNumber: nextCount, verificationActive: false };
- await CountingChannel.findOneAndUpdate(
- { guildId },
- { lastCount: nextCount, lastUserId: interaction.user.id }
- );
- interaction.reply(`β Correct! You've saved the count at ${nextCount}. Continue from here!`);
- await imageQuestionMessage.delete();
- message.react('β ');
- } else {
- interaction.reply(`β Incorrect CAPTCHA. Try again by selecting the correct number.`);
- message.react('β');
- const saveEmbed = new EmbedBuilder()
- .setColor('#FF0000')
- .setAuthor({ name: 'β Save the Count', iconURL: client.user.displayAvatarURL() })
- .setDescription(`**You have selected the wrong CAPTCHA number. The count has been reset to ${nextCount}.**`)
- .setFooter({ text: 'Counting | Powered by CubeCloud', iconURL: client.user.displayAvatarURL() })
- .setTimestamp();
- message.channel.send({ embeds: [saveEmbed] });
- }
- });
- collector.on('end', async (_, reason) => {
- if (reason === 'time') {
- activeCounts[guildId] = { lastCount: countingData.lastCount, expectedNumber: nextCount, verificationActive: false };
- const timeoutEmbed = new EmbedBuilder()
- .setColor('#FF0000')
- .setAuthor({ name: 'β Verification Timeout', iconURL: client.user.displayAvatarURL() })
- .setDescription('The counting system has been reset due to no response or incorrect input. Please enter the next correct count to resume.')
- .setFooter({ text: 'Counting | Powered by CubeCloud', iconURL: client.user.displayAvatarURL() })
- .setTimestamp();
- await imageQuestionMessage.delete();
- message.channel.send({ embeds: [timeoutEmbed] });
- }
- });
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement