This commit is contained in:
Flummi 2016-11-22 17:29:04 +01:00
parent 36fcb30630
commit 9ddb8ad7d4

View File

@ -2,31 +2,30 @@ var fs = require('fs-extra');
module.exports = (lib) => {
lib.trigger.add({
name: 'delete',
name: 'del',
call: /^\!(del|rm)/i,
level: 100,
active: 0,
func: (e) => {
var ids = e.message.split(' ');
var ok = [];
var fail = [];
ids.shift();
for(var id in ids) {
ids.forEach(id => {
if(Number.isInteger(parseInt(id))) {
lib.sql.query("select `dest` from `f0ck`.`items` where `id` = ?", id, (err, rows, fields) => {
lib.sql.query("select `dest` from `f0ck`.`items` where `id` = ? limit 1", id, (err, rows) => {
if(rows[0]) {
lib.sql.query("delete from `f0ck`.`items` where `id` = ?", id).on('end', () => {
fs.unlink(rows[0].dest);
fs.unlink("./t/"+id+".png");
ok.push(id);
});
lib.sql.query("delete from `f0ck`.`items` where `id` = ? limit 1", id, err => {
if(!err) {
fs.unlink(rows[0].dest, err => {});
fs.unlink("./t/"+id+".png", err => {});
}
else
fail.push(id);
e.reply(err);
});
}
});
}
e.reply(ok.length+" from "+(ok.length+fail.length)+" f0cks deleted");
});
e.reply("f0ck"+(ids.length>1?"s":"")+" deleted");
},
desc: 'delete f0ck'
});