This repository has been archived by the owner on Feb 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
bdoBossAlert.js
79 lines (75 loc) · 3.42 KB
/
bdoBossAlert.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
//Initial Variables
var cheerio = require("cheerio");
var request = require("request");
var emitter = require('./emitter')
///////////////////////////////////////
//Obtaining Boss Spawning Data (Loop)
//////////////////////////////////////
//Boss Data Holders: Ordered by how they appear on http://urzasarchives.com/bdo/wbtbdo/wbtna/ is mandatory
var bossData = {
kutum: {alert: "Kutum Spawned!", img: "http://urzasarchives.com/wp-content/uploads/wbt_kutum.png"},
dastardBheg: {alert: "Dastard Bheg Spawned!", img: "http://urzasarchives.com/wp-content/uploads/wbt_bheg.png"},
dimTreeSpirit: {alert: "Dim Tree Spirit Spawned!", img: "http://urzasarchives.com/wp-content/uploads/wbt_dim.png"},
giantMudster: {alert: "Giant Mudster Spawned!", img: "http://urzasarchives.com/wp-content/uploads/wbt_mudster.png"},
karanda: {alert: "Karanda Spawned!", img: "http://urzasarchives.com/wp-content/uploads/wbt_harpy.png"},
kzarka: {alert: "Kzarka Spawned!", img: "http://urzasarchives.com/wp-content/uploads/wbt_kzarka.png"},
redNose: {alert: "Red Nose Spawned!", img: "http://urzasarchives.com/wp-content/uploads/wbt_red.png"},
nouver: {alert: "Nouver Spawned!", img: "http://urzasarchives.com/wp-content/uploads/wbt_nouver.png"}
}
//Will be added if URZAS ARCHIVES ever updates...
//muraka: {alert: "Muraka Spawned!", img: "https://i.imgur.com/SrPM0fF.png"},
//quint: {alert: "Quint Spawned!", img: "https://i.imgur.com/nsp8tfc.png"}
//Scrape website for boss data
function retrieveBossData(callback){
//Url for boss spawn data (Set to NA server by default)
var url = "http://urzasarchives.com/bdo/wbtbdo/wbtna/";//other BDO server URLs are here: http://urzasarchives.com/bdo/wbtbdo/
//Obtain Boss Spawn Data
request(url, function (error, response, body) {
var $ = cheerio.load(body);//html body
//Attempt Obtain And Assign Boss Spawn Data
try{
//find each boss spawn
var counter = 0;
for(var boss in bossData){
readBossData(bossData[boss], counter, $("table"));
counter++;
}
//pass new data to callback
callback(bossData);
}
catch(htmlError){
console.log(htmlError+"\nCould not find HTML element!"+"\n Retrying Now!... ");
}
});
};
//Looks for appropriate boss table
function readBossData(boss, tableNumber, table){
var selector = table;//initial html table element
var lastSpawn;
//find desired boss table
for(i = 0; i < tableNumber; i++){
selector = selector.next();
}
//record last boss spawn
lastSpawn = selector.find("tbody > tr").next().find("td").next().next().html();
//ensure spawn time has numbers
if(!/\d/.test(lastSpawn))
return;//exit
//check if boss spawned
if(boss.lastSpawn != null && lastSpawn != null && lastSpawn !== boss.lastSpawn)
emitter.bossEvents.sendEvent("bossSpawn", boss);//alert if spawned
boss.lastSpawn = lastSpawn;//update last boss spawn
}
///////////////////////////////////////
//Begin Scraping
//////////////////////////////////////
//Wait 10 seconds before running again
function endlessLoop(){
//send alert to event object
retrieveBossData(function(data){
emitter.bossEvents.sendEvent("newData", data);
});
//loop
setTimeout(endlessLoop, 10000);
}
endlessLoop();//start loop