Clear OCR Timeout

This commit is contained in:
Dragon Fire
2021-03-18 17:34:56 -04:00
parent 902bd0f1f5
commit ac4813b710
+4 -1
View File
@@ -33,7 +33,9 @@ module.exports = class OcrCommand extends Command {
await worker.loadLanguage('eng');
await worker.initialize('eng');
let timedOut = false;
setTimeout(async () => {
let finished = false;
const timeout = setTimeout(async () => {
if (finished) return;
timedOut = true;
await worker.terminate();
await reactIfAble(msg, msg.author, FAILURE_EMOJI_ID, '❌');
@@ -41,6 +43,7 @@ module.exports = class OcrCommand extends Command {
}, 30000);
const { data: { text } } = await worker.recognize(image);
if (timedOut) return null;
clearTimeout(timeout);
await worker.terminate();
await reactIfAble(msg, this.client.user, SUCCESS_EMOJI_ID, '✅');
if (!text) return msg.reply('There is no text in this image.');