If else and url fetch

I have this:

!editcom !turno $(eval var r =’$(urlfetch https://twitch.center/customapi/quote?token=TOKENHERE&data=$(touser))’;
if(r.charAt(0)==‘0’){
r=’’;}
if(r== ‘There are no quotes added’){
r=’’;}
if®{
‘$(touser) ya está en el listado’;}
else{
‘$(urlfetch https://twitch.center/customapi/addquote?token=TOKEN2HERE&data=$(touser))’;}
)

The first part search for the user in a list

It returns 3 cases
-There are no quotes added (empty list)
-number.user (find user)
-0.last user (don’t find user)

When r is my user and i’m in a quote ( r=1.manito ) nightbot display “manito ya está en el listado” and enter and execute de else sentence too (adding me in a new quote)

How could i fix it? Thanks

Hey @manito!

Call the second $(urlfetch) in an alias command.

So you’d have your first command (assuming your current code works), and in the else you put your PRIVATE_TOKEN (which you call TOKEN2) along with what you want to add to the quote API:

$(eval var r =’$(urlfetch https://twitch.center/customapi/quote?token=TOKENHERE&data=$(touser))’;
if(r.charAt(0)==‘0’){
r=’’;}
if(r== ‘There are no quotes added’){
r=’’;}
if®{
‘$(touser) ya está en el listado’;}

else{
`TOKEN2HERE&data=$(touser)`}

)

And then for the alias command it’d go like this:

$(eval a=`$(urlfetch https://twitch.center/customapi/addquote?token=$(query))`; q=`$(query)`; q.includes(`PRIVATE_TOKEN`)?a:q)

That way, it’ll only add the user to the quote API if else is executed, otherwise you’ll get the expected output.

To add an alias from the chat use !addcom !command_name -a=alias_command_name response, but in general you want to avoid adding commands that contain sensible information such as a PRIVATE_TOKEN through your chat, anyone seeing the message can then edit your quote API, so do it through the dashboard, and don’t forget to fill the Alias field of the first command with the name of the second command.

1 Like

Thank you Emily !!!

For people who don’t understand (like me 5 minutes ago) the solution needs 2 commands :

!addcom !NEWCOMMAND $(eval a=$(urlfetch https://twitch.center/customapi/addquote?token=$(query)); q=$(query); q.includes(TOKEN2HERE)?a:q)

!addcom !turno -a=!NEWCOMMAND $(eval var r =’$(urlfetch https://twitch.center/customapi/quote?token=TOKENHERE&data=$(touser))’;
if(r.charAt(0)==‘0’){
r=’’;}
if(r== ‘There are no quotes added’){
r=’’;}
if®{
‘$(touser) ya está en el listado’;}
else{
TOKEN2HERE&data=$(touser);
} )

be careful with copy-paste, i only need the name of the user and use touser :wink:

1 Like

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