This repository has been archived by the owner on Sep 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cron.js
36 lines (32 loc) · 1.46 KB
/
cron.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// This script is ran every time Mipper starts up
const fs = require("fs");
module.exports = {
cron: function () {
try {
// Remove any audio leftovers
for (let file of fs.readdirSync(__dirname + "/audio")) {
if (filename.endsWith(".md")) continue;
fs.unlinkSync(__dirname + `/audio/${file}`);
}
// Remove any screenshot leftovers
for (let file of fs.readdirSync(__dirname + "/screenshots")) {
if (filename.endsWith(".md")) continue;
fs.unlinkSync(__dirname + `/screenshots/${file}`);
}
// Purge guild cache leftovers
for (let file of fs.readdirSync(__dirname + "/cache/guilds")) {
if (filename.endsWith(".md")) continue;
fs.unlinkSync(__dirname + `/cache/guilds/${file}`);
}
// Remove rewards with no role or no level
for (let filename of fs.readdirSync(__dirname + "/db/levels")) {
if (filename.endsWith(".md")) continue;
let file = JSON.parse(fs.readFileSync(__dirname + `/db/levels/${filename}`).toString());
file.info.rewards = file.info.rewards.filter(r => r.role != "" || r.level != null);
fs.writeFileSync(__dirname + `/db/levels/${filename}`, JSON.stringify(file));
}
} catch (e) {
console.log(e);
}
}
}