master #50

Merged
schrumpel merged 101 commits from master into dev 2022-10-22 23:40:03 +00:00
Showing only changes of commit 4f5d54ee19 - Show all commits

View File

@ -1,5 +1,6 @@
import { promises as fs } from "fs";
import db from "../sql.mjs";
import { getLevel } from "../../inc/admin.mjs";
export default async bot => {
@ -7,22 +8,42 @@ export default async bot => {
name: "delete",
call: /^\!(del|rm) .*/i,
active: true,
level: 100,
f: async e => {
const ret = (await Promise.all(e.args.map(async id => {
let deleted = [];
for(let id of e.args) {
id = +id;
if(id <= 0)
return false;
continue;
const f0ck = await db`
select dest
select dest, username, userchannel, usernetwork
from "items"
where id = ${+id}
where id = ${id}
limit 1
`;
if(f0ck.length === 0)
return false;
const level = getLevel(e.user).level;
if(f0ck.length === 0) {
e.reply(`f0ck ${id}: f0ck not found`);
continue;
}
if(
(f0ck[0].username !== (e.user.nick || e.user.username) ||
f0ck[0].userchannel !== e.channel ||
f0ck[0].usernetwork !== e.network) &&
level < 100
) {
e.reply(`f0ck ${id}: insufficient permissions`);
continue;
}
if(~~(new Date() / 1e3) >= (f0ck[0].stamp + 600) && level < 100) {
e.reply(`f0ck ${id}: too late lol`);
continue;
}
await fs.unlink(`./public/b/${f0ck[0].dest}`).catch(_=>{});
await fs.unlink(`./public/t/${id}`).catch(_=>{});
@ -31,13 +52,10 @@ export default async bot => {
where id = ${+id}
`;
return id;
}))).filter(d => d);
if(ret.length > 0)
e.reply(`deleted ${ret.length}/${e.args.length} (${ret.join(",")}) f0cks`);
else
e.reply(`oof`);
deleted.push(id);
}
e.reply(`deleted ${deleted.length}/${e.args.length} f0cks (${deleted.join(",")})`);
}
}]
};