So trying to add some custom logic and make cool commands
but I I found a weird bug:
$(eval
last_user = $(urlfetch http://twitch.center/customapi/quote?token=eb8a35dd&data=1).split(’,’)[1];
if (last_user) { Sorry to slow was taken by ${last_user}
} else { $(urlfetch http://twitch.center/customapi/addquote?token=df200448451fcc85&data=%2C$(user)); $(user) got the bacon!;
})
So we get Sorry to slow was taken by ${last_user} as our response but $(urlfetch http://twitch.center/customapi/addquote?token=df200448451fcc85&data=%2C$(user)); was also called! How can i avoid this?
Yes. Make this command an alias to a second command.
The first command will send part of a URL to the second command. The second command will visit the URL. The first command will either send a string that will result in a quote being added, or it will send a string that will cause nothing to happen but that contains data.
For example:
!first (alias to !second)
$(eval last_user = `$(urlfetch http://twitch.center/customapi/quote?token=eb8a35dd&data=1)`.split(",")[1]; if (last_user) {`?TAKEN?=${last_user}`} else {`addquote?token=df200448451fcc85&data=%2C$(user)`})
!second
$(eval if (`$(urlfetch http://twitch.center/customapi/$(query))`.startsWith("Successfully added entry ")) {`$(user) got the bacon!`} else {match = `$(query)`.match(/^\?TAKEN\?=(.*)$/); if (match == null) {`@$(user) use !first`} else {`Sorry to slow was taken by ${match[1]}`}})