tagger schmagger
All checks were successful
fetch npm modules / f0ck the f0cker (push) Successful in 37s
All checks were successful
fetch npm modules / f0ck the f0cker (push) Successful in 37s
This commit is contained in:
parent
4e6b337d4f
commit
61e02953c7
BIN
nsfw_model.h5
BIN
nsfw_model.h5
Binary file not shown.
32
src/inc/autotagger.mjs
Normal file
32
src/inc/autotagger.mjs
Normal file
|
@ -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;
|
||||||
|
};
|
||||||
|
};
|
|
@ -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
|
||||||
|
})
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,6 +3,7 @@ import db from "../sql.mjs";
|
||||||
import lib from "../lib.mjs";
|
import lib from "../lib.mjs";
|
||||||
import { getLevel } from "../admin.mjs";
|
import { getLevel } from "../admin.mjs";
|
||||||
import queue from "../queue.mjs";
|
import queue from "../queue.mjs";
|
||||||
|
import autotagger from "../autotagger.mjs";
|
||||||
import fetch from "flumm-fetch";
|
import fetch from "flumm-fetch";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
@ -20,7 +21,7 @@ export default async bot => {
|
||||||
call: regex.all,
|
call: regex.all,
|
||||||
active: true,
|
active: true,
|
||||||
f: e => {
|
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;
|
let repost;
|
||||||
|
|
||||||
if(e.media)
|
if(e.media)
|
||||||
|
@ -184,10 +185,24 @@ export default async bot => {
|
||||||
speed = !Number.isFinite(speed) ? "yes" : `${speed.toFixed(2)} Mbit/s`;
|
speed = !Number.isFinite(speed) ? "yes" : `${speed.toFixed(2)} Mbit/s`;
|
||||||
|
|
||||||
// autotagger
|
// 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}`;
|
let outputmsgirc = `[f0cked] link: ${cfg.main.url.full}/${itemid} | size: ${lib.formatSize(size)} | speed: ${speed}`;
|
||||||
const outputmsgtg = `[f0cked] 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') {
|
if(e.type == 'tg') {
|
||||||
await e.deleteMessage(msg.result.chat.id, msg.result.message_id);
|
await e.deleteMessage(msg.result.chat.id, msg.result.message_id);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user