If/else run Commercial depending of Game with Timers

Hey @John_Doe!

I assume you want to use the !commercial command inside a Timer since you want to automate the response whether it is to run a commercial or the subscribe message.

Sadly this won’t be possible without some concessions. As you can’t edit Timers from the chat, you can’t change the alias of it depending of the game: my first idea was to create a Timer that would be triggered a bit before the commercial Timer to check the game and update the commercial Timer alias if needed, in which case it’d run either the !commercial command or a !sub command. This would have been great.

But we can’t do that, the only solution I came up with is the following:

$(eval g=`$(twitch $(channel) "{{game}}")`; b=[`SPECIFIC_GAME1`,`SPECIFIC_GAME2`];b.includes(g)?`COMMERCIAL_LENGHT OPTIONAL_SILENT`:`0`)

Replace the SPECIFIC_GAMES field and make sure they’re capitalized like Twitch does.
Replace COMMERCIAL_LENGHT and OPTIONAL_SILENT with valid values: documentation
And then set up !commercial as the alias of the Timer.

The issue with this is that you’ll get an error message when no commercials are supposed to run and you won’t get the subscribe message.
In case it’s too big of an issue just turn on the timer when you play the game.
Sorry I couldn’t offer you a better solution.


And to reply to this:

Is there any way to use a command inside eval?

No, Nightbot doesn’t even read its own messages to prevent it from looping, the closest way you can go about this is by using an alias, like I did.

1 Like