pissbot-9000/commands/message/google/safetylabels.js
2025-03-09 20:24:44 +01:00

47 lines
No EOL
1.7 KiB
JavaScript
Raw Permalink 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 { googleVisionSafetyLabels } = require("#api");
const { GOOGLE_CLOUD_SAFETY_LABELS, GOOGLE_CLOUD_SAFETY_LABELS_NAMES, PERMISSION_GROUPS } = require("#constants");
const { getRecentImage } = require("#utils/attachment");
const { createEmbed } = require("#utils/embed");
const { acknowledge } = require("#utils/interactions");
const { iconPill, smallPill } = require("#utils/markdown");
const { editOrReply } = require("#utils/message");
const { STATICS } = require("#utils/statics");
module.exports = {
name: 'safetylabels',
metadata: {
description: 'Applies detection labels for potentially sensitive content of an image.',
description_short: 'Sensitive content detection labels',
category: 'utils',
usage: 'safetylabels <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 googleVisionSafetyLabels(context, image)
let labels = []
for (const l of Object.keys(label.response.body.labels)) {
let rating = GOOGLE_CLOUD_SAFETY_LABELS[label.response.body.labels[l]]
labels.push([
smallPill(GOOGLE_CLOUD_SAFETY_LABELS_NAMES[l]),
iconPill(rating.icon, rating.name)
].join(' '))
}
return editOrReply(context, createEmbed("default", context, {
description: labels.join('\n'),
thumbnail: {
url: image
},
footer: {
iconUrl: STATICS.googlelens,
text: `Google Lens • ${context.application.name}`
}
}))
},
};