improved deletefunction

This commit is contained in:
Flummi 2016-11-07 14:24:33 +01:00
parent f4d2b09f07
commit 17217f4506

View File

@ -1,3 +1,5 @@
var fs = require('fs-extra');
module.exports = (lib) => {
lib.trigger.add({
name: 'delete',
@ -6,8 +8,17 @@ module.exports = (lib) => {
active: 1,
func: (e) => {
var id = e.message.split(' ')[1];
lib.sql.query("delete from `f0ck`.`items` where `id` = ?", id).on('end', () => {
e.reply("f0ck "+id+" deleted");
lib.sql.query("select `dest` from `f0ck`.`items` where `id` = ?", id, (err, rows, fields) => {
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");
e.reply("f0ck "+id+" deleted");
});
}
else {
e.reply("404 - f0ck not found");
}
});
},
desc: 'delete f0ck'