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

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+’ ###’:wink:

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?

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.

1 Like

Hey @iamtiote!

While @potatoeaterlove’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} ###`;})
2 Likes

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

1 Like

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