mrmBot-Matrix/commands/qrcreate.js

26 lines
764 B
JavaScript
Raw Normal View History

2019-09-13 20:02:41 +00:00
const qrcode = require("qrcode");
const stream = require("stream");
exports.run = async (message, args, content) => {
2019-09-13 20:02:41 +00:00
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();
qrcode.toFileStream(writable, content, { margin: 1 });
2019-09-13 20:02:41 +00:00
const chunks = [];
writable.on("data", (chunk) => {
chunks.push(chunk);
});
writable.once("error", (error) => {
if (error) throw error;
2019-09-13 20:02:41 +00:00
});
writable.once("end", () => {
return message.channel.createMessage("", {
file: Buffer.concat(chunks),
2019-09-13 20:02:41 +00:00
name: "qr.png"
});
});
};
exports.category = 1;
exports.help = "Generates a QR code";
exports.params = "[text]";