-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebScript.json
More file actions
58 lines (48 loc) · 1.86 KB
/
WebScript.json
File metadata and controls
58 lines (48 loc) · 1.86 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
((
/** @type {string} */ streamUptimeString,
/** @type {string} */ streamStartDateString,
/** @type {string} */ urlEncodedGetMmrHistoryResponseJson,
) => {
/* streamStartDateString will be a date string even if the channel is not currently live (the date will be the current
date). This may be a Nightbot bug. This is why streamUptimeString is needed to check whether the channel is live */
if (/\bnot live\b/i.test(streamUptimeString)) {
return 'Draxick is not live';
}
const streamStartDate = new Date(streamStartDateString);
if (Number.isNaN(streamStartDate.valueOf())) {
return `Failed to parse stream start date: ${streamStartDateString}`.slice(0, 400);
}
const getMmrHistoryResponseJson = decodeURIComponent(urlEncodedGetMmrHistoryResponseJson);
if (/^Error Connecting To Remote Server\b/i.test(getMmrHistoryResponseJson)) {
return 'No games played yet.';
}
try {
/** @type {{
readonly data: ReadonlyArray<{
readonly mmr_change_to_last_game: number;
readonly date_raw: number;
}>;
}} */
const getMmrHistoryResponse = JSON.parse(getMmrHistoryResponseJson);
let mmrChangeThisStream = 0;
let winCountThisStream = 0;
let lossCountThisStream = 0;
let rankedRating = 0;
var string = "";
var rank = "";
json = JSON.parse(getMmrHistoryResponseJson);
currenttierpatched = json.data.currenttierpatched;
elo = json.data.elo;
mmr_change_to_last_game = json.data.mmr_change_to_last_game;
if(mmr_change_to_last_game > 0) {
string = "gained";
}else if(mmr_change_to_last_game < 0){
string = "lost";
}else{
string = "at";
}
return `Draxick is at ${(elo-2100)}RR in ${currenttierpatched} and ${string} ${Math.abs(mmr_change_to_last_game)}RR last game.` ;
} catch (e) {
return `Failed to parse MMR history: ${e.message}: ${getMmrHistoryResponseJson}`.slice(0, 400);
}
})