mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-07 13:43:06 -04:00
fix error if labels are unavailable (for whatever reason)
This commit is contained in:
parent
8657b8c93b
commit
91c7a6850c
1 changed files with 25 additions and 17 deletions
|
@ -19,25 +19,33 @@ module.exports = {
|
|||
permissionsClient: [...PERMISSION_GROUPS.baseline],
|
||||
run: async (context) => {
|
||||
await acknowledge(context);
|
||||
|
||||
let image = await getRecentImage(context, 50)
|
||||
if (!image) return editOrReply(context, createEmbed("warning", context, "No images found."))
|
||||
|
||||
let label = await googleVisionLabels(context, image)
|
||||
try{
|
||||
let image = await getRecentImage(context, 50)
|
||||
if (!image) return editOrReply(context, createEmbed("warning", context, "No images found."))
|
||||
|
||||
let labels = []
|
||||
for (const l of label.response.body.labels) {
|
||||
labels.push(smallPill(`${l.score.toString().substr(2, 2)}.${l.score.toString().substr(3, 1)}%`) + ' ' + pill(l.name))
|
||||
}
|
||||
return editOrReply(context, createEmbed("default", context, {
|
||||
description: labels.join('\n'),
|
||||
thumbnail: {
|
||||
url: image
|
||||
},
|
||||
footer: {
|
||||
iconUrl: STATICS.googlelens,
|
||||
text: `Google Lens • ${context.application.name}`
|
||||
let label = await googleVisionLabels(context, image)
|
||||
|
||||
let labels = []
|
||||
for (const l of label.response.body.labels) {
|
||||
labels.push(smallPill(`${l.score.toString().substr(2, 2)}.${l.score.toString().substr(3, 1)}%`) + ' ' + pill(l.name))
|
||||
}
|
||||
}))
|
||||
return editOrReply(context, createEmbed("default", context, {
|
||||
description: labels.join('\n'),
|
||||
thumbnail: {
|
||||
url: image
|
||||
},
|
||||
footer: {
|
||||
iconUrl: STATICS.googlelens,
|
||||
text: `Google Lens • ${context.application.name}`
|
||||
}
|
||||
}))
|
||||
}catch(e){
|
||||
console.error(e);
|
||||
if(e.response?.body?.message)
|
||||
return editOrReply(context, createEmbed(e.response.body.status === 1 ? "warning": "error", context, e.response.body.message))
|
||||
|
||||
return editOrReply(context, createEmbed("error", context, "Unable to get labels for this image."))
|
||||
}
|
||||
},
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue