why does urlfetch remove the spaces when calling the quotes api?

!commands edit !iqMOD -ul=moderator $(eval
a=$(urlfetch json http://twitch.center/customapi/quote/list?token=XXX&no_id=1);

return string when running postman: $(query) test test5
return string when running the command: $(query)testtest5
trying to understand how nightbot works, but the lack of debug tools makes it hard for me to do so.
so why does urlfetch remove the spaces when calling the list for the quotes command? some in detail documentation of nightbot would be greatly appreciated as well. i have already found: What is Nightbot? - Nightbot Docs but it does not describe this behavior but i might have misunderstood something

1 Like

Hey @gamanlogiz!

Okay, a few things first:

  • the quote API isn’t made by Nightdev,
  • with your command here you try to output the entire quote list in the chat, Twitch chat’s limit is 500 characters, so with such command you’ll end up reaching an error very soon.

Now, why does the spaces appear to be removed?
They’re not, in fact there isn’t spaces in the output of the API, if you open the link you’re trying to fetch in your browser, you’ll notice that every quote is on a new line, and since Twitch chat doesn’t support new lines, it puts everything on a single line. Nightbot has nothing to do with the presence or absence of spaces here, it’s a combination of how the API is built and how Twitch chat works.

hey @Emily

thanks for taking your time to answer my question!
I am aware that quotes api is separate from nightbot and that there is a chat limit, this code is mostly to try to understand how things work and purely for testing. what i did not understand however is that twitch chat removes line breaks, which is information i greatly appreciate.

after doing some testing i am still a bit confused doe. since this code still returns 1
!commands edit !iqMOD -ul=moderator $(eval
a=$(urlfetch json http://twitch.center/customapi/quote/list?token=ed9dbc83).split(/\n/g);

while the regex test with the postman output for the same url returns 5 matches.

does it take away the line breaks even when the text is not outputted to twitch chat? or am i misunderstanding something?

I looked into it, and I’d like to correct part of my statement, it appears to breaks into new lines using HTML and CSS.

Anyway, the way we usually do what you’re trying to do is we add an extra character when we add a quote, so let’s say a vertical line | for example, and then we split with that: .split('|').

I ended up using your solution and putting ‘/’ as a delimiter as a way to separate each entry combined with ‘&no_id=1’ to remove the numbers. thank you for your time so far, i appreciate it!

1 Like

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