mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-08 06:03:04 -04:00
Error message for ocr, fix attachment lookup
This commit is contained in:
parent
c384cb8022
commit
2ea818f30f
3 changed files with 15 additions and 6 deletions
|
@ -18,7 +18,7 @@ module.exports = {
|
||||||
const { message } = args;
|
const { message } = args;
|
||||||
|
|
||||||
let attachment = getMessageAttachment(message)
|
let attachment = getMessageAttachment(message)
|
||||||
if(attachment && validateAttachment(attachment)){
|
if(attachment && validateAttachment(attachment, "image")){
|
||||||
attachment = attachment.url
|
attachment = attachment.url
|
||||||
} else {
|
} else {
|
||||||
delete attachment;
|
delete attachment;
|
||||||
|
@ -27,12 +27,14 @@ module.exports = {
|
||||||
|
|
||||||
let ocr = await googleVisionOcr(context, attachment)
|
let ocr = await googleVisionOcr(context, attachment)
|
||||||
|
|
||||||
|
if(ocr.response.body.text.length == 0) return context.editOrRespond({ embeds: [createEmbed("warning", context, "No text detected.")], flags: MessageFlags.EPHEMERAL })
|
||||||
|
|
||||||
await context.editOrRespond({
|
await context.editOrRespond({
|
||||||
embeds: [createEmbed("default", context, {
|
embeds: [createEmbed("default", context, {
|
||||||
thumbnail: {
|
thumbnail: {
|
||||||
url: attachment
|
url: attachment
|
||||||
},
|
},
|
||||||
description: codeblock("ansi", [ocr.response.body.text]),
|
description: codeblock("ansi", ["" + ocr.response.body.text]),
|
||||||
footer: {
|
footer: {
|
||||||
iconUrl: STATICS.google,
|
iconUrl: STATICS.google,
|
||||||
text: `Google Cloud Vision • ${context.application.name} • Took ${ocr.timings}s`
|
text: `Google Cloud Vision • ${context.application.name} • Took ${ocr.timings}s`
|
||||||
|
|
|
@ -18,7 +18,12 @@ module.exports = {
|
||||||
let image = await getRecentImage(context, 50)
|
let image = await getRecentImage(context, 50)
|
||||||
if (!image) return editOrReply(context, { embeds: [createEmbed("warning", context, "No images found.")] })
|
if (!image) return editOrReply(context, { embeds: [createEmbed("warning", context, "No images found.")] })
|
||||||
|
|
||||||
|
console.log(image)
|
||||||
|
|
||||||
let ocr = await googleVisionOcr(context, image)
|
let ocr = await googleVisionOcr(context, image)
|
||||||
|
|
||||||
|
if(ocr.response.body.text.length == 0) return editOrReply(context, { embeds: [createEmbed("warning", context, "No text detected.")] })
|
||||||
|
|
||||||
return editOrReply(context, createEmbed("default", context, {
|
return editOrReply(context, createEmbed("default", context, {
|
||||||
thumbnail: {
|
thumbnail: {
|
||||||
url: image
|
url: image
|
||||||
|
|
|
@ -85,10 +85,12 @@ module.exports.getRecentVideo = async function(context, limit) {
|
||||||
return attachments;
|
return attachments;
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateAttachment(attachment){
|
function validateAttachment(attachment, type){
|
||||||
if (attachment.contentType && attachmentTypes.image.includes(attachment.contentType)) { // discord attachment
|
console.log(attachment)
|
||||||
|
let allowedTypes = attachmentTypes[type]
|
||||||
|
if (attachment.contentType && allowedTypes.includes(attachment.contentType)) { // discord attachment
|
||||||
return true
|
return true
|
||||||
} else if (!attachment.content_type) { // other form of media
|
} else if (!attachment.contentType) { // other form of media
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
|
@ -102,7 +104,7 @@ module.exports.getRecentImage = async function(context, limit){
|
||||||
|
|
||||||
let at;
|
let at;
|
||||||
for (const a of attachments) {
|
for (const a of attachments) {
|
||||||
if(validateAttachment(a) && at === undefined) at = a.url
|
if(validateAttachment(a, "image") && at === undefined) at = a.url
|
||||||
}
|
}
|
||||||
return at;
|
return at;
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue