mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-08 06:03:04 -04:00
41 lines
No EOL
1.4 KiB
JavaScript
41 lines
No EOL
1.4 KiB
JavaScript
const { googleVisionLabels } = require("../../../labscore/api");
|
||
const { getRecentImage } = require("../../../labscore/utils/attachment");
|
||
const { createEmbed } = require("../../../labscore/utils/embed");
|
||
const { pill } = require("../../../labscore/utils/markdown");
|
||
const { editOrReply } = require("../../../labscore/utils/message");
|
||
const { STATICS } = require("../../../labscore/utils/statics");
|
||
|
||
module.exports = {
|
||
name: 'labels',
|
||
metadata: {
|
||
description: 'Applies labels to an image based on its visual contents.',
|
||
description_short: 'Image content label detection',
|
||
examples: ['labels'],
|
||
category: 'utils',
|
||
usage: 'labels <attachment>'
|
||
},
|
||
run: async (context) => {
|
||
context.triggerTyping();
|
||
let image = await getRecentImage(context, 50)
|
||
if (!image) return editOrReply(context, { embeds: [createEmbed("warning", context, "No images found.")] })
|
||
|
||
let label = await googleVisionLabels(context, image)
|
||
|
||
let labels = []
|
||
for(const l of label.response.body.labels){
|
||
labels.push(pill(`${l.score.toString().substr(2,2)}.${l.score.toString().substr(3,1)}%`) + ' ' + pill(l.name))
|
||
}
|
||
return editOrReply(context, {
|
||
embeds: [createEmbed("default", context, {
|
||
description: labels.join('\n'),
|
||
thumbnail: {
|
||
url: image
|
||
},
|
||
footer: {
|
||
iconUrl: STATICS.google,
|
||
text: `Google Cloud Vision • ${context.application.name}`
|
||
}
|
||
})]
|
||
})
|
||
},
|
||
}; |