mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-24 02:15:10 +02:00
Fix readqr
This commit is contained in:
@@ -21,6 +21,6 @@ module.exports = class GenerationCommand extends Command {
|
|||||||
|
|
||||||
run(msg, { year }) {
|
run(msg, { year }) {
|
||||||
const generation = generations.find(gen => gen.start <= year && (gen.end ? gen.end >= year : true));
|
const generation = generations.find(gen => gen.start <= year && (gen.end ? gen.end >= year : true));
|
||||||
return msg.say(`Someone born in ${year} is part of: **${generation.name}**`);
|
return msg.say(`Someone born in ${year} is part of **${generation.name}**.`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -25,6 +25,6 @@ module.exports = class ImageSizeCommand extends Command {
|
|||||||
async run(msg, { image }) {
|
async run(msg, { image }) {
|
||||||
const { body } = await request.get(image);
|
const { body } = await request.get(image);
|
||||||
const data = await loadImage(body);
|
const data = await loadImage(body);
|
||||||
return msg.reply(`This image is ${data.width}x${data.height}.`);
|
return msg.reply(`This image is **${data.width}x${data.height}**.`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -35,6 +35,6 @@ module.exports = class NameGenderCommand extends Command {
|
|||||||
.query({ name });
|
.query({ name });
|
||||||
if (!body.gender) return msg.say(`I have no idea what gender ${body.name} is.`);
|
if (!body.gender) return msg.say(`I have no idea what gender ${body.name} is.`);
|
||||||
const prob = Math.round(body.probability * 100);
|
const prob = Math.round(body.probability * 100);
|
||||||
return msg.say(`I'm ${prob}% sure ${body.name} is a ${genders[body.gender]} name.`);
|
return msg.say(`I'm ${prob}% sure ${body.name} is a **${genders[body.gender]}** name.`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
const Command = require('../../framework/Command');
|
const Command = require('../../framework/Command');
|
||||||
const request = require('node-superfetch');
|
const request = require('node-superfetch');
|
||||||
|
const QrCode = require('qrcode-reader');
|
||||||
|
const { createCanvas, loadImage } = require('@napi-rs/canvas');
|
||||||
const { shorten } = require('../../util/Util');
|
const { shorten } = require('../../util/Util');
|
||||||
|
|
||||||
module.exports = class ReadQRCodeCommand extends Command {
|
module.exports = class ReadQRCodeCommand extends Command {
|
||||||
@@ -9,14 +11,6 @@ module.exports = class ReadQRCodeCommand extends Command {
|
|||||||
aliases: ['scan-qr-code', 'scan-qr', 'read-qr'],
|
aliases: ['scan-qr-code', 'scan-qr', 'read-qr'],
|
||||||
group: 'analyze',
|
group: 'analyze',
|
||||||
description: 'Reads a QR Code.',
|
description: 'Reads a QR Code.',
|
||||||
credit: [
|
|
||||||
{
|
|
||||||
name: 'goQR.me',
|
|
||||||
url: 'http://goqr.me/',
|
|
||||||
reason: 'QR code API',
|
|
||||||
reasonURL: 'http://goqr.me/api/'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
key: 'image',
|
key: 'image',
|
||||||
@@ -28,11 +22,27 @@ module.exports = class ReadQRCodeCommand extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async run(msg, { image }) {
|
async run(msg, { image }) {
|
||||||
const { body } = await request
|
const { body } = await request.get(image);
|
||||||
.get('https://api.qrserver.com/v1/read-qr-code/')
|
const img = await loadImage(body);
|
||||||
.query({ fileurl: image });
|
const canvas = createCanvas(img);
|
||||||
const data = body[0].symbol[0];
|
const ctx = canvas.getContext('2d');
|
||||||
if (!data.data) return msg.reply(`Could not read QR Code: ${data.error}.`);
|
const imgData = ctx.getImageData(0, 0, img.width, img.height);
|
||||||
return msg.reply(shorten(data.data, 2000 - (msg.author.toString().length + 2)));
|
try {
|
||||||
|
const result = await this.readQrCode(imgData);
|
||||||
|
return msg.reply(shorten(result, 2000));
|
||||||
|
} catch (err) {
|
||||||
|
return msg.reply(`Could not read QR Code: \`${err.message}\`.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
readQrCode(imgData) {
|
||||||
|
const qr = new QrCode();
|
||||||
|
return new Promise((res, rej) => {
|
||||||
|
qr.callback = (err, value) => {
|
||||||
|
if (err) return rej(err);
|
||||||
|
return res(value);
|
||||||
|
}
|
||||||
|
qr.decode(imgData);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ module.exports = class ZodiacSignCommand extends Command {
|
|||||||
run(msg, { month, day }) {
|
run(msg, { month, day }) {
|
||||||
const sign = this.determineSign(month, day);
|
const sign = this.determineSign(month, day);
|
||||||
if (!sign) return msg.reply('Invalid day.');
|
if (!sign) return msg.reply('Invalid day.');
|
||||||
return msg.say(`The Zodiac Sign for ${month}/${day} is ${sign.name}.`);
|
return msg.say(`The Zodiac Sign for ${month}/${day} is **${sign.name}**.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
determineSign(month, day) {
|
determineSign(month, day) {
|
||||||
|
|||||||
@@ -70,6 +70,7 @@
|
|||||||
"ntcjs": "^1.1.3",
|
"ntcjs": "^1.1.3",
|
||||||
"parse-domain": "^8.2.2",
|
"parse-domain": "^8.2.2",
|
||||||
"pokersolver": "^2.1.4",
|
"pokersolver": "^2.1.4",
|
||||||
|
"qrcode-reader": "^1.0.4",
|
||||||
"random-js": "^2.1.0",
|
"random-js": "^2.1.0",
|
||||||
"sagiri": "^4.3.0",
|
"sagiri": "^4.3.0",
|
||||||
"semver": "^7.7.2",
|
"semver": "^7.7.2",
|
||||||
|
|||||||
Reference in New Issue
Block a user