mIRC Home    About    Download    Register    News    Help

Print Thread
Random Quote Script From Sockets #148444 05/05/06 10:16 PM
Joined: May 2006
Posts: 17
S
sithnet Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: May 2006
Posts: 17
Code:
 alias showquote set %chan1 # | sockopen q www.sith-net.com 80

On *:sockopen:q:{
  if $sockerr {
    echo -s - Error: couldn't contact website.
    return
  }
  var %s = sockwrite -tn q
  %s GET www.sith-net.com/f4c/Quotes.php HTTP/1.0
  %s Host: www.sith-net.com
  %s
}
On *:sockread:q:{
  var %s
  sockread %s
  if Quote * iswm %s {
    msg %chan1 13,1 %s
    notice $me 9,1For More Quotes Be Sure To Visit www.Free4Canada.ca/MyQuotes.php
    sockclose q
  }
}
On *:sockclose:q:{
  echo -s - Error: couldn't fetch quote.
} 
 


you can get the quotes several ways
MyQuotes.php isnt done yet but that shouldnt matter

it should go to www.sith-net.com/f4c/Quotes.php
or www.free4canada.ca/Quotes.php
(which is the same addy in reality,

and it should randomly generate a quote from that page
(yes there are only 2 right now)

what is wrong with my code?

Re: Random Quote Script From Sockets #148445 05/05/06 10:36 PM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
I accessed the page manually and this is what i got back.

1 Poul 05/05/06 [18:53] <Aimee> I seen a pic yesterday Raven showed me, of you, you look pretty in your blond hair2 Poul 05/05/06 [13:58] <Phoenix> ok so i just had to fart...but now back to sleeping! not waking!

Since there is no word "Quote" on that line it wont match it when doing the if Quote * iswm %s {

* i would also note there appears to be 2 quotes on one line, but that would appear to be a fault in the php code, or the database.

* also Notciing your self a message "For More Quotes Be Sure To Visit www.Free4Canada.ca/MyQuotes.php" seems rather redundent, and wastefull to irc server bandwidth.

Re: Random Quote Script From Sockets #148446 05/05/06 10:47 PM
Joined: May 2006
Posts: 17
S
sithnet Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: May 2006
Posts: 17
on *:text:!Quotes:*:/showquote
alias showquote set %chan1 # | sockopen q www.sith-net.com 80

On *:sockopen:q:{
if $sockerr {
echo -s - Error: couldn't contact website1.
return
}
var %s = sockwrite -tn q
%s GET /f4c/Quotes.php HTTP/1.0
%s Host: http://www.sith-net.com
%s
}
On *:sockread:q:{
var %s
sockread %s
if quote * iswm %s {
msg %chan1 13,1 %s
notice $me 9,1For More Quotes Be Sure To Visit www.Free4Canada.ca/MyQuotes.php
sockclose q
}
}
On *:sockclose:q:{
echo -s - Error: couldn't fetch quote2.
}

i changed it around it still wont work

Re: Random Quote Script From Sockets #148447 06/05/06 07:53 AM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
i didnt see anything changed around there, your still accessing the same site, your still doing the IF

Re: Random Quote Script From Sockets #148448 06/05/06 01:35 PM
Joined: May 2006
Posts: 17
S
sithnet Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: May 2006
Posts: 17
its an old script,
one i used a long time ago when i was scritping more than I am now,

http://free4canada.ca/Quotes.php

if you look at that,
it randomly pics a quote on its own

Code:
On *:sockread:q:{
  var %s
  sockread %s
  if quote * iswm %s {
    msg %chan1 13,1 %s
    notice $me 9,1For More Quotes Be Sure To Visit www.Free4Canada.ca/MyQuotes.php
    sockclose q
  }
}

i know the if quote *iswm is the problem
but what would i replace it with to give me the whole line that is on the page?

Re: Random Quote Script From Sockets #148449 06/05/06 02:51 PM
Joined: May 2006
Posts: 17
S
sithnet Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: May 2006
Posts: 17
ok ive spent some time trying

again take alook at the site and see how its formated
i just want everything with in the body of the page

but here is the mirc code
Code:
on *:text:!Quotes:*:/showquote
alias showquote set %chan1 # | sockopen q www.sith-net.com 80

On *:sockopen:q:{
  if $sockerr {
    echo -s - Error: couldn't contact website1.
    return
  }
  var %s = sockwrite -tn q
  %s GET /f4c/Quotes.php  HTTP/1.0
  %s Host: http://www.sith-net.com
  %s
}
On *:sockread:q:{
  var %s
  sockread %s

  msg %chan1 13,1 %s
  msg %chan1 9,1For More Quotes Be Sure To Visit www.Free4Canada.ca/MyQuotes.php
  sockclose q
}
}
On *:sockclose:q:{
echo -s - Error: couldn't fetch quote2.
} 


it apears to me that
the code should work,
unless im missing something

but it apeas by the code that it should

Re: Random Quote Script From Sockets #148450 06/05/06 04:35 PM
Joined: Apr 2004
Posts: 759
M
Mpdreamz Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
Could you please be more descriptive what exactly is it not doing? You aren't even saying wheter it works or not.

Being descriptive both helps both you getting a fast answer and us by not wasting precious time.


$maybe
Re: Random Quote Script From Sockets #148451 06/05/06 04:41 PM
Joined: May 2006
Posts: 17
S
sithnet Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: May 2006
Posts: 17
my appologises

when you /showquote
it should put the whole quote into the variable
and display it into the channel
so the channel can see the quote

the php page randomly generates the quote to show it
which when the socket starts the page it should do fine
just want the script to copy and paist the full text on the page.
and right now its not showing anything on the script return

Re: Random Quote Script From Sockets #148452 06/05/06 05:50 PM
Joined: Apr 2004
Posts: 759
M
Mpdreamz Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
You assume you only read one line since thats all you see however when you open a socket connection you send and recieve page headers as well.

Example:
Quote:

HTTP/1.1 200 OK
Date: Sat, 06 May 2006 17:27:53 GMT
Server: Apache/1.3.34 (Unix) mod_fastcgi/2.4.2 mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 FrontPage/5.0.2.2635 mod_ssl/2.8.25 OpenSSL/0.9.7a PHP-CGI/0.1b
X-Powered-By: PHP/4.4.1
Transfer-Encoding: chunked
Content-Type: text/html
62
Poul 05/05/06 [13:58] <Phoenix> ok so i just had to fart...but now back to sleeping! not waking!

This is infact all the data you will recieve.

Also another thing i should note is that though it may seem easier to remove markup in your html for parsing the opposite is true markup lets you pinpoint information fast and discard bad data easy. One of the reasons XML is so popular.

also the code has some hooks i commented in between //'s
Code:
on *:text:!Quotes:*:/showquote
alias showquote set %chan1 # | sockopen q www.sith-net.com 80

On *:sockopen:q:{
  if $sockerr {
    echo -s - Error: couldn't contact website1.
    return
  }
  var %s = sockwrite -tn q
  %s GET /f4c/Quotes.php  HTTP/1.0
  %s Host: http://www.sith-net.com
  %s
  //change the above 3 lines to://
  %s GET /f4c/Quotes.php  HTTP/1.1
  %s Host: sith-net.com $+ $crlf $+ $crlf
  //this will send the correct page headers//
}
On *:sockread:q:{
  var %s
  sockread %s

  msg %chan1 13,1 %s
  msg %chan1 9,1For More Quotes Be Sure To Visit www.Free4Canada.ca/MyQuotes.php
//Place this in the sockclose event as you want to show this AFTER you recieved the page//
  sockclose q 
//you close it here right after you recieve the first line while in fact you want to keep on reading so lose this//
}
}
On *:sockclose:q:{
echo -s - Error: couldn't fetch quote2. 
//sockclose doesnt have to mean an error occured//
}


Right now to discard the headers we have to do alot of if's or a pretty long regex in the parsing. if formatted your line as <quote> quote goes here </quote> all it takes is one simple if statement.


$maybe
Re: Random Quote Script From Sockets #148453 06/05/06 05:58 PM
Joined: May 2006
Posts: 17
S
sithnet Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: May 2006
Posts: 17
Thanks alot smile

ill show you what the code is to make sure that i did what you said right

Code:
on *:text:!Quotes:*:/showquote
alias showquote set %chan1 # | sockopen q www.sith-net.com 80

On *:sockopen:q:{
  if $sockerr {
    echo -s - Error: couldn't contact website1.
    return
  }
  var %s = sockwrite -tn q
  %s GET /f4c/Quotes.php  HTTP/1.1
  %s Host: sith-net.com $+ $crlf $+ $crlf
}
On *:sockread:q:{
  var %s
  sockread %s

  msg %chan1 13,1 %s
  msg %chan1 9,1For More Quotes Be Sure To Visit www.Free4Canada.ca/MyQuotes.php

}
}
On *:sockclose:q:{
echo -s - Error: couldn't fetch quote2.
sockclose q
} 


here is the result of !Quotes
Code:
[14:56] &lt;Raven&gt; !quotes
[14:56] &lt;DrLove&gt;  HTTP/1.1 200 OK
[14:56] &lt;DrLove&gt; For More Quotes Be Sure To Visit www.Free4Canada.ca/MyQuotes.php
[14:56] &lt;DrLove&gt;  Date: Sat, 06 May 2006 17:56:21 GMT
[14:56] &lt;DrLove&gt; For More Quotes Be Sure To Visit www.Free4Canada.ca/MyQuotes.php
[14:56] &lt;DrLove&gt;  Server: Apache/1.3.34 (Unix) mod_fastcgi/2.4.2 mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 FrontPage/5.0.2.2635 mod_ssl/2.8.25 OpenSSL/0.9.7a PHP-CGI/0.1b
[14:56] &lt;DrLove&gt; For More Quotes Be Sure To Visit www.Free4Canada.ca/MyQuotes.php
[14:56] &lt;DrLove&gt;  X-Powered-By: PHP/4.4.1
[14:56] &lt;DrLove&gt; For More Quotes Be Sure To Visit www.Free4Canada.ca/MyQuotes.php
[14:56] &lt;DrLove&gt;  Transfer-Encoding: chunked
[14:56] &lt;DrLove&gt; For More Quotes Be Sure To Visit www.Free4Canada.ca/MyQuotes.php
[14:56] &lt;DrLove&gt;  Content-Type: text/html
[14:56] &lt;DrLove&gt; For More Quotes Be Sure To Visit www.Free4Canada.ca/MyQuotes.php
[14:56] &lt;DrLove&gt; 
[14:56] &lt;DrLove&gt; For More Quotes Be Sure To Visit www.Free4Canada.ca/MyQuotes.php
[14:56] &lt;DrLove&gt;  72
[14:56] &lt;DrLove&gt; For More Quotes Be Sure To Visit www.Free4Canada.ca/MyQuotes.php
[14:56] &lt;DrLove&gt;  Poul 05/05/06 [18:53] &lt;Aimee&gt; I seen a pic yesterday Raven showed me, of you, you look pretty in your blond hair
[14:56] &lt;DrLove&gt; For More Quotes Be Sure To Visit www.Free4Canada.ca/MyQuotes.php
[14:56] &lt;DrLove&gt; 
[14:56] &lt;DrLove&gt; For More Quotes Be Sure To Visit www.Free4Canada.ca/MyQuotes.php
[14:56] &lt;DrLove&gt;  0
[14:56] &lt;DrLove&gt; For More Quotes Be Sure To Visit www.Free4Canada.ca/MyQuotes.php
[14:56] &lt;DrLove&gt; 
[14:56] &lt;DrLove&gt; For More Quotes Be Sure To Visit www.Free4Canada.ca/MyQuotes.php


