diff --git a/nsfw_model.h5 b/nsfw_model.h5 deleted file mode 100644 index 6b2d2a1..0000000 Binary files a/nsfw_model.h5 and /dev/null differ diff --git a/src/inc/autotagger.mjs b/src/inc/autotagger.mjs new file mode 100644 index 0000000..3898a97 --- /dev/null +++ b/src/inc/autotagger.mjs @@ -0,0 +1,32 @@ +import fetch from 'flumm-fetch'; +import cfg from './config.mjs'; + +export default new class autotagger { + async isNSFW(filename, filesize) { + let opts = { + method: 'POST', + }; + let apiurl; + if(filesize < 4194304) { + apiurl = cfg.apis.nsfw1.url; + opts.headers = cfg.apis.nsfw1.headers; + opts.body = JSON.stringify({ + DataRepresentation: "URL", + Value: `${cfg.main.url.full}/b/${filename}` + }); + } + else { + apiurl = cfg.apis.nsfw2.url; + opts.headers = cfg.apis.nsfw2.headers; + opts.body = JSON.stringify({ + url: `${cfg.main.url.full}/b/${filename}` + }) + } + const res = await (await fetch(apiurl, opts)).json(); + + if(filesize < 4194304) + return res.IsImageAdultClassified || res.RacyClassificationScore > 0.6; + else + return res.unsafe; + }; +}; diff --git a/src/inc/queue.mjs b/src/inc/queue.mjs index 9f8ade1..df08fe3 100644 --- a/src/inc/queue.mjs +++ b/src/inc/queue.mjs @@ -107,4 +107,16 @@ export default new class queue { `; }; + async tagNSFW(itemid) { + return await db` + insert into "tags_assign" ${ + db({ + item_id: itemid, + tag_id: 2, + user_id: 1 + }) + } + `; + }; + }; diff --git a/src/inc/trigger/parser.mjs b/src/inc/trigger/parser.mjs index a1d096f..766708e 100644 --- a/src/inc/trigger/parser.mjs +++ b/src/inc/trigger/parser.mjs @@ -3,6 +3,7 @@ import db from "../sql.mjs"; import lib from "../lib.mjs"; import { getLevel } from "../admin.mjs"; import queue from "../queue.mjs"; +import autotagger from "../autotagger.mjs"; import fetch from "flumm-fetch"; import fs from "fs"; import path from "path"; @@ -20,7 +21,7 @@ export default async bot => { call: regex.all, active: true, f: e => { - const links = e.message.match(regex.all)?.filter(link => !link.includes("f0ck.me")) || []; + const links = e.message.match(regex.all)?.filter(link => !link.includes(cfg.main.url)) || []; let repost; if(e.media) @@ -184,10 +185,24 @@ export default async bot => { speed = !Number.isFinite(speed) ? "yes" : `${speed.toFixed(2)} Mbit/s`; // autotagger - //await queue.tagSFW(itemid); + let tags = []; + if(cfg.apis?.nsfw1 && mime.startsWith('image')) { + const nsfw = await autotagger.isNSFW(filename, size); + tags.push(nsfw ? 'nsfw' : 'sfw'); + if(nsfw) + await queue.tagNSFW(itemid); + else + await queue.tagSFW(itemid); + } - const outputmsgirc = `[f0cked] link: ${cfg.main.url.full}/${itemid} | size: ${lib.formatSize(size)} | speed: ${speed}`; - const outputmsgtg = `[f0cked] size: ${lib.formatSize(size)} | speed: ${speed}`; + let outputmsgirc = `[f0cked] link: ${cfg.main.url.full}/${itemid} | size: ${lib.formatSize(size)} | speed: ${speed}`; + let outputmsgtg = `[f0cked] size: ${lib.formatSize(size)} | speed: ${speed}`; + + if(tags.length > 0) { + const tagstr = tags.join(', '); + outputmsgirc += ` | tags: ${tagstr}`; + outputmsgtg += ` | tags: ${tagstr}`; + } if(e.type == 'tg') { await e.deleteMessage(msg.result.chat.id, msg.result.message_id);