Eval, lowercase and urlfetch

I feel like an utter idiot. Here’s what I’m trying to do:

I want “!command ARGUMENT” to turn the ARGUMENT into lowercase and then return the contents of a file from my server, where ARGUMENT is the file name, so that “!command FiLeNAME” returns the contents of https://www.myserver.com/directory/filename

This is probably incredibly easy to do, but somehow I’m stuck. Any help would be much appreciated!

Hey @BaronVonKale!

To make the query is in lower case you use .toLowerCase():

$(eval '$(1)'.toLowerCase())

However, since you call an API/URL you have to do it in two steps, because Nightbot executes the $(urlfetch) before the JS code, so it replaces the Nightbot variables with values/data that can be used with JS, the solution to that is to use an alias command: you have your first command that sets the argument to lowercase, and then the second command is called with the output of the first one:

!addcom !firstCommand -a=_secondCommand $(eval '$(1)'.toLowerCase())

!addcom _secondCommand $(urlfetch YOUR_API_URL)

Alternatively, you could make it so that on the server-end it’s case-insensitive.

Thanks a ton, didn’t realize the need for an alias!

No problem, it’s not obvious, it took me a while to understand it the first time I encountered such issue.

1 Like

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