mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-18 21:40:49 +02:00
NSFW Command with Tensorflow
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const crypto = require('crypto');
|
||||
const tf = require('@tensorflow/tfjs-node');
|
||||
const { decode: decodeHTML } = require('html-entities');
|
||||
const { stripIndents } = require('common-tags');
|
||||
const { URL } = require('url');
|
||||
@@ -216,6 +217,13 @@ module.exports = class Util {
|
||||
return str;
|
||||
}
|
||||
|
||||
static isImageNSFW(model, image, bool = true) {
|
||||
const img = await tf.node.decodeImage(new Uint8Array(image), 3);
|
||||
const predictions = model.classify(image, 1);
|
||||
img.dispose();
|
||||
return bool ? predictions[0] !== 'Neutral' && predictions[0] !== 'Drawing' : predictions[0];
|
||||
}
|
||||
|
||||
static async reactIfAble(msg, user, emoji, fallbackEmoji) {
|
||||
const dm = !msg.guild;
|
||||
if (fallbackEmoji && (!dm && !msg.channel.permissionsFor(user).has('USE_EXTERNAL_EMOJIS'))) {
|
||||
|
||||
Reference in New Issue
Block a user