-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage-formatter.js
More file actions
67 lines (58 loc) · 2.05 KB
/
Copy pathmessage-formatter.js
File metadata and controls
67 lines (58 loc) · 2.05 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const fs = require('fs');
module.exports = {
watchlistMessage(serverId) {
// prepare to grab watchlist
let raw;
// read watch list
let pathToWatchlist = `./resources/watchlists/${serverId}.json`;
if(fs.existsSync(pathToWatchlist)) {
console.log(`Found watchlist at: ${pathToWatchlist}`);
raw = fs.readFileSync(`./resources/watchlists/${serverId}.json`);
}
else {
console.log('Did not find watchlist. Returning.');
return "Could not find your watchlist. Have you made one with !setup w?";
}
console.log('Formatting watchlist into message');
let watchlist = JSON.parse(raw);
// format
let data = [];
data.push("=== Winners ===");
for(let i = 0; i < watchlist.winners.length; i++) {
data.push(`[${i + 1}] ${watchlist.winners[i].name} (${watchlist.winners[i].episode})`)
}
data.push("=== Candidates ===");
if(watchlist.candidates.length >= 1) {
data.push(watchlist.candidates.join('\n'));
}
data.push("=== Finished ===");
if(watchlist.finished.length >= 1) {
data.push(watchlist.finished.join('\n'));
}
data.push("=== On Pause ===");
for(let i = 0; i < watchlist.onPause.length; i++) {
data.push(`${watchlist.onPause[i].name} (${watchlist.onPause[i].episode})`)
}
data.push("=== Banished ===");
data.push(watchlist.banished.join('\n'));
return data.join('\n');
},
eventlistMessage(serverId) {
// prepare to grab eventlist
let raw;
let pathToEventlist = `./resources/eventlists/${serverId}.json`;
if(fs.existsSync(pathToEventlist)) {
console.log('Found eventlist.');
raw = fs.readFileSync(pathToEventlist);
}
else {
console.log('Did not find eventlist. Returning empty.');
return "Could not find your eventlist. Have you made one with !setup e?";
}
console.log('Formatting eventlist into message');
let eventlist = JSON.parse(raw);
let events = eventlist.events;
// generate up to date event list message
return `=== Events ===\n${events.join('\n')}`;
}
}