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