mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Fix readqr
This commit is contained in:
@@ -21,6 +21,6 @@ module.exports = class GenerationCommand extends Command {
|
||||
|
||||
run(msg, { year }) {
|
||||
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 }) {
|
||||
const { body } = await request.get(image);
|
||||
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 });
|
||||
if (!body.gender) return msg.say(`I have no idea what gender ${body.name} is.`);
|
||||
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 request = require('node-superfetch');
|
||||
const QrCode = require('qrcode-reader');
|
||||
const { createCanvas, loadImage } = require('@napi-rs/canvas');
|
||||
const { shorten } = require('../../util/Util');
|
||||
|
||||
module.exports = class ReadQRCodeCommand extends Command {
|
||||
@@ -9,14 +11,6 @@ module.exports = class ReadQRCodeCommand extends Command {
|
||||
aliases: ['scan-qr-code', 'scan-qr', 'read-qr'],
|
||||
group: 'analyze',
|
||||
description: 'Reads a QR Code.',
|
||||
credit: [
|
||||
{
|
||||
name: 'goQR.me',
|
||||
url: 'http://goqr.me/',
|
||||
reason: 'QR code API',
|
||||
reasonURL: 'http://goqr.me/api/'
|
||||
}
|
||||
],
|
||||
args: [
|
||||
{
|
||||
key: 'image',
|
||||
@@ -28,11 +22,27 @@ module.exports = class ReadQRCodeCommand extends Command {
|
||||
}
|
||||
|
||||
async run(msg, { image }) {
|
||||
const { body } = await request
|
||||
.get('https://api.qrserver.com/v1/read-qr-code/')
|
||||
.query({ fileurl: image });
|
||||
const data = body[0].symbol[0];
|
||||
if (!data.data) return msg.reply(`Could not read QR Code: ${data.error}.`);
|
||||
return msg.reply(shorten(data.data, 2000 - (msg.author.toString().length + 2)));
|
||||
const { body } = await request.get(image);
|
||||
const img = await loadImage(body);
|
||||
const canvas = createCanvas(img);
|
||||
const ctx = canvas.getContext('2d');
|
||||
const imgData = ctx.getImageData(0, 0, img.width, img.height);
|
||||
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 }) {
|
||||
const sign = this.determineSign(month, 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) {
|
||||
|
||||
Reference in New Issue
Block a user