mirror of
https://github.com/litruv/DAdmin.git
synced 2026-07-24 02:36:11 +10:00
safe image stuff, warning for no api key
This commit is contained in:
@@ -1,41 +1,46 @@
|
||||
const fs = require("fs")
|
||||
|
||||
|
||||
module.exports = {
|
||||
name: "Google Safe Image",
|
||||
init: (dclient) => {
|
||||
client = dclient
|
||||
|
||||
client.on('message', msg => {
|
||||
if (msg.author.bot) return
|
||||
if (msg.attachments.array().length = 0) return
|
||||
var img = msg.attachments.first()
|
||||
if (img == undefined) return
|
||||
if (img.height == undefined) return
|
||||
if (msg.channel.nsfw) return
|
||||
|
||||
detectSafeSearch(img.proxyURL, results => {
|
||||
var score = 0;
|
||||
if (results.safeSearchAnnotation.adult == "VERY_LIKELY" || results.safeSearchAnnotation.adult == "LIKELY") {
|
||||
score = "adult"
|
||||
}
|
||||
if (results.safeSearchAnnotation.racy == "VERY_LIKELY" || results.safeSearchAnnotation.racy == "LIKELY") {
|
||||
score = "racy"
|
||||
}
|
||||
|
||||
if (score != 0) {
|
||||
var stringmsg = `Adult: ${results.safeSearchAnnotation.adult} \n Medical: ${results.safeSearchAnnotation.medical}\n Spoof: ${results.safeSearchAnnotation.spoof}\n Violence: ${results.safeSearchAnnotation.violence}\n Racy: ${results.safeSearchAnnotation.racy}`;
|
||||
stringmsg += "\n\n Tags: "
|
||||
for (var i = 0; i < results.labelAnnotations.length; i++) {
|
||||
stringmsg += results.labelAnnotations[i].description
|
||||
if (i + 1 < results.labelAnnotations.length)
|
||||
stringmsg += ", "
|
||||
}
|
||||
// msg.reply(stringmsg)
|
||||
msg.reply("Oi, you can't have that " + score + " " + results.labelAnnotations[0].description.toLowerCase() + " here 😢")
|
||||
}
|
||||
})
|
||||
fs.exists("./googleapi.json", exists => {
|
||||
if (exists)
|
||||
client.on('message', msg => {
|
||||
if (msg.author.bot) return
|
||||
if (msg.attachments.array().length = 0) return
|
||||
var img = msg.attachments.first()
|
||||
if (img == undefined) return
|
||||
if (img.height == undefined) return
|
||||
if (msg.channel.nsfw) return
|
||||
|
||||
detectSafeSearch(img.proxyURL, results => {
|
||||
var score = 0;
|
||||
if (results.safeSearchAnnotation.adult == "VERY_LIKELY" || results.safeSearchAnnotation.adult == "LIKELY") {
|
||||
score = "adult"
|
||||
}
|
||||
if (results.safeSearchAnnotation.racy == "VERY_LIKELY" || results.safeSearchAnnotation.racy == "LIKELY") {
|
||||
score = "racy"
|
||||
}
|
||||
|
||||
if (score != 0) {
|
||||
var stringmsg = `Adult: ${results.safeSearchAnnotation.adult} \n Medical: ${results.safeSearchAnnotation.medical}\n Spoof: ${results.safeSearchAnnotation.spoof}\n Violence: ${results.safeSearchAnnotation.violence}\n Racy: ${results.safeSearchAnnotation.racy}`;
|
||||
stringmsg += "\n\n Tags: "
|
||||
for (var i = 0; i < results.labelAnnotations.length; i++) {
|
||||
stringmsg += results.labelAnnotations[i].description
|
||||
if (i + 1 < results.labelAnnotations.length)
|
||||
stringmsg += ", "
|
||||
}
|
||||
// msg.reply(stringmsg)
|
||||
msg.reply("Oi, you can't have that " + score + " " + results.labelAnnotations[0].description.toLowerCase() + " here 😢")
|
||||
}
|
||||
})
|
||||
})
|
||||
else {
|
||||
console.error("Google Safe Image ERROR\n" + __dirname + "/googleapi.json didn't exist\nYou need to create a service account key\nhttps://cloud.google.com/iam/docs/creating-managing-service-account-keys/ ")
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
@@ -52,12 +57,6 @@ async function detectSafeSearch(fileName, cb) {
|
||||
keyFilename: './googleapi.json'
|
||||
});
|
||||
|
||||
/**
|
||||
* TODO(developer): Uncomment the following line before running the sample.
|
||||
*/
|
||||
// const fileName = 'Local image file, e.g. /path/to/image.png';
|
||||
|
||||
// Performs safe search detection on the local file
|
||||
console.log(client.features)
|
||||
const request = {
|
||||
|
||||
@@ -81,6 +80,5 @@ async function detectSafeSearch(fileName, cb) {
|
||||
|
||||
const [result] = await client.annotateImage(request);
|
||||
console.log(result);
|
||||
//const detections = result.safeSearchAnnotation;
|
||||
cb(result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user