fix error if labels are unavailable (for whatever reason)

This commit is contained in:
bignutty 2025-03-03 14:21:04 +01:00
parent 8657b8c93b
commit 91c7a6850c

View file

@ -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."))
}
},
};