Created
April 24, 2022 19:39
-
-
Save LighteningCode/3607d326a4bdbd9e9af6540f5220c3b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// msg.hasMedo | |
if (msg.hasMedia) { | |
// impor at the top of file | |
// import Tesseract from 'tesseract.js'; | |
// pic | |
const messageMedia = await msg.downloadMedia() | |
// check if media is png or jpeg | |
if (messageMedia.mimetype === "image/jpeg" || messageMedia.mimetype === "image/png") { | |
// OCR to get text let a = recognize() | |
Tesseract.recognize( | |
messageMedia.data, | |
'eng', | |
{ logger: m => console.log(m) } | |
).then(async ({ data: { text } }) => { | |
console.log(text); | |
// make a request to api | |
const isFactual = await axios.post("https://api.chucknorris.io/jokes/random", { text: text }) | |
// {"categories":[],"created_at":"2020-01-05 13:42:20.568859","icon_url":"https://assets.chucknorris.host/img/avatar/chuck-norris.png","id":"8RyVauXsSLmVYxyRAy9dmA","updated_at":"2020-01-05 13:42:20.568859","url":"https://api.chucknorris.io/jokes/8RyVauXsSLmVYxyRAy9dmA","value":"Chuck Norris once ordered a Big Mac at a police stop... and fucking well got it."} | |
// response wil tell if its a correct fact or not | |
msg.reply(isFactual.data.value) | |
}) | |
}else{ | |
msg.reply("Only JPEG and PNG allowed") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment