I'm trying to create an auto death counter command but it's not working. I used an AI to generate it, and I've come to the conclusion that Nightbot can't execute the command because it's too complex. Is this true, or is it more likely that the code is just wrong?
Command to DISPLAY:
!addcom !deaths The streamer has died 0 times.
Command to ADD:
!addcom !adddeath -ul=moderator -a=$(eval const text = \$(urlfetch json https://nightbot.tv/1/commands/lookup?q=!deaths )\.trim(); const match = text.match(/\\d+/); const current = match ? parseInt(match\[0\]) : 0; const add = parseInt('$(query)') || 1; const total = current + add; \!editcom !deaths The streamer has died ${total} times.\)
Command to RESET:
!addcom !resetdeaths -ul=moderator -a=!editcom !deaths The streamer has died 0 times.
The AI says the error is as follows:
To understand why, we have to look at the "chain of execution"—the sequence of steps Nightbot must take to run the command:
1. A user runs !adddeath, which triggers the alias (-a=) function.
2. The alias needs to execute the result of the $(eval) script.
3. To get that result, the $(eval) script must first use the $(urlfetch) variable to read the !deaths command from Nightbot's server.
4. The $(eval) script then calculates the new total and generates a complete, new command as a line of text (e.g., !editcom !deaths The streamer has died 5 times.).
5. Finally, the alias (-a=) from Step 1 is supposed to take this text and execute it as a command.
Our tests proved that this chain breaks at the final step. The alias (-a=) function appears to be unable to execute a command that was generated by a script that is as complex as this one (containing both eval and urlfetch).