Nightbot resolves `$(urlfetch)` before $(eval)

So trying to add some custom logic and make cool commands
but I I found a weird bug:
last_user = $(urlfetch’,’)[1];
if (last_user) {
Sorry to slow was taken by ${last_user}
} else {
$(user) got the bacon!;

So we get Sorry to slow was taken by ${last_user} as our response but $(urlfetch$(user)); was also called! How can i avoid this?

This is not a bug, inner elements are replaced before outer elements. In general, eval will always be called last.

1 Like

Is there away to do something like this then?

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`.split(",")[1]; if (last_user) {`?TAKEN?=${last_user}`} else {`addquote?token=df200448451fcc85&data=%2C$(user)`})

$(eval if (`$(urlfetch$(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]}`}})

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