Command to fetch specific info

Asked Sep 7, 2023·35 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.

Hello guys
I wonder if it's possible to create a command which can fetch the specific ranking of a tennis player from a pastebin list. For example this week's top ten players are:

1. Carlos Alcaraz
2. Novak Djokovic
3. Daniil Medvedev
4. Holger Rune
5. Casper Ruud
6. Jannik Sinner
7. Stefanos Tsitsipas
8. Andrey Rublev
9. Taylor Fritz
10. Frances Tiafoe

and I would like a command called !rank player's_last_name to respond in which ranking position the desired player is. Not only for the top ten though, I'd like to have one with the first 100 players in the world. Do you think it can be done? there's a limit of characters in nighbot as you already know.

35 replies

all at once, no... not just the limit in nightbot, but twitch has a 400 character limit too... 100 names could only be 4 characters long with no spaces in between...

The idea of the command is to bring up just one name, not the whole list.

sorry, i was hoping somebody else would jump in... i can try and mess with it, but i'm not really familiar with pastebin...but i would need a paste to play with, so pass one over and i'll see what i can do ^^

Possible you can drop the pastebin that contains the data ?
I can give a shot.

idk where this list is from, but is it possible to have the list with a special character after each name?
if u can get that i can do it, but as is, idk how i'd teach it to differentiate between players, if all names were only first and last i could do it by number of names, but some have 3 or 4 names for one player...

special character for example, how? maybe the number of the ranking and the name?
1 xplayer
2 xplayer and so on?

uh, could be any specific character... if u want it to look more natural maybe a comma or something... like...
name one,
name two,
etc...
or semicolon like...
name one ;
name two ;
etc...
as long as each line has the same one (the last line doesn't need it, but not bad if it has it)

or even if the special character was before the name, that'd make a small part of the code easier actually... but the last one DOES need it if it's before the name, like maybe...

#name one
#name two

as long as the character is the same on each line

something like this maybe? we could try it just with the top 10 players first
#1 Novak Djokovic
#2 Carlos Alcaraz
#3 Daniil Medvedev
#4 Jannik Sinner
#5 Andrey Rublev
#6 Stefanos Tsitsipas
#7 Alexander Zverev
#8 Holger Rune
#9 Hubert Hurkacz
#10 Taylor Fritz

Oh! I implemented this when you first asked, but my account was in jail so I couldn't reply, and then I forgot.

Here's some nightbot incantation to do what you want:

$(eval q="$(querystring)"; p=$(urlfetch json https://pastebin.com/raw/4tus3Z1H).split(","); i=p.findIndex(e => e.toLowerCase().includes(q.toLowerCase())); (i < 0) ? q + " is not in the top 100" : p[i] + " is in position " + (i + 1))

Right now it's referencing a pastebin text at https://pastebin.com/raw/4tus3Z1H that I posted with quotes around your entire list, and commas between each player. It needs that format to split character names up effectively. If you replace the pastebin with updated standings, the command will still work.

Lookups could fail if the list has multiple players with the same last name! (It will always find the first player with that name in the list)

you're a wizard, amazing command. One question, how many names can this list contain? is there a limit?

easily more than what you ever need.

I think each nightbot command has a time limit to run. if the text file gets too large, you might exceed the limit just by loading all the text. You can probably get a list of 1000 or more before hitting that time limit though!

it would just take to edit the pastebin list, not the actual command or am I wrong?

technically both, but the only thing u need to do to the command is update the pastebin link ;)

yeah you'll want to edit the pastebin link in the command when you first set the command in nightbot, to point to text that you control.

after that, updating the pastebin text is good enough!

thanks a lot for your help. it's really amazing what you've done

Hi brother, I updated the list using the same model of yours but it's not working now, any ideas?

Can you share your updated list? Hopefully it's just a small formatting tweak so the javascript code can handle it

I think that's failing because the very last player has a comma after their name. If you delete the last comma, things should work again!

Nightbot might cache the pastebin data for a short time, so if the command doesn't work immediately, it should work within a few hours.

I fixed it but it's still not working, not even showing anything in chat

i wonder if changing "$(querystring)" to "$(query)" would help...

hmmm... can u paste the command contents, maybe u accidentally removed a symbol when updating the pastebin link

oh wait... did u use that exact link u posted earlier?... because u left out the "raw" portion...

it worked for me... the first 2 tries r with "$(querystring)" and the last one is with "$(query)" so that change actually does help... but if i had to guess, the "raw" part of the link was left out... this is what i have, that worked on the last try in the pic...

js
$(eval q="$(query)"; p=$(urlfetch json https://pastebin.com/raw/SEya1Ynh).split(","); i=p.findIndex(e => e.toLowerCase().includes(q.toLowerCase())); (i < 0) ? q + " is not in the top 100" : p[i] + " is in position " + (i + 1))

hope that does it for ya ^^

image.png

but this is discord, isn't it? not in twitch chat

well, yes, but the only difference in output is how it handles usernames... it shows the core username instead of the display name ("nickname")

here it is in twitch... and interestingly it will give the first place one if u don't include a name... purdy cool feature

image.png

but it doesn't work at all. it worked during the first days but now nothing. I used to use the command !ranking name

can u share what u have in the command

$(eval q="$(query)"; p=$(urlfetch json https://pastebin.com/raw/SEya1Ynh).split(","); i=p.findIndex(e => e.toLowerCase().includes(q.toLowerCase())); (i < 0) ? q + " is not in the top 100" : p[i] + " is in position " + (i + 1))

hmmm... everything looks in order... that should work... r there any twitch settings like banned words or anything that would stop it? like automod

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

Ask on Discord