mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-26 14:19:11 +02:00
OCR Timeout
This commit is contained in:
+10
-1
@@ -1,7 +1,7 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const { createWorker } = require('tesseract.js');
|
||||
const { reactIfAble } = require('../../util/Util');
|
||||
const { LOADING_EMOJI_ID, SUCCESS_EMOJI_ID } = process.env;
|
||||
const { LOADING_EMOJI_ID, SUCCESS_EMOJI_ID, FAILURE_EMOJI_ID } = process.env;
|
||||
|
||||
module.exports = class OcrCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -32,7 +32,16 @@ module.exports = class OcrCommand extends Command {
|
||||
await worker.load();
|
||||
await worker.loadLanguage('eng');
|
||||
await worker.initialize('eng');
|
||||
let timedOut = false;
|
||||
setTimeout(async () => {
|
||||
timedOut = false;
|
||||
await worker.terminate();
|
||||
}, 30000);
|
||||
const { data: { text } } = await worker.recognize(image);
|
||||
if (timedOut) {
|
||||
await reactIfAble(res, res.author, FAILURE_EMOJI_ID, '❌');
|
||||
return msg.reply('Scanning took longer than 30 seconds, so I\'ve given up.');
|
||||
}
|
||||
await worker.terminate();
|
||||
await reactIfAble(msg, this.client.user, SUCCESS_EMOJI_ID, '✅');
|
||||
if (!text) return msg.reply('There is no text in this image.');
|
||||
|
||||
Reference in New Issue
Block a user