pissbot-9000/commands/message/google/labels.js

43 lines
No EOL
1.4 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const { googleVisionLabels } = require("#api");
const { PERMISSION_GROUPS } = require("#constants");
const { getRecentImage } = require("#utils/attachment");
const { createEmbed } = require("#utils/embed");
const { acknowledge } = require("#utils/interactions");
const { pill, smallPill } = require("#utils/markdown");
const { editOrReply } = require("#utils/message");
const { STATICS } = require("#utils/statics");
module.exports = {
name: 'labels',
metadata: {
description: 'Applies labels to an image based on its visual contents.',
description_short: 'Image content label detection',
category: 'utils',
usage: 'labels <attachment>'
},
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)
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}`
}
}))
},
};