cleaner for unused items
This commit is contained in:
parent
8f708f8819
commit
8807934fcd
45
src/trigger/clean.js
Normal file
45
src/trigger/clean.js
Normal file
@ -0,0 +1,45 @@
|
||||
var fs = require('fs-extra');
|
||||
|
||||
module.exports = (bot, trigger, lib) => {
|
||||
trigger.add({
|
||||
name: 'clean',
|
||||
call: /^\!clean/i,
|
||||
level: 100,
|
||||
active: 1,
|
||||
func: (e) => {
|
||||
var dir_b = fs.readdirSync('./b/'); // Items
|
||||
var dir_t = fs.readdirSync('./t/'); // Thumbnails
|
||||
var items_id = [];
|
||||
var items_dest = [];
|
||||
|
||||
var failed_ids = [];
|
||||
var failed_dests = [];
|
||||
|
||||
lib.sql.query("select `id`, `dest` from `f0ck`.`items`", (err, rows, fields) => {
|
||||
rows.forEach((e,i,a) => {
|
||||
items_id.push(e.id);
|
||||
items_dest.push(e.dest.replace('./b/', ''));
|
||||
});
|
||||
|
||||
dir_b.forEach((e,i,a) => {
|
||||
if(!(e in items_dest)) {
|
||||
failed_dests.push(e);
|
||||
//fs.unlink('./b/'+e);
|
||||
}
|
||||
});
|
||||
dir_t.forEach((e,i,a) => {
|
||||
if(!(e.replace('.png', '') in items_id)) {
|
||||
failed_ids.push(e);
|
||||
//fs.unlink('./t/'+e);
|
||||
}
|
||||
});
|
||||
|
||||
e.reply('unused thumbnails: ' + failed_ids.length + ' ; unused dests: ' + failed_dests.length);
|
||||
//console.log(failed_dests);
|
||||
}).on('error', (err) => {
|
||||
e.reply(err);
|
||||
});
|
||||
},
|
||||
desc: 'testtrigger'
|
||||
});
|
||||
};
|
Loading…
Reference in New Issue
Block a user