This commit is contained in:
Flummi
2021-12-04 11:08:55 +01:00
parent 5b7dd4293c
commit d885dd8e4e
7 changed files with 123 additions and 19 deletions

View File

@ -4,6 +4,37 @@ import cfg from "../../inc/config.mjs";
import sql from "../sql.mjs";
import lib from "../lib.mjs";
const cleanTags = async () => {
const tags = await sql("tags").leftJoin("tags_assign", "tags_assign.tag_id", "tags.id").whereNull("tags_assign.item_id");
if(tags.length === 0)
return 0;
let deleteTag = sql("tags");
let dtags = 0;
tags.forEach(tag => {
if(["sfw", "nsfw"].includes(tag.tag.toLowerCase()))
return dtags;
deleteTag = deleteTag.orWhere("id", tag.id);
dtags++;
});
await deleteTag.del();
return dtags;
};
const countf0cks = async () => {
const tagged = (await sql("items").whereRaw("id in (select item_id from tags_assign group by item_id)").count("* as total"))[0].total;
const untagged = (await sql("items").whereRaw("id not in (select item_id from tags_assign group by item_id)").count("* as total"))[0].total;
const sfw = (await sql("items").whereRaw("id in (select item_id from tags_assign where tag_id = 1 group by item_id)").count("* as total"))[0].total;
const nsfw = (await sql("items").whereRaw("id in (select item_id from tags_assign where tag_id = 2 group by item_id)").count("* as total"))[0].total;
return {
tagged,
untagged,
total: tagged + untagged,
sfw,
nsfw
};
};
export default async bot => {
return [{
@ -47,6 +78,14 @@ export default async bot => {
e.reply("hay hay patron, hemen!");
exec("sudo systemctl restart f0ck");
break;
case "cleanTags":
const tags = await cleanTags();
e.reply(tags + " tags removed");
break;
case "status":
const tmpc = await countf0cks();
e.reply(`tagged: ${tmpc.tagged}; untagged: ${tmpc.untagged}; sfw: ${tmpc.sfw}; nsfw: ${tmpc.nsfw}; total: ${tmpc.total}`);
break;
default:
return;
}