-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
74 lines (60 loc) · 1.98 KB
/
index.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
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
68
69
70
71
72
73
74
const Tail = require('tail').Tail;
const fs = require('fs');
const config = require('./config.json');
const Discord = require('discord.js');
const stats = JSON.parse(fs.readFileSync('./stats.json'));
const client = new Discord.Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', msg => {
if (msg.content === '!stats') {
const deathStats = Object.keys(stats.deaths).map((player) => `${player}: ${stats.deaths[player]}`);
let text = '```Deaths:\n'
text += deathStats.join('\n');
text += '\n\nRockets launched: ' + stats.launches + '```';
msg.channel.send(text);
}
});
client.login(config.discordToken).then(() => {
client.user.setActivity('you die', { type: 'WATCHING' })
})
tail = new Tail(config.logfile);
tail.on("line", function (data) {
if (data.startsWith('FDDLOGGER:')) {
console.log(data);
if (data.includes("Player ")) {
const player = data.split("Player ")[1].split(" ")[0]
addDeath(player)
} else {
console.log(data);
// Rocket launched
addLaunch();
}
};
});
tail.on("error", function (error) {
console.log('ERROR: ', error);
});
function addLaunch() {
console.log("Added rocket launch")
stats.launches = stats.launches + 1;
saveStats();
}
function addDeath(player) {
console.log(stats.deaths, player)
console.log("deds", stats.deaths[player])
if (stats.deaths[player] !== undefined) {
stats.deaths[player] = stats.deaths[player] + 1;
} else {
stats.deaths[player] = 1;
}
console.log("added death for ", player);
console.log("Current deaths", stats.deaths)
saveStats();
client.channels.cache.get(config.textChannel).send(`Player ${player} has died! That's already ${stats.deaths[player]} time(s)`)
}
function saveStats() {
fs.writeFileSync('./stats.json', JSON.stringify(stats, null, 2));
}
console.log("Launched bridge")