Move QR code decoding to c++ module
This commit is contained in:
parent
7a13431dfa
commit
a11fee5ff1
8 changed files with 78 additions and 487 deletions
|
@ -1,10 +1,10 @@
|
|||
const qrcode = require("qrcode");
|
||||
const stream = require("stream");
|
||||
const { PassThrough } = require("stream");
|
||||
|
||||
exports.run = async (message, args, content) => {
|
||||
if (args.length === 0) return `${message.author.mention}, you need to provide some text to generate a QR code!`;
|
||||
message.channel.sendTyping();
|
||||
const writable = new stream.PassThrough();
|
||||
const writable = new PassThrough();
|
||||
qrcode.toFileStream(writable, content, { margin: 1 });
|
||||
const file = await streamToBuf(writable);
|
||||
return {
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
const jsqr = require("jsqr");
|
||||
const sharp = require("sharp");
|
||||
const magick = require("../build/Release/image.node");
|
||||
const { promisify } = require("util");
|
||||
|
||||
exports.run = async (message) => {
|
||||
const image = await require("../utils/imagedetect.js")(message);
|
||||
if (image === undefined) return `${message.author.mention}, you need to provide an image with a QR code to read!`;
|
||||
message.channel.sendTyping();
|
||||
const rawData = await sharp(image.path).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
||||
const qrBuffer = jsqr(rawData.data, rawData.info.width, rawData.info.height);
|
||||
if (!qrBuffer) return `${message.author.mention}, I couldn't find a QR code!`;
|
||||
return `\`\`\`\n${qrBuffer.data}\n\`\`\``;
|
||||
const {qrText, missing} = await promisify(magick.qrread)(image.path);
|
||||
if (missing) return `${message.author.mention}, I couldn't find a QR code!`;
|
||||
return `\`\`\`\n${qrText}\n\`\`\``;
|
||||
};
|
||||
|
||||
exports.category = 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue