|
Joined: Jan 2015
Posts: 3
Self-satisified door
|
OP
Self-satisified door
Joined: Jan 2015
Posts: 3 |
Hi all! I've spent pretty much the last day solidly learning how to script in mirc (oh, and I had an exam xD). It's gone well but I've hit one final stumbling block... I want to type !elo <nickname> in my channel, and have my bot respond with the elo of <nickname>. The information is handily stored on this website (e.g. nickname = earth_quake): http://www.qlranks.com/api.aspx?nick=earth_quakeI have managed to make my bot print out the header of the webpage...but nothing else. When I try other websites I can print the entire html source of the webpage. What is going wrong? Any help would be much appreciated 2nd question: How can I create a global variable defined in "on $*:text:!elo*:#: {" that contains the <nickname> specified, that is then accessible in "on *:SOCKOPEN:QLR: {" ? i.e. GET /api.aspx?nick=<nickname> on $*:text:!elo*:#: {
msg $chan Getting elo for $$2 ...
if ($sock(QLR)) {
.sockclose QLR
msg #prdxclan Socket already open! Closed socket, trying again...
}
sockopen QLR www.qlranks.com 80
}
on *:SOCKOPEN:QLR: {
msg #prdxclan Opened socket...
; $sockname stands for the name of the socket - QLR
sockwrite -n $sockname GET /api.aspx?nick=earth_quake HTTP/1.1
sockwrite -n $sockname Accept: */*
sockwrite -n $sockname Accept-Language: en-us
sockwrite -n $sockname User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; DigExt)
sockwrite -n $sockname Host: www.qlranks.com
sockwrite -n $sockname
sockwrite $sockname $crlf
; sent data to QLR socket requesting the api info for earth_quake
}
on *:SOCKREAD:QLR: {
if ($sockerr > 0) return
:nextread
sockread %temp
; read the data coming from the socket
if ($sockbr == 0) { sockclose %sockname }
; if i've read all the data, stop
if (%temp) { msg #prdxclan %temp }
; if there was stuff received from the socket, then echo it
goto nextread
}
on *:SOCKCLOSE:QLR: {
msg #prdxclan Closed socket.
}
Thank youuuuuu <3
|
|
|
|
Joined: Apr 2010
Posts: 969
Hoopy frood
|
Hoopy frood
Joined: Apr 2010
Posts: 969 |
If you don't mind using other scripts to help you, you could use my json parsing script to make the code quite easy: ; on a message starting with "!elo <name>" sent to any channel
on *:TEXT:!elo ?*:#:{
; open a json handler to the required page($2 is the specified nick)
jsonopen -ud elo http://www.qlranks.com/api.apsx?nick= $+ $2
; get the number of player results
var %x = 0, %len = $json(elo, players, length)
; loop over each player
while (%x < %len) {
; Grab the player data for each 'section'
; Done like this so you can see how I got the data
var %pname = $json(elo, players, %x, nick)
var %ca_rank = $json(elo, players, %x, ca, rank)
var %ca_elo = $json(elo, players, %x, ca, elo)
var %ca = %ca_rank $+ ( $+ %ca_elo $+ )
var %dual_rank = $json(elo, players, %x, dual, rank)
var %dual_elo = $json(elo, players, %x, dual, elo)
var %dual = %dual_rank $+ ( $+ %dual_elo $+ )
var %tdm_rank = $json(elo, players, %x, tdm, rank)
var %tdm_elo = $json(elo, players, %x, tdm, elo)
var %tdm = %tdm_rank $+ ( $+ %tdm_elo $+ )
var %ctf_rank = $json(elo, players, %x, ctf, rank)
var %ctf_elo = $json(elo, players, %x, ctf, elo)
var %ctf = %ctf_rank $+ ( $+ %ctf_elo $+ )
var %ff_rank = $json(elo, players, %x, ff, rank)
var %ff_elo = $json(elo, players, %x, ff, elo)
var %ff = %ff_rank $+ ( $+ %ff_elo $+ )
; message the channel with:
; [ELO] earth_quake - CA: 6058(1747) - Dual: 16079(1287) - TDM: 170276(700) - CTF: 7437(1739) - FF: 45786(1828)
msg # [ELO] %pname - CA: %ca - Dual: %dual - TDM: %tdm - CTF: %ctf - FF: %ff
; Increase %x to move on to the next player if any
inc %x
}
}
Last edited by FroggieDaFrog; 12/01/15 11:55 PM.
|
|
|
|
Joined: Jan 2015
Posts: 3
Self-satisified door
|
OP
Self-satisified door
Joined: Jan 2015
Posts: 3 |
hey! Thanks so much, this is great! Unfortunately it's not working for me 100%. I fixed a few typos you made (dual->duel and ff ->ffa) but other than that I don't know what to change. I'm getting: [ELO] - CA: () - Duel: () - TDM: () - CTF: () - FFA: () i.e. none of the json vars are working properly. I installed the json for mirc script from here: ( http://hawkee.com/snippet/10194/) Any suggestions? Thanks EDIT: I placed "JSONList" just below the "JSONOpen" line, and I got the message: "* No active JSON handlers"
Last edited by prdxeq; 13/01/15 12:58 PM.
|
|
|
|
Joined: Dec 2008
Posts: 1,515
Hoopy frood
|
Hoopy frood
Joined: Dec 2008
Posts: 1,515 |
Well good job FroggieDaFrog but some values was incorrect typo and the url too, try use this one (fixed).
; on a message starting with "!elo <name>" sent to any channel
on *:TEXT:!elo ?*:#:{
; open a json handler to the required page($2 is the specified nick)
jsonopen -ud elo http://www.qlranks.com/api.aspx?nick= $+ $2
; reporting an error message if any errors appear while trying to open the json
if (%JSONError) { msg # [ELO]: Error, There was an connection problem to the qlranks.com website, please try again later! | goto end }
; get the number of player results
var %x = 0, %len = $json(elo, players, length)
; loop over each player
while (%x < %len) {
; Grab the player data for each 'section'
; Done like this so you can see how I got the data
var %pname = $json(elo, players, %x, nick)
var %ca_rank = $json(elo, players, %x, ca, rank)
var %ca_elo = $json(elo, players, %x, ca, elo)
var %ca = %ca_rank $+ ( $+ %ca_elo $+ )
var %dual_rank = $json(elo, players, %x, duel, rank)
var %dual_elo = $json(elo, players, %x, duel, elo)
var %dual = %dual_rank $+ ( $+ %dual_elo $+ )
var %tdm_rank = $json(elo, players, %x, tdm, rank)
var %tdm_elo = $json(elo, players, %x, tdm, elo)
var %tdm = %tdm_rank $+ ( $+ %tdm_elo $+ )
var %ctf_rank = $json(elo, players, %x, ctf, rank)
var %ctf_elo = $json(elo, players, %x, ctf, elo)
var %ctf = %ctf_rank $+ ( $+ %ctf_elo $+ )
var %ff_rank = $json(elo, players, %x, ffa, rank)
var %ff_elo = $json(elo, players, %x, ffa, elo)
var %ff = %ff_rank $+ ( $+ %ff_elo $+ )
; message the channel with:
; [ELO] earth_quake - CA: 6058(1747) - Duel: 16079(1287) - TDM: 170276(700) - CTF: 7437(1739) - FF: 45786(1828)
msg # [ELO] %pname - CA: %ca - Duel: %dual - TDM: %tdm - CTF: %ctf - FF: %ff
; Increase %x to move on to the next player if any
inc %x
}
:end
jsonclose elo
}
|
|
|
|
Joined: Jan 2015
Posts: 3
Self-satisified door
|
OP
Self-satisified door
Joined: Jan 2015
Posts: 3 |
|
|
|
|
Joined: Apr 2010
Posts: 969
Hoopy frood
|
Hoopy frood
Joined: Apr 2010
Posts: 969 |
Sorry for the typos, I sort of rushed it, thanks westor for fixing them.
With that said, /jsonclose isn't needed at the end, as the -d switch with jsonopen will close the handler automatically as soon as the onText event finishes
|
|
|
|
|