Fix readqr

This commit is contained in:
lilyissillyyy
2025-09-06 00:16:00 -04:00
parent deb42234b9
commit d012ce7185
6 changed files with 29 additions and 18 deletions
+1 -1
View File
@@ -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}**.`);
}
};
+1 -1
View File
@@ -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}**.`);
}
};
+1 -1
View File
@@ -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.`);
}
};
+24 -14
View File
@@ -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);
});
}
};
+1 -1
View File
@@ -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) {
+1
View File
@@ -70,6 +70,7 @@
"ntcjs": "^1.1.3",
"parse-domain": "^8.2.2",
"pokersolver": "^2.1.4",
"qrcode-reader": "^1.0.4",
"random-js": "^2.1.0",
"sagiri": "^4.3.0",
"semver": "^7.7.2",