Custom Counter in Nightbot with Twitch.center

Hey,

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 http://twitch.center/customapi/addquote?token=SECTOKEN&data=1)`
.match(/^Successfully added entry #(\d+)$/))
 match ? ( if (i>0) {
   foo(i-1)
 }) : "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.

@hyper_lol

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 http://twitch.center/customapi/addquote?token=$(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 https://twitch.center/customapi/quote/list?token=PUBLIC_TOKEN&no_id=1)`.match(/1/g);b=a!=null?a.length:0;`The counter value is ${b}.`)

!addcom -ul=mod !clear $(eval `$(urlfetch https://twitch.center/customapi/delquote?token=PRIVATE_TOKEN&clear=1)`==`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.