mIRC Home    About    Download    Register    News    Help

Print Thread
Some help #166847 15/12/06 08:07 PM
Joined: Oct 2006
Posts: 60
M
moshkin Offline OP
Babel fish
OP Offline
Babel fish
M
Joined: Oct 2006
Posts: 60
Ok, i want to use this site so when people type !clan <username> i return with their clan. it should use www.runehead.com/clans you can test using my username, Moshkin_khan. I would like soemone to actually explain how to do it, maybe suupporting it with a scripts, please dont just make a script and post it, i want to learn.

Re: Some help [Re: moshkin] #166859 15/12/06 10:02 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
Well, you will need to learn to use sockets. The best way I found to learn sockets is to grab a script that has them and then examine how it works.

If you want, I have 3 scripts online right now that have sockets (http://www.kakkoiitranslations.net/mircscripts/ == weather and dictionary and bible ones), or you can search here for socket scripts and see how they work.

The main things you need to use for them are:

sockopen
on SOCKOPEN
on SOCKREAD

The sockopen event is almost always the same from one script to the next other than to change the site information and url information.

The sockread event starts the same, but then each one will parse the html file. Basically, you need to watch for a line that has the information you need.

For example,

if (*Clan Name* iswm %temptext) { var %clanname = $gettok( something ) }

Then, if a line comes up with Clan Name in it, it will set the clan name variable with whatever $gettok you set up. $gettok is useful for pulling out a specific piece of information from the html line.

Also, you may want to have a $htmlfree alias that you can use to remove all html to make parsing it easier.

The best thing to do will be to look at some scripts and see what they do and try to change one to do what you want it to do. Then, if you have trouble, paste what you have so far and we will help you sort it out.

(best I can do without giving you the script) smile


Invision Support
#Invision on irc.irchighway.net
Re: Some help [Re: Riamus2] #166919 16/12/06 06:21 PM
Joined: Oct 2006
Posts: 60
M
moshkin Offline OP
Babel fish
OP Offline
Babel fish
M
Joined: Oct 2006
Posts: 60
Seeing that dictionary script, wanna just make the the script :P
naa, im going to try, looks complicated though o.0

Re: Some help [Re: moshkin] #166920 16/12/06 07:05 PM
Joined: Oct 2006
Posts: 60
M
moshkin Offline OP
Babel fish
OP Offline
Babel fish
M
Joined: Oct 2006
Posts: 60
Yeah, can someone make me one, and i will learn by just looking at it?

Re: Some help [Re: moshkin] #166924 16/12/06 09:11 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
Well, keep in mind that the script does a lot of extra things that you don't necessarily need. Start by trying to do the sockopen command and the sockopen event yourself and paste them here. Those are basically cut/paste things and you just have to change the host/link info. Note that the GET line in that script uses a variable... you can put the actual address you want instead of a variable if you're just pulling up a single page.


Invision Support
#Invision on irc.irchighway.net
Re: Some help [Re: Riamus2] #167025 18/12/06 07:13 PM
Joined: Oct 2006
Posts: 60
M
moshkin Offline OP
Babel fish
OP Offline
Babel fish
M
Joined: Oct 2006
Posts: 60
Code:
 alias clansock {
  set %word $replace($1-,$chr(32),+)
  sockopen dictionarysock www.runehead.com/clans
}

on *:sockopen:clansock: {
  sockwrite -n $sockname GET /?w= $+ %word $+ &ls=a 

HTTP/1.0
  sockwrite -n $sockname User-Agent: Mozilla/4.0 (compatible; 

MSIE 4.01; Windows NT)
  sockwrite -n $sockname Host: www.runehead.com/clans
  sockwrite -n $sockname Accept-Language: en-us
  sockwrite -n $sockname Accept-Encoding: gzip, deflate
  sockwrite -n $sockname Accept: */* $+ $crlf $+ $crlf
}

on *:sockread:clansock: {
  if ($sockerr) {
    echo -a Error.
    halt
  }
  else {
    var %temptext
    sockread %temptext
    if (*Quick definitions* iswm %temptext) {
      set %clan.clan $htmlfree($gettok($gettok(%

temptext,2,40),1,41))
    }
    if (<LI><b><i>* iswm %temptext) {
      inc %defcnt
      set %clan [ $+ [ %defcnt ] ] $htmlfree(%temptext)
    }
    if (<LI> $+ $chr(40) $+ <I>* iswm %temptext) {
      inc %defcnt
      set %clan [ $+ [ %defcnt ] ] $htmlfree(%temptext)
    }
    if (<P><B> $+ %word $+ </B>* iswm %temptext) {
      inc %defcnt
      set %clan [ $+ [ %defcnt ] ] $gettok($htmlfree(%

temptext),2-,32)
    }
    if (<br><table border=0 cellpadding=0 bgcolor="#ffcccc" 

width=95%>* iswm %temptext) {
      sockclose clansock
      DisplayClan
    }
    if (*</html> iswm %temptext) {
      sockclose dictionarysock
      DisplayClan
    }
  }
}

alias DisplayClan {
  if (%defcnt == $null) {
    msg %clanchan User cannot be found.
    unset %dict.delay
    return
  } 

Last edited by moshkin; 18/12/06 07:14 PM.
Re: Some help [Re: moshkin] #167026 18/12/06 07:20 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
First of all, your sockopen command is opening "dictionarysock" (from my script). You didn't change it to clansock.

Second, you have a sockclose dictionarysock in there too. That can also be removed.

Third, your code here looks like some lines are split onto multiple lines. I'm not sure if that is how it is in your script, or just how it came out here. I'd check it out to be sure.


Invision Support
#Invision on irc.irchighway.net
Re: Some help [Re: Riamus2] #167086 19/12/06 05:45 PM
Joined: Oct 2006
Posts: 60
M
moshkin Offline OP
Babel fish
OP Offline
Babel fish
M
Joined: Oct 2006
Posts: 60
Code:
alias clansock {
  set %word $replace($1-,$chr(32),+)
  sockopen clansock www.runehead.com/clans
}

on *:sockopen:clansock: {
  sockwrite -n $sockname GET /?w= $+ %word $+ &ls=a 

HTTP/1.0
  sockwrite -n $sockname User-Agent: Mozilla/4.0 (compatible; 

MSIE 4.01; Windows NT)
  sockwrite -n $sockname Host: www.runehead.com/clans
  sockwrite -n $sockname Accept-Language: en-us
  sockwrite -n $sockname Accept-Encoding: gzip, deflate
  sockwrite -n $sockname Accept: */* $+ $crlf $+ $crlf
}

on *:sockread:clansock: {
  if ($sockerr) {
    echo -a Error.
    halt
  }
  else {
    var %temptext
    sockread %temptext
    if (*Quick Clan name* iswm %temptext) {
      set %clan.clan $htmlfree($gettok($gettok(%

temptext,2,40),1,41))
    }
    if (<LI><b><i>* iswm %temptext) {
      inc %defcnt
      set %clan [ $+ [ %defcnt ] ] $htmlfree(%temptext)
    }
    if (<LI> $+ $chr(40) $+ <I>* iswm %temptext) {
      inc %defcnt
      set %clan [ $+ [ %defcnt ] ] $htmlfree(%temptext)
    }
    if (<P><B> $+ %word $+ </B>* iswm %temptext) {
      inc %defcnt
      set %clan [ $+ [ %defcnt ] ] $gettok($htmlfree(%

temptext),2-,32)
    }
    if (<br><table border=0 cellpadding=0 bgcolor="#ffcccc" 

width=95%>* iswm %temptext) {
      sockclose clansock
      DisplayClan
    }
    if (*</html> iswm %temptext) {
      sockclose clansock
      DisplayClan
    }
  }
}

alias DisplayClan {
  if (%defcnt == $null) {
    msg %clanchan User cannot be found.
    unset %dict.delay
    return
  } 
 

Re: Some help [Re: moshkin] #167092 19/12/06 10:06 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
It looks good assuming your IF lines are looking for the right data and that your set lines are correct.

Make sure you have the htmlfree alias or it won't work.

Also, your last alias you have there isn't complete. It doesn't have a closing }, but it also seems like it's missing code for what to do if the variable isn't $null.

And don't forget to unset variables once they aren't needed anymore.

If the script isn't working still, mention what is working and what isn't working (I'm at work, so can't test it right now).


Invision Support
#Invision on irc.irchighway.net
Re: Some help [Re: Riamus2] #167132 20/12/06 02:12 PM
Joined: Oct 2006
Posts: 60
M
moshkin Offline OP
Babel fish
OP Offline
Babel fish
M
Joined: Oct 2006
Posts: 60
which bit tells it to get the word?

Re: Some help [Re: moshkin] #167135 20/12/06 02:31 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
Originally Posted By: moshkin
which bit tells it to get the word?


If you mean what part is it to get the data off the page itself, that is what these lines do. The IF checks if a word/phrase is on the line being read (it reads each html line one at a time). If it is, it sets the variable to whatever you tell it to set it to.

Code:
   if (*Quick Clan name* iswm %temptext) {
      set %clan.clan $htmlfree($gettok($gettok(%temptext,2,40),1,41))
    }


In this case, you're using $gettok to locate the whatever is between the first ( and the first ) that follows it. Then, you have it removing html codes from that... assuming you have the $htmlfree alias. That part may be unnecessary if there aren't html codes within those ()'s.


Invision Support
#Invision on irc.irchighway.net
Re: Some help [Re: moshkin] #167601 27/12/06 12:15 PM
Joined: Oct 2006
Posts: 60
M
moshkin Offline OP
Babel fish
OP Offline
Babel fish
M
Joined: Oct 2006
Posts: 60
yep, no idea.