Files
twitch-subathon-countdown/js/api/streamloots.js
T
Lea 386fee2a84 ReUp of correct files, made a mistake
merged with an older version (I think), so here the correct files again
2023-03-01 12:25:05 +01:00

63 lines
3.5 KiB
JavaScript

if (streamloots_token !== "") {
evtSourceStreamLoots = new EventSource(`https://widgets.streamloots.com/alerts/${streamloots_token}/media-stream`);
logMessage("Streamloots", "Event Source Created");
evtSourceStreamLoots.onmessage = async (event) => {
data = await JSON.parse(event.data);
logObject("Streamloots", data);
if (data.data.type == "purchase") {
if (!countdownEnded && chestEnable) {
if(!happy_hour_active){
let chests;
if (typeof(data.data.fields[0].value) == "number") {
chests = data.data.fields[0].value;
if (chests >= min_amount_of_chests) {
let times = Math.floor(chests/min_amount_of_chests);
addTime(endingTime, seconds_added_per_chests * times);
logMessage("Streamloots", `Added ${seconds_added_per_chests * times} Seconds Because ${data.data.fields[1].value} Bought ${chests} Chests`);
if (!users.includes(data.data.fields[1].value)) {
users.push(data.data.fields[1].value);
}
}
}
else {
chests = data.data.fields[1].value;
if (chests >= min_amount_of_chests) {
let times = Math.floor(chests/min_amount_of_chests);
addTime(endingTime, seconds_added_per_chests * times);
logMessage("Streamloots", `Added ${seconds_added_per_chests * times} Seconds Because ${data.data.fields[0].value} Gifted ${chests} Chests`);
if (!users.includes(data.data.fields[0].value)) {
users.push(data.data.fields[0].value);
}
}
}
}
if(happy_hour_active){
let chests;
if (typeof(data.data.fields[0].value) == "number") {
chests = data.data.fields[0].value;
if (chests >= min_amount_of_chests) {
let times = Math.floor(chests/min_amount_of_chests);
addTime(endingTime, seconds_added_per_chests_happy * times);
logMessage("Streamloots", `Added ${seconds_added_per_chests_happy * times} Seconds Because ${data.data.fields[1].value} Bought ${chests} Chests`);
if (!users.includes(data.data.fields[1].value)) {
users.push(data.data.fields[1].value);
}
}
}
else {
chests = data.data.fields[1].value;
if (chests >= min_amount_of_chests) {
let times = Math.floor(chests/min_amount_of_chests);
addTime(endingTime, seconds_added_per_chests_happy * times);
logMessage("Streamloots", `Added ${seconds_added_per_chests_happy * times} Seconds Because ${data.data.fields[0].value} Gifted ${chests} Chests`);
if (!users.includes(data.data.fields[0].value)) {
users.push(data.data.fields[0].value);
}
}
}
}
}
}
}
}