"Code generation from strings disallowed for this context" error

hello,

I’m having issues running my command

$(eval w=$(urlfetch json https://www.helbreath.net/top-eks);r=w.slice(w.search(/Brosky/gi), w.indexOf(<tr,w.search(/Brosky/gi))).slice(55,75).replace(///g,).replace(/<td>|<tr>|td>/g,); )

getting the error Code generation from strings disallowed for this context
I’ve googled and haven’t found anyone that’s had similar issues.

Thanks for any help provided.

Hey @Dan_Huang!

Looks like @night updated how the $(urlfetch) variable behaves and it doesn’t allow us to pull website sources anymore, which is understandable given how it could affect Nightbot, so it seems there’s no solution, sorry about that.


That being said, I think I found a better way you could have written your command:

w=`$(urlfetch json https://www.helbreath.net/top-eks)`;
w.slice(w.search(/\d+<\/td><td>Brosky/i),w.indexOf(`</tr>`,w.search(/\d+<\/td><td>Brosky/i))).replace(/<\/td>/g,``).split(/<td.*\>/g);
`Rank: ${w[0]} | Enemy kills: ${w[4]} | Nation: ${w[2]} | Guild: ${w[3]}`

But it’s useless now, haha!

1 Like

Thanks @Emily!

In my case the error is not about urlfetch, but about ‘new Function’ Javascript mechanism. I still can use urlfetch inside eval without a problem.

I used urlfetch to download javascript code from external website and put the contents into new Function inside $(eval). You can call it kind of abusing the system, but the only reason I did so is because nightbot restriction on command length is too tight (the other reason is that editing commands is not too convenient via textbox in nightbot dashboard interface and it was much better to do so on external text file storage). Please consider increasing the maximum length of the command.

Hey @FreeSlave!

I too have commands fetching extra code on a third party website, and they still work, so that must be due to either your code or the third party website you use. Could you please share more details so we can help you?

Regarding the command length, it wasn’t like that before, but people had too many issues with the bot not sending messages because they weren’t aware of the limitations of the chats, so limits were introduced, if I understood properly. While I agree it’s an inconvenience for people who use JS to make complex commands, it’s necessary to ensure the majority of the people get a service that works, and as you said, there are workarounds. Most people don’t know about the limitations, so it makes sense to have them.

One thing to fix this issue once and for all while allowing as much freedom as possible though, would be for Nightbot to crop each messages it sends to chat with .slice(0,500) for Twitch and .slice(0,250) for YouTube, but I don’t know what are @night’s thoughts on this, there must be a good reason why it’s not implemented this way.

As I said, I used ‘new Function’. Like this:

$(eval var f=new Function('a','b',"return a+b"); f(4,3);)

Even this command, without any urlfetch’es gives me “Code generation” error. In my real commands I urlfetch code from pastebin and put it as a function body (in the example above it’s “return a+b”).

If you know some other code gen technics that still work, let me know.

As for command length, the length of resulting message has a little to do with the length of command, when $(eval) is in use, so the limitation seems odd.

Function constructor, eval, and async logic is now disabled within the eval context due to people causing abuse. You can rewrite your code to perform logic iteratively within the same functional context for now. We may introduce better ways to write custom complex logic in the future.

Thanks for answer.

Well, that’s the thing, I can’t do so due to command length limitation. And other people probably had to abuse code generation for the same reason. Now I had to rewrite my commands so they fit the limits, but it lost some functionality and I had to use one-letter variables, remove spaces and add some hacks to decrease the length of the code. No need to say, the result looks horrible and unreadable.

Btw, outside of code gen discussion, I often use urlfetch to grab a list of answers and choose a random one from the list. Again, the list could be stored in the command itself, instead of external storage, making the http request redundant (less http requests = better for nightbot servers).

Anyway, looking forward to improvements in this area.

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