Returning the number of items in a pastebin?

I have a Nightbot command for Twitch that outputs a basic “[USER] is a/an [ADJECTIVE] [NOUN] [CLAUSE]” type sentence, with each pulling from a pastebin list. This all functions as I want it to. However, I am trying to figure out how to create a stats command for it that will display the number of items in each list, and the total number of combinations. Ideal output would be something like "Command has COUNT1 adjectives, COUNT2 nouns, and COUNT3 clauses for a total of [COUNT1*COUNT2*COUNT3] combinations!"

How can I achieve this?

Alternatively, if it’s not possible, is there a way to force nightbot to return a specific line from a pastebin? I have a hacky workaround in mind if I can do that.

Hey @FancySkunk!

It depends on how your command is built, including the Pastebin, if we can’t see your code we can’t help you.

Anyway, you can try to do it yourself with the length property.


The info on the length property was extremely helpful. I was able to automatically pull the list lengths for the stats command. I’m just not sure how to output math using those numbers now for the total combinations:

The !iam command currently has $(eval a=`$(urlfetch json`.split(;);(a.length-1);) adjectives, $(eval n=`$(urlfetch json`.split(;);(n.length-1);) nouns, and $(eval c=`$(urlfetch json`.split(;);(c.length-1);) clauses. That’s 47,935,818 possible combinations! attacPoppop WOW!

I’ve tried a few different things but really not sure what I’m doing. I’m a bit concerned about character count at this point, so I might resign to just using a fuzzy version of the number (like “almost 48 million”) and updating it manually here and there.

Nice, glad you were able to figure part of it out, it’s great you gave it a try!

The solution is to have all of the $(urlfetch) inside one $(eval), so something like this:

$(eval a = `$(urlfetch json RAW_PASTEBIN_LINK)`.split(`;`).length - 1; n = `$(urlfetch json RAW_PASTEBIN_LINK)`.split(`;`).length - 1; c = `$(urlfetch json RAW_PASTEBIN_LINK)`.split(`;`).length - 1; `The !iam command currently has ${a} adjectives, ${n} nouns, and ${c} clauses. That's ${Intl.NumberFormat().format(a * n * c)} possible combinations!`)

Or to keep the code DRY:

$(eval l = (u) => u.split(`;`).length - 1; a = l(`$(urlfetch json RAW_PASTEBIN_LINK)`); n = l(`$(urlfetch json RAW_PASTEBIN_LINK)`); c = l(`$(urlfetch json RAW_PASTEBIN_LINK)`); `The !iam command currently has ${a} adjectives, ${n} nouns, and ${c} clauses. That's ${Intl.NumberFormat().format(a * n * c)} possible combinations!`)

Thank you so much! This works like a charm.

I had tried having them all in one $(eval) but I must have been messing something up a bit because it wasn’t working. Jumping into making commands has been a heck of a time. I took a javascript class about a decade ago, but that’s all I really have for experience. :sweat_smile:

1 Like

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