Removed qrcreate/qrread
This commit is contained in:
parent
a80355bced
commit
1b4348fcb3
4 changed files with 385 additions and 981 deletions
|
@ -1,37 +0,0 @@
|
|||
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;
|
|
@ -1,23 +0,0 @@
|
|||
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;
|
1303
package-lock.json
generated
1303
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -33,13 +33,10 @@
|
|||
"eris-fleet": "github:esmBot/eris-fleet",
|
||||
"file-type": "^16.1.0",
|
||||
"format-duration": "^1.4.0",
|
||||
"jsqr": "^1.3.1",
|
||||
"lavacord": "^1.1.9",
|
||||
"node-addon-api": "^3.2.1",
|
||||
"node-emoji": "^1.10.0",
|
||||
"node-fetch": "^2.6.1",
|
||||
"qrcode": "^1.4.4",
|
||||
"sharp": "^0.28.2",
|
||||
"winston": "^3.3.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
Loading…
Reference in a new issue