Added safe images

This commit is contained in:
2019-04-04 13:34:46 +11:00
parent ed5d34e57e
commit 1ddd172478
2 changed files with 84 additions and 1 deletions

View File

@@ -4,6 +4,7 @@
"description": "",
"main": "index.js",
"dependencies": {
"@google-cloud/vision": "^0.25.0",
"colors": "^1.3.3",
"discord.js": "^11.4.2",
"mysql": "^2.16.0",

82
plugins/safeimage.js Normal file
View File

@@ -0,0 +1,82 @@
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.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 😢")
}
})
})
}
}
async function detectSafeSearch(fileName, cb) {
// [START vision_safe_search_detection]
const vision = require('@google-cloud/vision');
// Creates a client
const client = new vision.ImageAnnotatorClient({
projectId: 'causal-galaxy-207206',
keyFilename: 'C:/dev/myproject.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 = {
"image": {
"source": {
"imageUri": fileName
}
},
features: [
{
type: "LABEL_DETECTION",
},
{
type: "SAFE_SEARCH_DETECTION",
}
]
}
const [result] = await client.annotateImage(request);
console.log(result);
//const detections = result.safeSearchAnnotation;
cb(result);
}