From c934ca400625891f0b0f227a35595d34d34bcbcb Mon Sep 17 00:00:00 2001 From: Airbus A330-200 <53490656+Airbus-A330@users.noreply.github.com> Date: Mon, 11 Apr 2022 21:15:48 -0700 Subject: [PATCH 1/2] Add .buffer prop and update discord.js example --- README.md | 18 +++++++++++------- src/index.ts | 4 ++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 98188e6..7687e08 100644 --- a/README.md +++ b/README.md @@ -64,14 +64,18 @@ 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.JPEGStream, "captcha.jpeg") - ); - let collector = msg.channel.createMessageCollector(m => m.author.id === msg.author.id); + msg.channel.send({ + content: "**Enter the text shown in the image below:**", + files: [{ + attachment: captcha.buffer, + name: "captcha.jpg" + }] + }); + let filter = m => m.author.id === msg.author.id; + let collector = msg.channel.createMessageCollector({ filter, time: 15000 }); collector.on("collect", m => { - if (m.content.toUpperCase() === captcha.value) msg.channel.send("Verified Successfully!"); - else msg.channel.send("Failed Verification!"); + if (m.content.toUpperCase() === captcha.value) msg.channel.send({ content: "Verified Successfully!" }); + else msg.channel.send({ content: "Failed Verification!" }); collector.stop(); }); } diff --git a/src/index.ts b/src/index.ts index 47f3a5d..e9c6476 100644 --- a/src/index.ts +++ b/src/index.ts @@ -141,6 +141,10 @@ class Captcha { get dataURL(): string { return this._canvas.toDataURL("image/jpeg"); } + + get buffer(): string { + return this._canvas.toBuffer(); + } } export = Captcha; From e565e64e309df4dc8a562f461034375aa7291ee6 Mon Sep 17 00:00:00 2001 From: Airbus A330-200 <53490656+Airbus-A330@users.noreply.github.com> Date: Mon, 11 Apr 2022 21:21:08 -0700 Subject: [PATCH 2/2] update type for buffer prop --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index e9c6476..aeff995 100644 --- a/src/index.ts +++ b/src/index.ts @@ -142,7 +142,7 @@ class Captcha { return this._canvas.toDataURL("image/jpeg"); } - get buffer(): string { + get buffer(): Buffer { return this._canvas.toBuffer(); } }