Code generation from strings disallowed for this context

Hello, I have a problem creating a command in Nightbot in connection with Pastebin:

My Command !keks should trigger random sentences (with User / Touser)

Here the integration in Nightbot:

$(eval a=[$(urlfetch json Pastebin.com - Locked Paste)];a[Math.floor(Math.random()*a.length)].replace(/~U/g,$(user)).replace(/~T/g,decodeURIComponent($(querystring $(touser)))))

Then I get the error message: Code generation from strings disallowed for this context

I don’t know what to do next, can someone please help me? thanks

Hey @wifeyoutofcontrol!

Your paste is password-locked, Nightbot can’t access it, make sure it’s either Public or Unlisted.

1 Like

Hi

Thanks, I changed that but now this message comes up:

[Response must be less than 400 characters]

Yes, that’s because of how you set up your paste and your command code, I couldn’t fix it before seeing the paste content, so here’s a fix suggestion:

First, update the paste content with the following:

${u} rast durch die Küche und sucht im Fieberwahn nach Cookies - ${t} sieht nur noch eine Staubwolke|
${u} duckt sich als ${t} Mehl um sich wirft.|
${u} fleht ${t} an INSTANT Cookies zu backen!!!|
${u} und ${t} lachen sich leise ins Fäustchen, denn sie haben den letzten Cookies weggefuttert.|
und ${u} nehmen die Beine in die Hand um schnell für ${t} die Zutaten für die Cookies zu besorgen.|
und ${t} sind fassungslos nachdem sie die Kalorien für einen Cookie ausgerechnet haben.|
In der Küche ist es verdächtig ruhig, ich schaue nach und finde ${t} im Eck die Teigschale ausschlecken.|
really?! ${t} steckt mit der Hand im Cookie Glas fest…. Ohne Worte|
${u} läuft zu ${t} und teilt den letzten Cookie in zwei Hälften. Das ist sehr nett!!|
${u} reißt ${t} den letzten Cookie aus der Hand und läuft böse lachend davon.

I used the vertical bar to show end of sentences instead of the comma since you have some in your responses, note that the last one doesn’t end with one, it’s because otherwise it increases the length of the array by 1, which will cause issues.

Then for your command, I call $(user) and $(touser) outside of the paste, otherwise it doesn’t work, not sure what you would have been replacing with your code, nothing matched the RegExp:

$(eval u=`$(user)`; t=`$(touser)`; a=`$(urlfetch json https://pastebin.com/raw/ar9WjAd8)`.split(`|`); a[Math.floor(Math.random()*a.length)];)

And if you really want to use the decodeURIComponent() function, replace:
t=`$(touser)`; by t=decodeURIComponent(`$(touser)`);

1 Like

Thanks very much! It works now

1 Like

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