Trying to pull a list from pastebin based on current game played

Asked Nov 25, 2023·5 replies·Last activity 2 years ago·Open in Discord ↗
Archived from the original community forum
Things may have changed since it was written. Still stuck? Ask the community on Discord.

I'm very new to complex nightbot commands and I'm having trouble getting something to work that I know SHOULD work. What I want to do is have a !join command that will list the in-game user name based on current game being played.

example:
fortnite: fakename1

Based on cursory research, I know I should be able to have a pastebin set up with the list of games and usernames to add and use it as a JSON to look up the game and print the right username. But I cannot get it to work.

I have gotten $(twitch "{{game}}") to work to use as the input, but I haven't been able to incorporate that input into an $(eval) to look up in the pastebin.

5 replies

You should be able to do a someVar = $(urlfetch json https://pastebin.com/raw/xxxxxxxxx); within the eval, then access the data you need through the someVar variable. The "json" portion of the urlfetch is important, as it parses the resulting message straight to a json object rather than a string, which bypasses the usual 400 character limit.

I've seen some of your previous posts on the topic (before I made this post) and tried to incorporate the logic from those, but I think my issue is that I know actual nothing about this. It seems like my current issue is I can define variables, but I don't know what to do to make it execute. Here's what I have so far:

$(eval game = '$(twitch vlamish {{game}})'; ID = $(urlfetch json https:// pastebin . com/raw/LUeiDFh9); )

the pastebin:
{"Overwatch 2":"testname1",
"Apex Legends":"testname2",
"World of Warcraft","testname3"}

Apologize for having to break the pastebin link, the site wouldn't let me post with a link. So ideally someone would use the command and when I'm playing overwatch, the output would simply be "testname1".

I appreciate any help, of course. 🙂

It wont work because you have to tell the JSON in your paste which game to look at, try this:

$(eval const game = '$(twitch $(channel) "{{game}}")'; const json = $(urlfetch json https://pastebin.com/raw/XXXXXXXX); json[game];)

Don't forget to replace the paste ID with yours, but no need to replace anything else.

You'll also need to fix your JSON: after "World of Warcraft" it should be a colon (:), not a comma (,).

Thank you so much! that last "json[game]" part is what I wasn't aware of. I've got it working with the test.

Didn't find your answer? The community is on Discord.

Ask on Discord