Implement OCR

This commit is contained in:
Chloe Fontenot 🏳️‍⚧️ 2024-08-09 23:08:51 -05:00
parent 0667dd70d8
commit 1406378c9f

View File

@ -198,7 +198,7 @@ function getMatchingPhrase(inputString, targetCharacter) {
message.delete(); message.delete();
return true; return true;
} }
}); })();
return false; return false;
} }
if (checkLoop(message, checkString)) { if (checkLoop(message, checkString)) {
@ -209,9 +209,10 @@ function getMatchingPhrase(inputString, targetCharacter) {
(async () => { (async () => {
// Does the message have an attachment? Check the attachment with OCR // Does the message have an attachment? Check the attachment with OCR
console.log(message.attachments); console.log(message.attachments);
if (message.attachments.contentType.includes("image")) { message.attachments.forEach(i => {
if (i.contentType.includes("image")) {
const worker = await createWorker('eng'); const worker = await createWorker('eng');
const ret = await worker.recognize(message.attachments.proxyURL); const ret = await worker.recognize(i.proxyURL);
console.log("OCR Results: " + ret.data.text); console.log("OCR Results: " + ret.data.text);
checkString = ret.data.text; checkString = ret.data.text;
await worker.terminate(); await worker.terminate();
@ -222,6 +223,7 @@ function getMatchingPhrase(inputString, targetCharacter) {
checkLoop(message, checkString); checkLoop(message, checkString);
} }
})(); })();
})();
} }
/* /*
Main bot logic. Check for abbreviations by splitting the message at any non-word characters, then if we find a match, create a new array, replace the abbreviation with the phrase, then call replyMessage() and reply to the original message with the corrected one. Main bot logic. Check for abbreviations by splitting the message at any non-word characters, then if we find a match, create a new array, replace the abbreviation with the phrase, then call replyMessage() and reply to the original message with the corrected one.