diff --git a/README.md b/README.md index 2a954b92..1089cc93 100644 --- a/README.md +++ b/README.md @@ -1187,8 +1187,6 @@ Total: 518 - [ImageMagick](https://imagemagick.org/index.php) (Image Manipulation) * **communist:** - [PNGFuel](https://www.pngfuel.com/) ([Image](https://www.pngfuel.com/free-png/osnol)) -* **create-qr-code:** - - [goQR.me](http://goqr.me/) ([QR code API](http://goqr.me/api/)) * **dexter:** - [Pokémon](https://www.pokemon.com/us/) (Image, Original Anime) * **emboss:** diff --git a/commands/edit-image/create-qr-code.js b/commands/edit-image/create-qr-code.js index cb1d9135..18dc7795 100644 --- a/commands/edit-image/create-qr-code.js +++ b/commands/edit-image/create-qr-code.js @@ -1,5 +1,6 @@ const Command = require('../../framework/Command'); -const request = require('node-superfetch'); +const { createCanvas } = require('@napi-rs/canvas'); +const { encodeQR } = require('qr'); module.exports = class CreateQRCodeCommand extends Command { constructor(client) { @@ -8,14 +9,6 @@ module.exports = class CreateQRCodeCommand extends Command { aliases: ['create-qr'], group: 'edit-image', description: 'Converts text to a QR Code.', - credit: [ - { - name: 'goQR.me', - url: 'http://goqr.me/', - reason: 'QR code API', - reasonURL: 'http://goqr.me/api/' - } - ], args: [ { key: 'text', @@ -26,9 +19,26 @@ module.exports = class CreateQRCodeCommand extends Command { } async run(msg, { text }) { - const { body } = await request - .get('https://api.qrserver.com/v1/create-qr-code/') - .query({ data: text }); - return msg.say({ files: [{ attachment: body, name: 'qr-code.png' }] }); + const qr = this.createQRCode(text); + return msg.say({ files: [{ attachment: qr, name: 'qr-code.png' }] }); + } + + createQRCode(text) { + const qr = encodeQR(text, 'raw'); + const size = qr.length; + const scale = 10; + const canvas = createCanvas(size * scale, size * scale); + const ctx = canvas.getContext('2d'); + ctx.fillStyle = 'white'; + ctx.fillRect(0, 0, canvas.width, canvas.height); + ctx.fillStyle = 'black'; + for (let y = 0; y < size; y++) { + for (let x = 0; x < size; x++) { + if (qr[y][x]) { + ctx.fillRect(x * scale, y * scale, scale, scale); + } + } + } + return canvas.toBuffer('image/png'); } }; diff --git a/package.json b/package.json index 6780b73d..638a0d96 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "155.2.0", + "version": "155.2.1", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {