I have my doubts that this is possible, but I figured I’d check with all of you first. I was working on making a !free command for a jail in our stream and I found out you can use raw pastebin files with urlfetch to make long lists of outcomes. I have plans to make a long JSON list of outcomes but I tested it first with a short list and nightbot interprets the $(user) and $(touser) as part of the string. I probably should have expected this but alas. Is there any way to differentiate those variables from the rest of the string?
Here is the command I tried out
$(eval a="$(urlfetch https://pastebin.com/raw/kq672UpF)".split(";"); b="$(urlfetch https://pastebin.com/raw/VjttXd7d)".split(";"); c=a.concat(b); c[Math.floor(Math.random() * (c.length-1))]
First of all, I assume you’re using multiple Pastebins to avoid the 400-character limit/error.
Instead of doing that you can combine them into one Pastebin, then use
$(urlfetch json https://pastebin.com/) instead.
You’re right in that variables in urlfetches aren’t replaced correctly, but you’re using an eval and can do it yourself by using the
Here’s a full example following my own suggestions (keep in mind that the Pastebin link is also changed, so make sure to modify that before you use it):
$(eval const results = `$(urlfetch json https://pastebin.com/raw/7TNznHD5)`.split(';'); const text = results[Math.floor(Math.random() * (results.length-1))]; text.replace(/\$user/g, `$(user)`).replace(/\$touser/g, `$(touser)`);)
/* Fetch results, split by semicolons as before. Keep in mind the Pastebin link is a bit different */
const results = `$(urlfetch json https://pastebin.com/raw/7TNznHD5)`.split(';');
/* Pick a random result */
const text = results[Math.floor(Math.random() * (results.length-1))];
/* Replace instances of $user and $touser with the correct names. `/\$user/g` is used to replace all instances of `$user` */
text.replace(/\$user/g, `$(user)`).replace(/\$touser/g, `$(touser)`);
This works perfectly! I can’t thank you enough! I did know about the JSON part, I just hadn’t learned how to write it yet and wanted to test it out first, but it seems easy enough. Thanks so much!
Hello! You can pass the command of $ (user and $ (touser without pastebin
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.