I'm honestly not sure about <quote>

Re: Random Quote Script From Sockets #148454 07/05/06 04:30 PM
Joined: May 2006
Posts: 17
S
sithnet Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: May 2006
Posts: 17
I'm sorry guys
ive tried the codes
and ive edited and ive tried
but i cant seem to fix it so i just get the one line on the web page
any ideas?

Re: Random Quote Script From Sockets #148455 07/05/06 05:30 PM
Joined: Oct 2005
Posts: 1,741
G
genius_at_work Offline
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
This code will consider every (non-blank) line after the end of the headers to be a quote.
Code:
on *:TEXT:!quotes:#:showquote
alias showquote {
  if ($event == text) set %qm msg $chan
  else set %qm echo -a
  unset %nextline
  if ($hget(quotes)) hfree quotes
  hmake quotes 5
  if ($sock(q)) sockclose q
  sockopen q www.sith-net.com 80
  .timer 1 5 sockclose q
}

on *:SOCKOPEN:q:{
  if ($sockerr) {
    echo -s Error: couldn't contact website1.
    return
  }
  sockwrite -tn q GET /f4c/Quotes.php HTTP/1.0
  sockwrite -tn q Host: www.sith-net.com
  sockwrite -tn q

}
on *:SOCKREAD:q:{
  var %s
  sockread %s
  ;echo 7 -s &gt; %s

  if ((%s == $null) &amp;&amp; (!%nextline)) { set %nextline 1 }
  elseif ((%nextline) &amp;&amp; (%s != $null)) {
    hadd quotes %nextline %s
    inc %nextline
  }
}

on *:SOCKCLOSE:q:{
  var %rand = $r(1,$hget(quotes,0).item)
  %qm $hget(quotes,%rand)
  unset %nextline, %qm
  if ($hget(quotes)) hfree quotes
}


If the webpage has one line, that line will always be shown. If the webpage has multiple quotes on multiple lines, all of the lines will be read and a random one will be chosen and sent.

If the /showquote command is entered manually, the quote will be echo'd to the active window. If someone types !quotes in any channel, the quote will be msg'd to that channel.

-genius_at_work

Re: Random Quote Script From Sockets #148456 07/05/06 08:43 PM
Joined: May 2006
Posts: 17
S
sithnet Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: May 2006
Posts: 17
thank you for the help, ill read the code a few times to try and learn it smile
thank you for your help.