Revert qrcreate/qrread removal

The impact wasn't too bad in retrospect
This commit is contained in:
Essem 2022-01-12 19:47:36 -06:00
parent 382a7b0298
commit 64462f2202
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
4 changed files with 1508 additions and 1449 deletions

View file

@ -0,0 +1,37 @@
import qrcode from "qrcode";
import { PassThrough } from "stream";
import Command from "../../classes/command.js";
class QrCreateCommand extends Command {
async run() {
if (this.args.length === 0) return "You need to provide some text to generate a QR code!";
this.client.sendChannelTyping(this.message.channel.id);
const writable = new PassThrough();
qrcode.toFileStream(writable, this.content, { margin: 1 });
const file = await this.streamToBuf(writable);
return {
file: file,
name: "qr.png"
};
}
streamToBuf(stream) {
return new Promise((resolve, reject) => {
const chunks = [];
stream.on("data", (chunk) => {
chunks.push(chunk);
});
stream.once("error", (error) => {
reject(error);
});
stream.once("end", () => {
resolve(Buffer.concat(chunks));
});
});
}
static description = "Generates a QR code";
static arguments = ["[text]"];
}
export default QrCreateCommand;

View file

@ -0,0 +1,23 @@
import jsqr from "jsqr";
import fetch from "node-fetch";
import sharp from "sharp";
import { clean } from "../../utils/misc.js";
import Command from "../../classes/command.js";
import imageDetect from "../../utils/imagedetect.js";
class QrReadCommand extends Command {
async run() {
const image = await imageDetect(this.client, this.message);
if (image === undefined) return "You need to provide an image with a QR code to read!";
this.client.sendChannelTyping(this.message.channel.id);
const data = await (await fetch(image.path)).buffer();
const rawData = await sharp(data).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
const qrBuffer = jsqr(rawData.data, rawData.info.width, rawData.info.height);
if (!qrBuffer) return "I couldn't find a QR code!";
return `\`\`\`\n${await clean(qrBuffer.data)}\n\`\`\``;
}
static description = "Reads a QR code";
}
export default QrReadCommand;

2894
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -33,10 +33,13 @@
"eris-fleet": "github:esmBot/eris-fleet#master", "eris-fleet": "github:esmBot/eris-fleet#master",
"file-type": "^16.1.0", "file-type": "^16.1.0",
"format-duration": "^1.4.0", "format-duration": "^1.4.0",
"jsqr": "^1.3.1",
"lavacord": "^1.1.9", "lavacord": "^1.1.9",
"node-addon-api": "^4.2.0", "node-addon-api": "^4.2.0",
"node-emoji": "^1.10.0", "node-emoji": "^1.10.0",
"node-fetch": "^3.1.0", "node-fetch": "^3.1.0",
"qrcode": "^1.4.4",
"sharp": "^0.28.2",
"winston": "^3.3.3" "winston": "^3.3.3"
}, },
"devDependencies": { "devDependencies": {