From a97ed32c9f06751048c47f93bc5215dcf13a97a7 Mon Sep 17 00:00:00 2001 From: Flummi Date: Thu, 12 May 2022 16:18:18 +0200 Subject: [PATCH] ability to delete own f0cks --- src/inc/trigger/delete.mjs | 48 ++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/src/inc/trigger/delete.mjs b/src/inc/trigger/delete.mjs index 98dac12..ecb29e3 100644 --- a/src/inc/trigger/delete.mjs +++ b/src/inc/trigger/delete.mjs @@ -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(",")})`); } }] };