Skip to content

Commit

Permalink
Update bot counter usage in goal widget
Browse files Browse the repository at this point in the history
  • Loading branch information
justlx committed Oct 31, 2024
1 parent 07f0a33 commit 562686a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
12 changes: 6 additions & 6 deletions GoalsOverPeriod/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ let getCounterValue = apiKey => {
"authorization": `apikey ${apiKey}`
}, "method": "GET"
}).then(response => response.json()).then(obj => {
fetch(`https://api.streamelements.com/kappa/v2/bot/${obj._id}/counters/goal`).then(response => response.json()).then(data => {
resolve(data.value)
fetch(`https://api.streamelements.com/kappa/v2/bot/${obj._id}/counters/${fieldData.botCounterName}`).then(response => response.json()).then(data => {
resolve(data.count)
})
});
})
Expand All @@ -81,19 +81,19 @@ window.addEventListener('onEventReceived', function (obj) {
const listener = obj.detail.listener;
const data = obj.detail.event;

if (listener === 'bot:counter' && data.counter === "goal") {
if (listener === 'bot:counter' && data.counter === fieldData.botCounterName) {
goal = data.value;
setGoal();
updateBar(count);
updateBar(prevCount, true);
}
});


async function updateBar(count) {
async function updateBar(count, force = false) {
if (fieldData['eventType'] === 'tip') {
count = await convertCurrency(count);
}
if (count === prevCount) return;
if (count === prevCount && !force) return;
if (count >= goal) {
if (fieldData['autoIncrement'] > 0 && fieldData.onGoalReach === "increment") {
goal += fieldData['autoIncrement'];
Expand Down
12 changes: 9 additions & 3 deletions GoalsOverPeriod/widget.json
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,15 @@
},
"botCounter": {
"type": "checkbox",
"label": "Use 'goal' bot counter as goal number?",
"label": "Use bot counter as goal number?",
"value": false,
"group": "Goal & Currency"
"group": "Bot counter"
},
"botCounterName": {
"type": "text",
"label": "Bot counter name",
"value": "goal",
"group": "Bot counter"
},
"eventType": {
"type": "dropdown",
Expand Down Expand Up @@ -651,4 +657,4 @@
"type": "hidden",
"value": "https://github.com/StreamElements/widgets/blob/master/GoalsOverPeriod/"
}
}
}

0 comments on commit 562686a

Please sign in to comment.