diff --git a/commands/message/google/labels.js b/commands/message/google/labels.js index 947801c..528db91 100644 --- a/commands/message/google/labels.js +++ b/commands/message/google/labels.js @@ -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.")) + } }, }; \ No newline at end of file