Menteroth   -  Oct 20, 2013

Hello people. I would like to ask for some help to create a script. Actually it's more than just help. If anyone could create this socket script for me I would be much appreciated. Never played around with socket scripts and am really new to scripts in general.

When you search for someone on www.lolking.net this is what you get. Because of the different regions you don't get the profile page instantly. But this is enough info anyway.

Image

I would like to get this info sent to the channel when triggered.

Like usage: !elo euw menterothh
and it would return like:

Menterothh - EUW - Level: 30 - League: Silver I - Rating: 1456 - Wins: 152 - Losses: 137 - KDA: 4/4.2/10.7 The three regions I would like to have are "Europe West", "Europe Nordic & East" and "North America". Which will be abbreviated to EUW, EUNE and NA in the response. If it's not too much it would be nice to have responses if nothing is typed after the command, region isn't matched with EUW, EUNE or NA and if nickname is missing so people in the channel understand what they are doing wrong if they don't get a response from the bot. Thanks in advance.
Meta  -  Oct 25, 2013

Try this. Let me know if there's any issues with it... The output's not EXACTLY as you've described, but if you want it to be, that can easily be fixed.

on *:TEXT:!elo*:#:lkstats $2-
on *:ACTION:!elo*:#:lkstats $2-
;---------------------------------------------------------------------------------------------;
alias lkue return $regsubex($1,/(\W)/g,$iif(\t == $chr(32),+,$+(%,$base($asc(\t),10,16))))
alias lkstats {
  if $sock(lkstats) { .notice $nick Please wait while the previous lookup request finishes }
  elseif $0 < 2 { 
    .notice $nick Please specify a region and a player
    .notice $nick Valid Regions are: EUW, EUNE, NA
  }
  elseif !$istok(EUW EUNE NA,$1,32) {
    .notice $nick Invalid Region: $qt($1)
    .notice $nick Valid Regions are: EUW, EUNE, NA
  }
  else {
    var -g %lk.c #, %lk.r $1, %lk.u $2- 
    sockopen lkstats www.lolking.net 80
    msg # Searching for $qt($2-) in $replace($1,EUW,Europe West,EUNE,Europe Nordic & East,NA,North America) $+ ...
  }
}

on *:SOCKOPEN:lkstats:{
  if $sockerr { 
    .msg %lk.c Unable to connect to site
    return
  }
  sockwrite -nt $sockname GET /search?name= $+ $lkue(%lk.u) HTTP/1.1
  sockwrite -n $sockname Host: www.lolking.net
  sockwrite -n $sockname Connection: close
  sockwrite -n $sockname $crlf
}

on *:SOCKREAD:lkstats:{
  if $sockerr { 
    .msg %lk.c Unable to connect to site
    return
  }
  var %sock | sockread %sock
  if $regex(%sock,m@"search_result_item(?:_disabled)?".+?/[^/]+/([a-z]+)/@i) { sockmark $sockname $iif($regml(1) == %lk.r,1) }
  if $sock($sockname).mark {
    tokenize 15 $regsubex(%sock,/(<[^>]+>|  )/g,$iif(</ isin \t\,))
        msg %lk.c $iif($0 < 11,User Not Ranked,$replace($+($2/,$5/,$4),Level,Level/League/Rating:) -- W/L: $+($6/,$8) -- KDA: $10)
    unset %lk.*
    sockclose $sockname
  }
}

on *:SOCKCLOSE:lkstats:{
  msg %lk.c No Results found.
  unset %lk.*
}

Examples of script in use (including errors):

[15:27 10/25] <~Meta> !elo euw
[15:27 10/25] -blahahaha- Please specify a region and player
[15:27 10/25] -blahahaha- Valid Regions are: EUW, EUNE, NA

[15:27 10/25] <~Meta> !elo euwe Menterothh
[15:27 10/25] -blahahaha- Invalid Region: "euwe"
[15:27 10/25] -blahahaha- Valid Regions are: EUW, EUNE, NA

[15:28 10/25] <~Meta> !elo euw Menterothh
[15:28 10/25] Searching for "Menterothh" in Europe West...
[15:28 10/25] Level/League/Rating: 30/Silver I/1476 :: Wins/Losses: 186/180 :: KDA: 4.1/4.2/10.2

[15:28 10/25] <~Meta> !elo euw test
[15:28 10/25] Searching for "test" in Europe West...
[15:28 10/25] User Not Ranked

[15:28 10/25] <~Meta> !elo euw aasdjk
[15:28 10/25] Searching for "aasdjk" in Europe West...
[15:28 10/25] No Results found.

Menteroth  -  Oct 26, 2013

wow. thank you very much.

(mentbot) Level/League/Rating: 30/Silver I/1476 -- W/L: 186/ 180 -- KDA: 4.1/4.2/10.2

just changed a little of the output to shorten the text. wasn't hard to find.

I do get a space in the output after the "/" here:
W/L: 186/ 180

but it only shows up in the twitch chat. in the IRC-client it's fine with no space though.
no big deal. just a little annoying. but if it can't really be fixed it's okay.

and again. thank you very much.

Meta  -  Oct 26, 2013

Turns out there was a tab there; I've updated the code to strip them out, (and also to reflect your output), so try it now.

Menteroth  -  Oct 26, 2013

nice. thanks a lot. much appreciated.

Menteroth  -  Oct 30, 2013

for some reason all I get now is "No Results found."
I went to the site and searched manually to check it still worked properly and it did.
would you know what's causing it maybe?

Meta  -  Oct 30, 2013

Hm... It's working fine for me. Nevertheless, I changed /search.php?name= to /search?name= (as it appears in the url in browser), so see if that makes a difference.

Menteroth  -  Oct 30, 2013

is there some way I can check if the connection is being blocked or something?
since it seems to close the socket instantly (where the 'no results found' message) and worked before.

Edit: I might add that the urban dictionary script still works.

Menteroth  -  Nov 01, 2013

it started working again, after I got a new IP when my network card reset for some reason.
not sure how it works though, since I could still search on the site. oh well.

Menteroth  -  Nov 01, 2013

this turned out like this for some reason

(11:28:21) (menteroth) !elo eune Menteroth
(11:28:26) (mentbot) East/1500/Menteroth -- W/L: Gold V/Wins -- KDA: Losses

but NA region worked fine

(11:31:26) (menteroth) !elo na Menteroth
(11:31:29) (mentbot) Level/League/Rating: 30/Silver I/1500 -- W/L: 39/33 -- KDA: 5.2/5.7/9.9

Meta  -  Nov 01, 2013

the ; in the & html entity for & was screwing with the tokenization. Try now.

Menteroth  -  Nov 01, 2013

same weird response.

Meta  -  Nov 01, 2013

After updating the code? This is what I got:

[22:38 11/01] <~Meta> !elo eune menteroth
[22:39 11/01] Searching for "menteroth" in Europe Nordic & East...
[22:39 11/01] Level/League/Rating: 30/Gold V/1500 -- W/L: 35/30 -- KDA: 5.1/3.8/11.9

Menteroth  -  Nov 02, 2013

thanks. it works now.

nildnab  -  Feb 26, 2014

I used to use this and it no longer works, just keep getting unable to connect to site. Can someone else test this and tell me if it's still working?

Menteroth  -  Apr 01, 2014

The reason the script isn't working at the moment is that they changed the site.
So we'll just have to wait until Meta, if he feels like it, to update it or perhaps someone else.

Sign in to comment

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.