This repository has been archived by the owner on Feb 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
worldstate.js
157 lines (121 loc) · 3.75 KB
/
worldstate.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// THIS FILE IS A WIP TRYING TO GET INFORMATION ABOUT THE WORLD STATE IN WARFRAME
const http = require('http');
const schedule = require('node-schedule');
var channels = [];
var alertChannels = {
any: [],
nitain: []
};
module.exports = {
start: () => {start()},
addChannel: (channel, tag) => {
if(alertChannels[tag] == null)
alertChannels[tag] = [];
if(!alertChannels[tag].includes(channel)){
alertChannels[tag].push(channel);
channel.send("Succesfully added alert log for: " + tag);
}else{
channel.send("Channel is already used to log alerts for: " + tag);
}
},
removeChannel: (channel, tag) => {
if(alertChannels[tag] != null && alertChannels[tag].includes(channel)){
alertChannels[tag].push(channel);
channel.send("Succesfully removed alert log for: " + tag);
}else{
channel.send("Channel is not currently receiving logs for alerts for: " + tag);
}
}
}
var scheduleWS;
var delay = 10;
function start(){
scheduleWS = schedule.scheduleJob('*/' + delay + ' * * * * *', function(){getData();});
}
function getData(){
console.log("getting World State");
var hostURL = "content.warframe.com";
var pathURL = "/dynamic/worldState.php";
var options = {
host: hostURL,
path: pathURL
}
var request = http.request(options, function (res) {
var data = '';
res.on('data', function (chunk) {
data += chunk;
});
res.on('end', function () {
analyse(data);
});
});
request.on('error', function (e) {
console.log(e.message);
});
request.end();
}
var alreadyAnnouncedAlerts = [];
function analyse(data){
console.log("analysing World State");
let jData = JSON.parse(data);
let alerts = jData["Alerts"];
let recent = [];
for(let a of alerts){
let id = a["_id"];
let realId = id["$oid"];
recent.push(realId);
/*if(alreadyAnnouncedAlerts.includes(realId))
continue;*/
alreadyAnnouncedAlerts.push(realId);
let missionInfo = a["MissionInfo"];
let missionType = missionInfo["missionType"];
let faction = missionInfo["faction"];
let missionReward = missionInfo["missionReward"];
let minLevel = missionInfo["minEnemyLevel"];
let maxLevel = missionInfo["maxEnemyLevel"];
let loc = missionInfo["location"];
let dateA = a["Expiry"]; let dateB = dateA["$date"]; let dateC = dateB["$numberLong"];
let date = new Date(Number(dateC));
let left = timeLeft(date);
console.log("Credits from alert (" + realId + ") " + missionReward["credits"] + " expiration: " + date + " in " + left);
}
for(let i of alreadyAnnouncedAlerts){
if(!recent.includes(i))
alreadyAnnouncedAlerts.remove(i);
}
}
function notify(){
}
function timeLeft(t){
return timeLeftString(new Date(), t);
}
function timeLeftString(n, t){
let days = timeLeftDays(n, t);
let hour = timeLeftHour(n, t)-days*24;
let min = timeLeftMin(n, t)-hour*60;
let sec = timeLeftSec(n, t)-min*60;
return (days > 0 ? days + "d" : "") + (hour > 0 ? hour + "h" : "") + (min > 0 ? min + "m" : "") + (sec > 0 ? sec + "s" : "") + " left";
}
function timeLeftDays(n,t){
var t1 = t.getTime();
var t2 = n.getTime();
return parseInt((t1-t2)/(24*3600*1000));
}
function timeLeftHour(n,t){
var t1 = t.getTime();
var t2 = n.getTime();
return parseInt((t1-t2)/(3600*1000));
}
function timeLeftMin(n,t){
var t1 = t.getTime();
var t2 = n.getTime();
return parseInt((t1-t2)/(60*1000));
}
function timeLeftSec(n,t){
var t1 = t.getTime();
var t2 = n.getTime();
return parseInt((t1-t2)/(1000));
}
Array.prototype.remove = function(element){
this.splice(this.indexOf(element),1);
}