mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Move create QR away from API
This commit is contained in:
@@ -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:**
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
};
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "155.2.0",
|
||||
"version": "155.2.1",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user