New Problem with This

Hey! I’m getting an annoying error that I’m sure is caused by my poor syntax. I’ve only ever used Java and C++ so I’m having trouble adjusting to JavaScript.

Here is the code I’m having the issue with:

!addcom -cd=60 !card $(eval
if($(1) == 1){
a=$(urlfetch http://twitch.center/customapi/addquote?token=PRIVATE_TOKEN&data=card1);}
else if($(1) == 2) {
a=$(urlfetch http://twitch.center/customapi/addquote?token=PRIVATE_TOKEN&data=card2);}
else if($(1) == 3) {
eval a=$(urlfetch http://twitch.center/customapi/addquote?token=PRIVATE_TOKEN&data=card3);})

The purpose of the code is to basically count 3 different values based on the argument from nightbot using $(1), using just one command. I have this working fine with three separate commands, but I can’t force a cd from one command onto the others. So if someone calls !card1 they can still call !card2 which is a problem. My solution was to try and combine them all into one command, !card.

Nevermind, finally caught the extra eval in the last line.

Okay, just as a final note, I ended up changing the code because NightBot was accessing the URLs regardless of the if statements. The new code is like this:

!addcom -cd=60 !card $(eval a=$(urlfetch http://twitch.center/customapi/addquote?token=PRIVATE_TOKEN&data=card$(1));)

Let’s me use !card 1/2/3 as I wanted (though technically allows for infinite cards, I GUESS.)

Thanks to RokettoJanpu for all of the code I cannibalized to make this work.

Okay, so it worked great for one day, and then completely broke down afterwards.

The code I’m using to display the results is breaking, having a " Cannot read property ‘length’ of null" error and otherwise display the wrong results for card 3, usually duplicating those of card 2. Can anyone look over this code and tell me what’s wrong? This code is just an edited version of something RokettoJanpu wrote for someone else, so I’m not 100% sure what’s going on:

$(eval a=$(urlfetch json http://twitch.center/customapi/quote/list?token=50be22ae);a.match(/card1/g)!=null?w=a.match(/card1/g).length:w=0;a.match(/card2/g)!=null?l=a.match(/card2/g).length:l=0;a.match(/card3/g)!=null?d=a.match(/card2/g).length:d=0;w+vote(s) for card 1,+l+for card 2, and+d+for card 3.)

For help with the quote API you check out the thread: [CustomAPI] Quote system