Advertisement
Guest User

Verification Captcha

a guest
Oct 7th, 2019
1,089
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { randomBytes } = require("crypto");
  2. const Jimp = require("jimp");
  3. const { RichEmbed } = require("discord.js");
  4. const Discord = require("discord.js");
  5.  
  6. const command = require("../config.json")
  7.  
  8.   // Check if command is enabled
  9.  if (command.enabled === false) return message.reply("⛔ | This command has been disabled.");
  10.  
  11.  
  12.  
  13. module.exports = async function(message) {
  14.           let verifyChannel = message.guild.channels.find("name", "verify");
  15.      if(!verifyChannel) return message.channel.send(`<@${message.guild.owner.id}>` + " Couldn't find the verification channel, please create a channel named ``verify`` before your members ccan use this command");
  16.      if (!message.guild.roles.exists("name", "Verified")) return message.channel.send(`<@${message.guild.owner.id}>` + " You need to create a ``Verified`` role before your members can use this command");
  17.      if (!message.channel.name(`verify`)) {
  18.     const embed = new Discord.RichEmbed()
  19.     .setColor(0x00AE86)
  20.     .addField(`:shrug: Whoops That's Not Right :shrug:`, `You can't use this command outside of the ``verify`` channel.`)
  21.     message.channel.send({ embed: embed });
  22.     return
  23.     }
  24.  
  25.     if (message.args.length === 0) {
  26.         // No arguments provided
  27.  
  28.         const captcha = randomBytes(32).toString("hex").substr(0, 6);
  29.         const font = await Jimp.loadFont(Jimp.FONT_SANS_64_BLACK);
  30.         const image = await Jimp.read("./assets/noise.jpg");
  31.         image.print(font, 0, 0, captcha);
  32.  
  33.         const buffer = await image.getBufferAsync(Jimp.MIME_JPEG);
  34.         const embed = new RichEmbed()
  35.             .setTitle("Verification")
  36.             .setColor(0x36393f)
  37.             .setDescription("Please solve this captcha by sending `" + this.config.prefix + "verify [code]` in " + verifyChannel + " ")
  38.             .attachFile({ attachment: buffer, name: "captcha.jpeg" })
  39.             .setImage("attachment://captcha.jpeg");
  40.         message.author.send(embed).catch(() => {
  41.             message.reply("⛔ | Could not send captcha, maybe you have Direct Messages disabled?");
  42.         });
  43.  
  44.         this.query.set(message.author.id, captcha);
  45.  
  46.     } else {
  47.         // Arguments provided
  48.         if (!this.query.has(message.author.id)) return message.reply("⛔ | Please request a captcha by sending `" + this.config.prefix + "verify`");
  49.  
  50.         const captcha = this.query.get(message.author.id);
  51.         let verifyRole = message.guild.roles.find('name', `Verified`);
  52.  
  53.  
  54.         if (message.args[0] !== captcha) return message.reply("⛔ | Invalid captcha!");
  55.         else {
  56.             message.member.addRole(verifyRole).then(() => {
  57.                 message.reply("✅ | Successfully verified.");
  58.             }).catch(console.error);
  59.             this.query.delete(message.author.id);
  60.         }
  61.  
  62.     }
  63. };
  64.  
  65. module.exports.info = {
  66.     description: "Used to receive a captcha or to use it",
  67.     args: [
  68.         { required: false, description: "The captcha code", name: "captcha" }
  69.     ]
  70. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement