Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const CountingChannel = require(`${process.cwd()}/src/database/CountingChannel.js`);
- 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 (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('✅');
- return;
- }
- const canvas = createCanvas(800, 400);
- const ctx = canvas.getContext('2d');
- const background = await loadImage('https://i.imgur.com/0d4i1kR.jpg');
- ctx.drawImage(background, 0, 0, canvas.width, canvas.height);
- const gradient = ctx.createLinearGradient(0, 0, canvas.width, 0);
- gradient.addColorStop(0, '#0062ff');
- gradient.addColorStop(1, '#00d2ff');
- ctx.fillStyle = gradient;
- ctx.font = '45px Arial';
- ctx.fillText('Counting System', 50, 50);
- ctx.fillStyle = '#FFFFFF';
- ctx.font = '30px Arial';
- ctx.fillText(`Next Number: ${nextCount}`, 50, 150);
- const lastUser = countingData.lastUserId ? await client.users.fetch(countingData.lastUserId) : null;
- ctx.fillStyle = '#FFFFFF';
- ctx.font = '25px Arial';
- ctx.fillText(`Last User: ${lastUser ? lastUser.username : 'None'}`, 50, 200);
- ctx.fillStyle = '#FFFFFF';
- ctx.font = '25px Arial';
- ctx.fillText('Type the next number in the sequence to continue counting!', 50, 250);
- const gradientLine = ctx.createLinearGradient(0, canvas.height - 50, canvas.width, canvas.height);
- gradientLine.addColorStop(0, '#ff6347');
- gradientLine.addColorStop(1, '#32cd32');
- ctx.strokeStyle = gradientLine;
- ctx.lineWidth = 5;
- ctx.beginPath();
- ctx.moveTo(0, canvas.height - 50);
- ctx.lineTo(canvas.width, canvas.height - 50);
- ctx.stroke();
- const attachment = new AttachmentBuilder(canvas.toBuffer(), { name: 'counting-info.png' });
- const countingEmbed = new EmbedBuilder()
- .setColor('#00d2ff')
- .setAuthor({ name: 'Counting System | Continue the Sequence', iconURL: client.user.displayAvatarURL() })
- .setDescription(`**Next number: ${nextCount}**\n\n**Last User**: ${lastUser ? lastUser.username : 'None'}`)
- .setImage(`attachment://counting-info.png`)
- .setFooter({ text: 'Counting | Powered by ZayDocs', iconURL: client.user.displayAvatarURL() })
- .setTimestamp();
- const countingMessage = await message.channel.send({
- embeds: [countingEmbed],
- files: [attachment]
- });
- activeCounts[guildId] = { lastCount: countingData.lastCount, expectedNumber: nextCount, verificationActive: false };
- const row = new ActionRowBuilder().addComponents(
- new ButtonBuilder()
- .setCustomId('show_rules')
- .setLabel('Show Rules')
- .setStyle(ButtonStyle.Primary)
- );
- countingMessage.edit({
- components: [row]
- });
- const filter = (interaction) => interaction.user.id === message.author.id && interaction.isButton();
- const collector = message.channel.createMessageComponentCollector({ filter, time: 60000 });
- collector.on('collect', async (interaction) => {
- if (interaction.customId === 'show_rules') {
- const rulesCanvas = createCanvas(800, 400);
- const rulesCtx = rulesCanvas.getContext('2d');
- const rulesBackground = await loadImage('https://i.imgur.com/0d4i1kR.jpg'); // Use a different background or any image you want for the rules
- rulesCtx.drawImage(rulesBackground, 0, 0, rulesCanvas.width, rulesCanvas.height);
- const rulesGradient = rulesCtx.createLinearGradient(0, 0, rulesCanvas.width, 0);
- rulesGradient.addColorStop(0, '#ff6347');
- rulesGradient.addColorStop(1, '#32cd32');
- rulesCtx.fillStyle = rulesGradient;
- rulesCtx.font = '45px Arial';
- rulesCtx.fillText('Counting Rules', 50, 50);
- rulesCtx.fillStyle = '#FFFFFF';
- rulesCtx.font = '30px Arial';
- rulesCtx.fillText('1. Type the correct number in sequence.', 50, 100);
- rulesCtx.fillText('2. No skipping numbers or spamming.', 50, 150);
- rulesCtx.fillText('3. Be respectful of others and the bot.', 50, 200);
- const rulesAttachment = new AttachmentBuilder(rulesCanvas.toBuffer(), { name: 'rules.png' });
- const rulesEmbed = new EmbedBuilder()
- .setColor('#ff6347')
- .setTitle('Counting Game Rules')
- .setDescription('Here are the rules for the counting game!')
- .setImage('attachment://rules.png')
- .setFooter({ text: 'Counting | Powered by ZayDocs', iconURL: client.user.displayAvatarURL() })
- .setTimestamp();
- interaction.reply({
- embeds: [rulesEmbed],
- files: [rulesAttachment]
- });
- }
- });
- collector.on('end', async (_, reason) => {
- if (reason === 'time') {
- message.reply('❌ Time expired. The counting session has ended.');
- countingMessage.delete();
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement