mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-09 14:43:05 -04:00
[cmd] labels, safetylabels
This commit is contained in:
parent
e3bfaa8803
commit
7395d7d096
2 changed files with 88 additions and 0 deletions
44
commands/message/google/labels.js
Normal file
44
commands/message/google/labels.js
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
const { googleVisionLabels } = require("../../../labscore/api");
|
||||||
|
const { getRecentImage } = require("../../../labscore/utils/attachment");
|
||||||
|
const { createEmbed } = require("../../../labscore/utils/embed");
|
||||||
|
const { codeblock } = require("../../../labscore/utils/markdown");
|
||||||
|
const { editOrReply } = require("../../../labscore/utils/message");
|
||||||
|
const { STATICS } = require("../../../labscore/utils/statics");
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'labels',
|
||||||
|
metadata: {
|
||||||
|
description: 'Image Labelling',
|
||||||
|
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({
|
||||||
|
name: l.name,
|
||||||
|
value: `${l.score.toString().substr(2,2)}.${l.score.toString().substr(3,1)}%`,
|
||||||
|
inline: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return editOrReply(context, {
|
||||||
|
embeds: [createEmbed("default", context, {
|
||||||
|
fields: labels,
|
||||||
|
thumbnail: {
|
||||||
|
url: image
|
||||||
|
},
|
||||||
|
footer: {
|
||||||
|
iconUrl: STATICS.google,
|
||||||
|
text: `Google Cloud Vision • ${context.application.name} • Took ${label.timings}s`
|
||||||
|
}
|
||||||
|
})]
|
||||||
|
})
|
||||||
|
},
|
||||||
|
};
|
44
commands/message/google/safetylabels.js
Normal file
44
commands/message/google/safetylabels.js
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
const { googleVisionSafetyLabels } = require("../../../labscore/api");
|
||||||
|
const { getRecentImage } = require("../../../labscore/utils/attachment");
|
||||||
|
const { createEmbed } = require("../../../labscore/utils/embed");
|
||||||
|
const { codeblock } = require("../../../labscore/utils/markdown");
|
||||||
|
const { editOrReply } = require("../../../labscore/utils/message");
|
||||||
|
const { STATICS } = require("../../../labscore/utils/statics");
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'safetylabels',
|
||||||
|
metadata: {
|
||||||
|
description: 'Image Safe Search Labels',
|
||||||
|
examples: ['labels'],
|
||||||
|
category: 'utils',
|
||||||
|
usage: 'safetylabels <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 googleVisionSafetyLabels(context, image)
|
||||||
|
|
||||||
|
let labels = []
|
||||||
|
for(const l of Object.keys(label.response.body.labels)){
|
||||||
|
labels.push({
|
||||||
|
name: l.charAt(0).toUpperCase() + l.slice(1),
|
||||||
|
value: label.response.body.labels[l],
|
||||||
|
inline: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return editOrReply(context, {
|
||||||
|
embeds: [createEmbed("default", context, {
|
||||||
|
fields: labels,
|
||||||
|
thumbnail: {
|
||||||
|
url: image
|
||||||
|
},
|
||||||
|
footer: {
|
||||||
|
iconUrl: STATICS.google,
|
||||||
|
text: `Google Cloud Vision • ${context.application.name} • Took ${label.timings}s`
|
||||||
|
}
|
||||||
|
})]
|
||||||
|
})
|
||||||
|
},
|
||||||
|
};
|
Loading…
Add table
Add a link
Reference in a new issue