mIRC Homepage

Some help

Posted By: moshkin

Some help - 15/12/06 08:07 PM

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.
Posted By: Riamus2

Re: Some help - 15/12/06 10:02 PM

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
Posted By: moshkin

Re: Some help - 16/12/06 06:21 PM

Seeing that dictionary script, wanna just make the the script :P
naa, im going to try, looks complicated though o.0
Posted By: moshkin

Re: Some help - 16/12/06 07:05 PM

Yeah, can someone make me one, and i will learn by just looking at it?
Posted By: Riamus2

Re: Some help - 16/12/06 09:11 PM

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.
Posted By: moshkin

Re: Some help - 18/12/06 07:13 PM

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
  } 
Posted By: Riamus2

Re: Some help - 18/12/06 07:20 PM

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.
Posted By: moshkin

Re: Some help - 19/12/06 05:45 PM

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
  } 
 
Posted By: Riamus2

Re: Some help - 19/12/06 10:06 PM

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).
Posted By: moshkin

Re: Some help - 20/12/06 02:12 PM

which bit tells it to get the word?
Posted By: Riamus2

Re: Some help - 20/12/06 02:31 PM

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.
Posted By: moshkin

Re: Some help - 27/12/06 12:15 PM

yep, no idea.
© 2022 mIRC Discussion Forums