JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 545
  • Score
    100M100P100Q120661F
  • License AGPL-3.0

Generate captcha images for use with bots on chat platforms

Package Exports

  • @haileybot/captcha-generator

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@haileybot/captcha-generator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

License NPM version NPM downloads FOSSA Status Dependencies PayPal Portfolio

Captcha Generator

Captcha Generator is a Node library for quickly and easily generating captcha images that can be used through an authorized bot to verify human users on a chat platform such as Slack or Discord.

Installation

Use the package manager npm to install Captcha Generator

npm i @haileybot/captcha-generator

Usage

Basic:

// Import the module
const Captcha = require("@haileybot/captcha-generator");

// Create a new Captcha object - this will contain "PNGStream" and "value"
//   - "PNGStream" is a stream of the image in PNG format
//   - "value" is the 6 character code the image contains
let captcha = new Captcha();

Save to file example:

const Captcha = require("@haileybot/captcha-generator"),
  fs = require("fs"),
  path = require("path");

let captcha = new Captcha();
captcha.PNGStream.pipe(fs.createWriteStream(path.join(__dirname, `${captcha.value}.png`)));

Discord Example:

This example assumes you already have the core framework of a Discord Bot set up

const Captcha = require("@haileybot/captcha-generator");

// Use this function for blocking certain commands or features from automated self-bots
function verifyHuman(msg) {
  let captcha = new Captcha();
  msg.channel.send(
    "**Enter the text shown in the image below:**",
    new Discord.MessageAttachment(captcha.PNGStream, "captcha.png")
  );
  let collector = msg.channel.createMessageCollector(m => m.author.id === msg.author.id);
  collector.on("collect", m => {
    if (m.content.toUpperCase() === captcha.value) msg.channel.send("Verified Successfully!");
    else msg.channel.send("Failed Verification!");
    collector.stop();
  })
}

License

This project is licensed under AGPL-3.0

FOSSA Status