Advertisement
spiralvibes

Made By ZayDocs | CubeCloud Team

Nov 9th, 2024
24
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.  
  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 (message.content === nextCount.toString() && message.author.id !== countingData.lastUserId) {
  16.         activeCounts[guildId] = { lastCount: nextCount, expectedNumber: nextCount, verificationActive: false };
  17.  
  18.         await CountingChannel.findOneAndUpdate(
  19.             { guildId },
  20.             { lastCount: nextCount, lastUserId: message.author.id }
  21.         );
  22.  
  23.         message.react('✅');
  24.         return;
  25.     }
  26.  
  27.     const canvas = createCanvas(800, 400);
  28.     const ctx = canvas.getContext('2d');
  29.  
  30.     const background = await loadImage('https://i.imgur.com/0d4i1kR.jpg');
  31.     ctx.drawImage(background, 0, 0, canvas.width, canvas.height);
  32.  
  33.     const gradient = ctx.createLinearGradient(0, 0, canvas.width, 0);
  34.     gradient.addColorStop(0, '#0062ff');
  35.     gradient.addColorStop(1, '#00d2ff');
  36.     ctx.fillStyle = gradient;
  37.     ctx.font = '45px Arial';
  38.     ctx.fillText('Counting System', 50, 50);
  39.  
  40.     ctx.fillStyle = '#FFFFFF';
  41.     ctx.font = '30px Arial';
  42.     ctx.fillText(`Next Number: ${nextCount}`, 50, 150);
  43.  
  44.     const lastUser = countingData.lastUserId ? await client.users.fetch(countingData.lastUserId) : null;
  45.     ctx.fillStyle = '#FFFFFF';
  46.     ctx.font = '25px Arial';
  47.     ctx.fillText(`Last User: ${lastUser ? lastUser.username : 'None'}`, 50, 200);
  48.  
  49.     ctx.fillStyle = '#FFFFFF';
  50.     ctx.font = '25px Arial';
  51.     ctx.fillText('Type the next number in the sequence to continue counting!', 50, 250);
  52.  
  53.     const gradientLine = ctx.createLinearGradient(0, canvas.height - 50, canvas.width, canvas.height);
  54.     gradientLine.addColorStop(0, '#ff6347');
  55.     gradientLine.addColorStop(1, '#32cd32');
  56.     ctx.strokeStyle = gradientLine;
  57.     ctx.lineWidth = 5;
  58.     ctx.beginPath();
  59.     ctx.moveTo(0, canvas.height - 50);
  60.     ctx.lineTo(canvas.width, canvas.height - 50);
  61.     ctx.stroke();
  62.  
  63.     const attachment = new AttachmentBuilder(canvas.toBuffer(), { name: 'counting-info.png' });
  64.  
  65.     const countingEmbed = new EmbedBuilder()
  66.         .setColor('#00d2ff')
  67.         .setAuthor({ name: 'Counting System | Continue the Sequence', iconURL: client.user.displayAvatarURL() })
  68.         .setDescription(`**Next number: ${nextCount}**\n\n**Last User**: ${lastUser ? lastUser.username : 'None'}`)
  69.         .setImage(`attachment://counting-info.png`)
  70.         .setFooter({ text: 'Counting | Powered by ZayDocs', iconURL: client.user.displayAvatarURL() })
  71.         .setTimestamp();
  72.  
  73.     const countingMessage = await message.channel.send({
  74.         embeds: [countingEmbed],
  75.         files: [attachment]
  76.     });
  77.  
  78.     activeCounts[guildId] = { lastCount: countingData.lastCount, expectedNumber: nextCount, verificationActive: false };
  79.  
  80.     const row = new ActionRowBuilder().addComponents(
  81.         new ButtonBuilder()
  82.             .setCustomId('show_rules')
  83.             .setLabel('Show Rules')
  84.             .setStyle(ButtonStyle.Primary)
  85.     );
  86.  
  87.     countingMessage.edit({
  88.         components: [row]
  89.     });
  90.  
  91.     const filter = (interaction) => interaction.user.id === message.author.id && interaction.isButton();
  92.     const collector = message.channel.createMessageComponentCollector({ filter, time: 60000 });
  93.  
  94.     collector.on('collect', async (interaction) => {
  95.         if (interaction.customId === 'show_rules') {
  96.             const rulesCanvas = createCanvas(800, 400);
  97.             const rulesCtx = rulesCanvas.getContext('2d');
  98.  
  99.             const rulesBackground = await loadImage('https://i.imgur.com/0d4i1kR.jpg');  // Use a different background or any image you want for the rules
  100.             rulesCtx.drawImage(rulesBackground, 0, 0, rulesCanvas.width, rulesCanvas.height);
  101.  
  102.             const rulesGradient = rulesCtx.createLinearGradient(0, 0, rulesCanvas.width, 0);
  103.             rulesGradient.addColorStop(0, '#ff6347');
  104.             rulesGradient.addColorStop(1, '#32cd32');
  105.             rulesCtx.fillStyle = rulesGradient;
  106.             rulesCtx.font = '45px Arial';
  107.             rulesCtx.fillText('Counting Rules', 50, 50);
  108.  
  109.             rulesCtx.fillStyle = '#FFFFFF';
  110.             rulesCtx.font = '30px Arial';
  111.             rulesCtx.fillText('1. Type the correct number in sequence.', 50, 100);
  112.             rulesCtx.fillText('2. No skipping numbers or spamming.', 50, 150);
  113.             rulesCtx.fillText('3. Be respectful of others and the bot.', 50, 200);
  114.  
  115.             const rulesAttachment = new AttachmentBuilder(rulesCanvas.toBuffer(), { name: 'rules.png' });
  116.  
  117.             const rulesEmbed = new EmbedBuilder()
  118.                 .setColor('#ff6347')
  119.                 .setTitle('Counting Game Rules')
  120.                 .setDescription('Here are the rules for the counting game!')
  121.                 .setImage('attachment://rules.png')
  122.                 .setFooter({ text: 'Counting | Powered by ZayDocs', iconURL: client.user.displayAvatarURL() })
  123.                 .setTimestamp();
  124.  
  125.             interaction.reply({
  126.                 embeds: [rulesEmbed],
  127.                 files: [rulesAttachment]
  128.             });
  129.         }
  130.     });
  131.  
  132.     collector.on('end', async (_, reason) => {
  133.         if (reason === 'time') {
  134.             message.reply('❌ Time expired. The counting session has ended.');
  135.             countingMessage.delete();
  136.         }
  137.     });
  138. });
  139.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement