Assistance with custom command

So i’m trying to have my !addwin command show my wins when i add it and also edit !wins.


But I keep getting this in my chat
Adding win to total amount of wins, TacoArrest is now at 1 wins! edit !win TacoArrest has won 2 games in total!
I can’t figure out why it wont register the edit in the line.

This is not possible with Nightbot’s $(count). You need a custom API such as this quote system.

Here is a working example:

Go to https://twitch.center/customapi/quote/generate. You will see three lines. Your first token is after token= and before &data= on the first line. Your second token is after token= and before &data= on the second and third lines. Replace FIRSTTOKEN and SECONDTOKEN with these before you add the following commands.

!wins

$(eval quotes = `$(urlfetch json http://twitch.center/customapi/quote/list?token=FIRSTTOKEN&no_id=1)`; wins = quotes == "There are no quotes added" ? 0 : quotes.length; `TacoArrest has won ${wins} game${wins == 1 ? "" : "s"} in total!`)

!addwin

$(eval match = `$(urlfetch json http://twitch.center/customapi/addquote?token=SECONDTOKEN&data=1)`.match(/^Successfully added entry #(\d+)$/); match ? `TacoArrest is now at ${match[1]} win${match[1] == 1 ? "" : "s"}!` : "Failed to reach API")

!resetwins

$(eval `$(urlfetch http://twitch.center/customapi/quote/list?token=FIRSTTOKEN)` == "There are no quotes added" ? "TacoArrest already has 0 wins" : (`$(urlfetch http://twitch.center/customapi/delquote?token=SECONDTOKEN&clear=1)`, "TacoArrest's wins have been reset"))
1 Like

Alright, so how would I remove like only 1 win? Also is there a way to manually set how many quotes you’re at, like I got 240 wins and don’t want to run the command 240 times to get my total if you get what I mean.
Btw thanks for the help, I don’t understand this really :stuck_out_tongue:

Edit:
!delwin
Successfully adjusted wins. $(eval match = $(urlfetch json http://twitch.center/customapi/delquote?token=TOKENITISINc&data=1).match(/^Successfully added entry #(\d+)$/); match ? TacoArrest is now at ${match[1]} win${match[1] == 1 ? "" : "s"}! : “Failed to reach API”)
Result
Successfully adjusted wins. Failed to reach API
eh?

You need more advanced commands if you want to set the number of wins or subtract from it.

Go to https://twitch.center/customapi/quote/generate. You will see three lines. Your first token is after token= and before &data= on the first line. Your second token is after token= and before &data= on the second and third lines. Replace FIRSTTOKEN and SECONDTOKEN with these before you add the following commands.

!wins

$(eval quote = `$(urlfetch json http://twitch.center/customapi/quote?token=FIRSTTOKEN&data=1&no_id=1)`; wins = quote == "There are no quotes added" ? 0 : quote; `TacoArrest has won ${wins} game${wins === "1" ? "" : "s"} in total!`)

!addwin (alias to !addwineditor, userlevel moderator)

$(eval quote = `$(urlfetch json http://twitch.center/customapi/quote?token=FIRSTTOKEN&data=1&no_id=1)`; wins = parseInt(quote); if (isNaN(wins)){"$NOTINITIALIZED$"} else {delta = (`$(query)` ? parseInt(`$(query)`) : 1); if (isNaN(delta)){"$INVALIDQUERY$"} else{newWinsEncoded = encodeURIComponent(wins + delta); `?token=SECONDTOKEN&data=1%20${newWinsEncoded}`}})

!addwineditor (userlevel moderator)

$(eval r=`$(urlfetch http://twitch.center/customapi/editquote$(query))`;if (r.startsWith("Successfully modified entry ")){match=`$(query)`.match(/=1%20(.*)$/);if(match){wins=decodeURIComponent(match[1]);`TacoArrest is now at ${wins} win${wins=="1"?"":"s"}!`}else{"!addwin is misconfigured"}}else if(r=="Invalid entry index."||`$(query)`=="$NOTINITIALIZED$"){"A moderator must use !resetwins"}else if(`$(query)`=="$INVALIDQUERY$"){"Enter a number after !addwin"}else{"Use !addwin"})

!resetwins (userlevel moderator)

$(eval clearresponse = `$(urlfetch http://twitch.center/customapi/delquote?token=SECONDTOKEN&clear=1)`; addresponse = `$(urlfetch http://twitch.center/customapi/addquote?token=SECONDTOKEN&data=0)`; (clearresponse === "All entries have been deleted" && addresponse === "Successfully added entry #1") ? "TacoArrest's wins have been reset" : `Error initializing !wins (${clearresponse}, ${addresponse})`)

Add the commands. Then type !resetwins. Then type !addwin 240 to manually set the number of wins. You can remove a single win using !addwin -1.

Yo, thanks! Greatly appreciate it!

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