Random Icebreaker In Chat

Hi all. Incredibly new to Nightbot and bots in general… I’ve been working off of other posts to try to create a command that pulls from pastebin to ask a random question in chat to keep conversation going. I have four pastebins right now (will maybe add more) so that the “under 400 character” limit is handled. I’m still getting errors when I used my command in chat. Sometimes it’s the 400 character error (which I have checked several times) and sometimes it just pulls the same question over and over.

Can you help me figure out what this newbie is doing wrong?

ibq

Can’t test your code since it’s an image, but try using $(urlfetch json https://pastebin.com/raw/...) by adding the json parameter to the urlfetch, if I remember correctly this will help with the character limit error.
With that you should be able to use a single pastebin, the length shouldn’t really matter.

1 Like

@thekatisalie

Like xgerhard said, having json in $(urlfetch) allows Nightbot to pull responses that are over 400 characters long, so feel free to move all of your responses onto one single Pastebin file. This will remove the need to use concat() to combine multiple lists of responses.


Choose an uncommonly used character or string of characters to use as your separator in split() and to put at the end of each response. The problem with using a common character like a comma is that there are other commas located in places other than at the end of each response. This means that your responses will get split in the wrong places. For example, look at these lines from https://pastebin.com/raw/hNzmAjNn

What’s the best book or series that you’ve ever read?,
If you didn’t have to sleep, what would you do with the extra time?,

Using a comma as the separator in split(), the responses should be:

What’s the best book or series that you’ve ever read?
If you didn’t have to sleep, what would you do with the extra time?

But because there’s a comma inside the second line, the responses will actually be:

What’s the best book or series that you’ve ever read?
If you didn’t have to sleep
what would you do with the extra time?

Your other set of responses at https://pastebin.com/raw/jcyPPsci has many commas per line, which will make the list of responses an even bigger mess.


Therefore I suggest putting a rare character or a unique string of characters like a double comma (,,) at the end of each line and using that rare character/string of characters as your separator in split(). If you do decide to move all of your responses to one file, make sure that each line has the same character/string of characters at the end.

Assuming you move all responses to one file, the command response should look something like this:

$(eval a="$(urlfetch json https://pastebin.com/raw/FOOrBARj)".split("separator");a[Math.floor(Math.random()*a.length)])

Where separator is replaced by your rare character/string of characters separator.

2 Likes

This works perfectly. THANK YOU.

1 Like

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