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:
Carlos Alcaraz
Novak Djokovic
Daniil Medvedev
Holger Rune
Casper Ruud
Jannik Sinner
Stefanos Tsitsipas
Andrey Rublev
Taylor Fritz
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.
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…
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 ^^
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…
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…
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)
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!