NightDev Community Forums

Need help with a lookup command

Hello all!

I have zero experience with coding, minus my trivial efforts to figure this out on my own (with no success). What I’m looking to do is to use Nightbot in order to lookup definitions to specific keywords for a game that we stream. I have a google sheet with all of the keywords and their definitions but I cannot figure out how to get Nightbot to pull the information.

Essentially what I need is this:

command: !keyword SPECIFICKEYWORD (ex: !keyword bribe)
response: Keyword: Definition. (ex: Bribe: You can fight Villains by spending any combination of Attack and/or Recruit.)

Here is the link to the google sheet of keywords: Keywords - Google Sheets

If this can’t be done through Google sheets, can someone assist with how else to do this?

Greatly appreciate anyone willing to assist! :slight_smile:

Yeah you can do it with google sheets you have to get the page to output the info in json How to use Google Sheets as a JSON Endpoint
Here is a website explaining how to do that. Though I’ve never seen the way it outputs the data so to help you further I would need to see the result.

There is another’s way to do it with pastebin to which I can explain:
Your command will look like this:

$(eval a=$(urlfetch json pastebin_raw_link);a[$(query)])

(This is a really fought draft I’ll make a better version that can handle inputs better should you choose this option)

As for the pastebin it will look like this:

{"Term1":"Explanation",
"Term2":"Explanation",
"TermX":"Explanation",
…}
1 Like

Hi! Thank you so much for the help. I’ve gotten the Terms and explanations input into a pastebin here: (https:// pastebin. com /3WWVfzND) sans spaces

I believe I’ve done it correctly? When I replaced pastebin_raw_link with the link and did !keyword berserk for example. I got the error: Code generation from strings disallowed for this context!
image

Sorry for the quick follow up. Lol. But I realized I didn’t do it with the “raw” link. When I updated that then Nightbot comes back with Invalid or unexpected token.

Ok so here’s code for a command which should work much better:

$(eval a=$(urlfetch json https://pastebin.com/raw/xxxxxx);x=[];y=[];for(string in a){x.push(string);y.push(string.toLowerCase())};y.includes(`$(query)`)?a[x[y.indexOf(`$(query)`)]]:`$(query)`.length==1?`${x.filter(z=>z.match(/^$(query).+/i)).length>0?x.filter(z=>z.match(/^$(query).+/i)).join(`, `):`No matches for “$(query)”.`}`:`$(query)`.length==0?`Either type the name of what your searching or any letter.`:`”$(query)” not found.`)

And secondly the code should work perfectly from my testing. I will tell you however the unexpected identifier is happening in the pastebin somewhere. Most likely you forgot a , or something I’ll look and update this when I find it.

Edit: Ok so the error appears to be three things there is an uneven number of " should be even(it’s possible that if you have a singular “ in one of them that this is wrong) and you accidentally used “ instead of " in quite a few of them and in a few of the key words too finally “Revenge” doesn’t have a ", at the end.

That worked perfectly! Thank you so much!!!