2023-03-15 14:09:09 +00:00
|
|
|
import qrcode from "qrcode";
|
|
|
|
import { PassThrough } from "stream";
|
|
|
|
import Command from "../../classes/command.js";
|
|
|
|
|
|
|
|
class QrCreateCommand extends Command {
|
2023-03-19 05:10:48 +00:00
|
|
|
static category = "general"
|
2023-03-15 14:09:09 +00:00
|
|
|
async run() {
|
|
|
|
if (this.args.length === 0) {
|
|
|
|
this.success = false;
|
|
|
|
return "You need to provide some text to generate a QR code!";
|
|
|
|
}
|
2023-03-17 00:23:01 +00:00
|
|
|
// await this.acknowledge();
|
2023-03-15 14:09:09 +00:00
|
|
|
const writable = new PassThrough();
|
|
|
|
qrcode.toFileStream(writable, this.content, { margin: 1 });
|
|
|
|
const file = await this.streamToBuf(writable);
|
|
|
|
return {
|
|
|
|
contents: 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]"];
|
|
|
|
}
|
|
|
|
|
2022-01-13 01:47:36 +00:00
|
|
|
export default QrCreateCommand;
|