$(twitch "{{game}}") returning literals for games with apostrophes

Asked Sep 28, 2021·3 replies·Last activity 4 years ago·Open in Discord ↗
Archived from the original community forum
Things may have changed since it was written. Still stuck? Ask the community on Discord.

I'm wanting to build a branching eval for a shoutout for a channel I moderate.

Here's the snippet of what I'm using currently for the eval:

$(eval game='$(twitch $(touser) "{{game}}")'; if (game=="no game") '### NON-GAMER MESSAGE ###'; else '### GAMER MESSAGE '+game+' ###';)

This functions perfectly most of the time, but if the game title includes an apostrophe (Demon's Souls, for example) it throws an error (Unexpected identifier) which I believe is a result of pulling the information from Twitch without parsing special characters to special characters, instead returning the single quote as a literal character and thus breaking the string.

I've got a functional workaround by using decapi but I'd like to do as little outside API calling as possible. Is this a thing that can be addressed?

3 replies

Well, $(querystring) should do exactly as you want.

First command the one you call !so

$(querystring $(twitch $(touser) "{{game}}"))

Alias it to _so or something similar

Second command _so Same code as before just one minor difference

$(eval game=decodeURIComponent(`$(query)`; if (game=="no game") `### NON-GAMER MESSAGE ###`; else `### GAMER MESSAGE ${game} ###`)

If your wondering why I used two commands it has to do with nightbots nesting limit “$($($()))” can only nest two times max.

Hey @Dusty Crab!

While @Quirky Fox's solution will work, there's a better/simpler solution, and he demonstrated it in his reply.

Simply use template literals, aka backticks: `` ```.

So your command would be:

$(eval game=`$(twitch $(touser) "{{game}}")`; if (game==`no game`){`### NON-GAMER MESSAGE ###`;} else {`### GAMER MESSAGE ${game} ###`;})
Polar Cat said:
$(eval game=$(twitch $(touser) "{{game}}"); if (game==no game){### NON-GAMER MESSAGE ###;} else {### GAMER MESSAGE ${game} ###;})

That works a treat, and taught me something new in the process. Thanks, @Polar Cat !