Custom Counter in Nightbot with


I ran into a problem because I got no experience in JS.

However I tried many things to make my custom counter work. Atm 2/3 of the counter is working fine (!clear and !showcounter) but I got problems with giving my counter a custom number to add.

This is my !counteradd rn:

$(eval  var i;  function foo(i) {
match = `$(urlfetch json`
.match(/^Successfully added entry #(\d+)$/))
 match ? ( if (i>0) {
 }) : "Failed to reach API"  return i; }  foo(3); )

Number 3 is planned to get replaced by &(query).

A simple loop does not work here because the fetched side needs to get the request done but the loop is already requesting a new one. This way only the last request is adding a quote pokes the counter up.

I tried using sleep or something in every notation even if it needs some time, but it does not work.

I tried getting a documentation about the twitch quote api, but I could not find it.

The code you can see is my most recent try to get this done but it does not work either. I also don’t get those β€œ? && :” …

I really would appreciate some help.


I set up 2 commands below, !counteradd and _counteradd which work in tandem to take a number in the user input and add it to the counter. Copy and paste the following into chat. Replace PRIVATE_TOKEN with your second (private) token:

!addcom -cd=5 !counteradd -a=_counteradd $(eval a=parseInt(decodeURIComponent(`$(querystring)`));Number.isInteger(a)&&a>0?`PRIVATE_TOKEN&data=${`1`.repeat(a)} ${a}`:` `) 

!addcom -cd=5 _counteradd $(eval `$(urlfetch$(query))`.includes(`Successfully added entry`)?`$(user) has increased the counter by $(2).`:`Enter a number greater than 0!`)

You may also need to edit the response for !showcounter and !clear (mod-only), these command setups will work with what has been set up above. Replace PUBLIC_TOKEN with your first (public) token and PRIVATE_TOKEN with your second (private) token:

!addcom -cd=5 !showcounter $(eval a=`$(urlfetch json`.match(/1/g);b=a!=null?a.length:0;`The counter value is ${b}.`)

!addcom -ul=mod !clear $(eval `$(urlfetch`==`All entries have been deleted`?`$(user) reset the counter!`:`Try again...`)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.