Need help with a urlfetch command that returns variables

I’m creating a chat mini-game where people can battle each other WWE style. Originally I was trying to just do a random eval command similar to a basic !8ball command but I ran into the 400 character limit problem. I then used an eval with a concat function with 3 pastebin files and that got me around the character limit except the $(user) and $(touser) variables do not get filled in with the names in the response. I then tried another method by creating a php page that would randomly generate the responses and just did a urlfetch in the command but again the $(user) and $(touser) variables do not get filled in with the names. I’ve tried various urlfetch and eval nesting and it just doesn’t seem to work. Is this just not possible or am I missing something super simple?

Here is an example of the responses my php page returns:
$(touser) annihilates $(user) with a rebound clothesline and is the winner!
$(user) devastates $(touser) with a diving elbow drop and is the winner!
$(user) destroys $(touser) with an inverted suplex and is the winner!
$(touser) dispatches $(user) with a Ric Flair signature figure-four leglock and is the winner!

Here is the Nightbot command I’ve tried using:
!commands add !match $(user) challenges $(touser) to a cage match! $(urlfetch http://clintwestemeyer.com/match/match.php)

The response I would like to get back is:
ClintWestemeyer challenges @Electricalskateboard to a cage match! @Electricalskateboard destroys ClintWestemeyer with an inverted suplex and is the winner!

But this is what I get back instead:
ClintWestemeyer challenges @Electricalskateboard to a cage match! $(touser) destroys $(user) with an inverted suplex and is the winner!

Is there anyway to get the variables to work in the urlfetched responses?

Sorry if I’m missing something basic and thanks so much for any help I really appreciate it!

Clint

If you want to use the Pastebin method:
Store $(user) and $(touser) in variables before urlfetch'ing the main code:

$(eval d=decodeURIComponent;user=d("$(querystring $(user))");touser=d("$(querystring $(touser))");c=d("$(querystring $(urlfetch json YOUR_CODE_URL_HERE))");try{eval(c)}catch(e){`${e.message}: ${c}`.substr(0,400)})

You can then use the variables user and touser in the code uploaded at YOUR_CODE_URL_HERE. You only need a single code URL if you use urlfetch json, which doesn’t have a character limit.

If you want to use the PHP method:
Provide $(user) and $(touser) to your PHP page as query parameters:

$(urlfetch http://clintwestemeyer.com/match/match.php?user=$(querystring $(user))&touser=$(querystring $(touser)))

You can then use user and touser in your PHP code with $_GET['user'] and $_GET['touser']

1 Like

@am_1 Thank you so much!! I got it working successfully via the PHP method. I just had to figure out how to modify my PHP page to pull in and display the GET input correctly (took me a bit of tinkering as I’m a Network Engineer not a Programmer so this stuff is def not my language lol) but I eventually figured it out and it works great! Thank you very much for your help!

Clint

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