mIRC Homepage
Posted By: lassyakjedi Getting data from website - 06/09/10 04:13 PM
Hey guys ,
I'm not much of an mirc coder at the moment, but have managed to create a decent bot smile
My query here is ,is there any way to link a particular website to my bot using scripts.Scripts that read data from the website and transfer it to my bot,when some user triggers my bot?
Basically i am making a bot that reads data from a text based gaming site (Take www.ruinsofchaos.com ,for example)

Example:
If there is a player named ABC on the website,
in my mirc window when i type '!link ABC'
i want my bot to display that particular players link.
something like
Code:
<user>!link ABC
<Bot>http://www.ruinsofchaos.com/stats.php?id=4358952
Posted By: Tomao Re: Getting data from website - 06/09/10 07:43 PM
You may need to write a socket script to receive info from and send your request to a website.
Posted By: lassyakjedi Re: Getting data from website - 12/09/10 05:12 AM
Can u be a little bit more clear please, im new to mirc scripting so wont understand all the advanced stuff :p

Posted By: Chessnut Re: Getting data from website - 12/09/10 09:38 AM
you could try this tutorial i wrote: http://forum.swiftirc.net/viewtopic.php?t=4378
Posted By: lassyakjedi Re: Getting data from website - 12/09/10 10:46 AM
ok will go through that and give it a try smile
Also ,are all sockets written in remotes or Aliases ?
Posted By: Riamus2 Re: Getting data from website - 12/09/10 01:56 PM
Everything is written in Remotes except aliases (and those can be written in remotes if prefixed with "alias"). Unless someone says otherwise, anything given on this forum will usually go into Remotes.
Posted By: lassyakjedi Re: Getting data from website - 12/09/10 03:22 PM
I gave my best shot after reading that tutorial...Great tutorial btw Chessnut smile
The beginning was easy enough to follow but i got stuck when i came to the SOCKREAD and SOCKCLOSE parts.

The game name is kingsofchaos as i said earlier
Quote:
Example:
If there is a player named ABC on the website,
in my mirc window when i type '!link ABC'
i want my bot to display that particular players link.
something like
Code:

<user>!link ABC
<Bot>http://www.kingsofchaos.com/stats.php?id=4358952 (just an example)


This is what i have managed to do so far.
Also all url of players are on the battlefield.php if that helps.(http://www.kingsofchaos.com/battlefield.php)

Code:
sockopen kocsock www.kingsofchaos.com 80
on $*:text:!link*:#: {
if ($sock(kocplay)) .sockclose kocplay
set %kocplayway $iif($left($1,1) == @, msg $chan, notice $nick)
sockopen kocplay www.kingsofchaos.com.com 80
}
on *:SOCKOPEN:kocplay: {
sockwrite -nt $sockname GET /lang/en/aff/kingsofchaos/title.ws HTTP/1.1
sockwrite -nt $sockname Host: www.kingsofchaos.com
sockwrite -nt $sockname $crlf
}
on *:SOCKREAD:kocplay: {
  if ($sockerr) { halt }
  else {
  ...
  }
}

Any help will be appreciated smile
Thanks in advance!
Posted By: lassyakjedi Re: Getting data from website - 09/10/10 01:55 PM
Anyone help please wink
Posted By: Riamus2 Re: Getting data from website - 09/10/10 03:28 PM
Remove www. from your sockopen command (remove the duplicate one at the top), remove the duplicate .com from the sockopen command, and try HTTP/1.0 instead of 1.1. Also, if it's on battlefield.php, you should use that in your GET instead of what you have there now.
Posted By: N3M3S1S Re: Getting data from website - 09/10/10 10:09 PM
You may have to add certain functions so that it responds to that website's syntax.

Code:
on *:TEXT:!kings*:#: {
  %king.chan = $chan
  kingsofchaos $1-
}
alias kingsofchaos {
  ;add syntax to variable here
  %king.srch = $1-
  sockclose kings
  sockopen kings kingsofchaos.com 80
}
on *:SOCKOPEN:kings: {
  ;might have to add log-in as well
  sockwrite -n $sockname GET %king.srch HTTP/1.0
  sockwrite -n $sockname Host: www.kingsofchaos.com
  sockwrite -n $sockname Connection: Keep-Alive
  sockwrite -n $sockname Content-Type: text/html
  sockwrite -n $sockname $crlf
}
on *:SOCKREAD:kings: {
  sockread %kings

  ;may need to add $regex or $regml to sperate info from html.
  %king.num = 1

  ;change the number to appropriate number of information
  if (%king.num < 6) { 
    msg %king.chan %kings
    inc %king.num
  }
  elseif (%king.num >= 6) { sockclose king }
}
on *:SOCKCLOSE:king: { unset %king* }


Try something like that or improve upon this. I just threw it together as an example. One thing I noticed is that in order to do anything with that website you might have to have the bot log into the website through the sockets as well.
Posted By: FroggieDaFrog Re: Getting data from website - 10/10/10 03:20 AM
So i've been looking into it, and here is the problem, due to them using multiple pages to return the result if the player being searched for is on any page other than the first, I can't make an easy way to get it :\
Posted By: lassyakjedi Re: Getting data from website - 10/10/10 06:41 PM
Originally Posted By: N3M3S1S
You may have to add certain functions so that it responds to that website's syntax.

Code:
on *:TEXT:!kings*:#: {
  %king.chan = $chan
  kingsofchaos $1-
}
alias kingsofchaos {
  ;add syntax to variable here
  %king.srch = $1-
  sockclose kings
  sockopen kings kingsofchaos.com 80
}
on *:SOCKOPEN:kings: {
  ;might have to add log-in as well
  sockwrite -n $sockname GET %king.srch HTTP/1.0
  sockwrite -n $sockname Host: www.kingsofchaos.com
  sockwrite -n $sockname Connection: Keep-Alive
  sockwrite -n $sockname Content-Type: text/html
  sockwrite -n $sockname $crlf
}
on *:SOCKREAD:kings: {
  sockread %kings

  ;may need to add $regex or $regml to sperate info from html.
  %king.num = 1

  ;change the number to appropriate number of information
  if (%king.num < 6) { 
    msg %king.chan %kings
    inc %king.num
  }
  elseif (%king.num >= 6) { sockclose king }
}
on *:SOCKCLOSE:king: { unset %king* }


Try something like that or improve upon this. I just threw it together as an example. One thing I noticed is that in order to do anything with that website you might have to have the bot log into the website through the sockets as well.


Well i get This Error:
<&Btxx>!kings dark222
<~Bot1> <html>
<~Bot1> <head><title>400 Bad Request</title></head>
<~Bot1> <body bgcolor="white">
<~Bot1> <center><h1>400 Bad Request</h1></center>
<~Bot1> <hr><center>nginx/0.6.32</center>
<~Bot1> </body>
<~Bot1> </html>
© mIRC Discussion Forums