Commands:
!Quote/&Quote/@Quote - posts a random quote to the channel.
!Fact/&Fact/@Fact - posts a random fact to the channel.
I made this with entire purpose to test a few things, like while ($sockbr), and my very remedial regex. I admit I did not entirely code all of the $hhfree, it is my adapted version of $htmlfree (who wrote that? I forget; if someone posts I will give credit.)
Any bugs/feedback/advice please post!
Note: 2 second spam filter per nick
on $*:TEXT:/^[!@&](quote|fact)$/Si:#:{
if (!$($+(%,qspam,$nick),3)) {
var %ticks = $ticks $+ $r(1,100)
while ($sock($+(randomquotesearch,%ticks))) {
var %ticks = $ticks $+ $r(1,100)
}
sockopen $+(randomquotesearch,%ticks) www.ikwote.com 80
sockmark $+(randomquotesearch,%ticks) $+(msg # [Random $+ $chr(32),$iif($regml(1) == fact,Fact,Quote),],:,$iif($regml(1) == fact,fact,quote))
set -u2 $+(%,qspam,$nick) $regml(1)
}
}
on *:SOCKOPEN:randomquotesearch*:{
sockwrite -n $sockname GET / HTTP/1.1
sockwrite -n $sockname Host: www.ikwote.com $+ $crlf $+ $crlf
}
on *:SOCKREAD:randomquotesearch*:{
var %a | sockread %a
tokenize 58 $sock($sockname).mark
while ($sockbr) {
var %ticks = $ticks $+ $r(1,10000)
if ($regex(%ticks,%a,/<div align="center" style="width:600px;"><p class="Quote">(.+?)<\/p>/)) {
if (($2 == Fact) && (%randqtsrch)) || (($2 == Quote) && (!%randqtsrch)) { $1 $noqt($hhfree($regml(%ticks,1))) | sockclose $sockname | halt }
var %randqtsrch on
}
sockread %a
}
}
alias -l hhfree {
var %x, %x = $regsubex($ticks,$1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null), %x = $regsubex($+($ticks,$r(1,1000)),%x,/&#(\d+);/g,$chr(\1)), %x = $replace(%x, ,$chr(32),",")
return %x
}
I was referring to jaytea's say about "the modification you suggested may even have been necessary on an older mIRC version." So if the latest version doesn't have the issue you've demonstrated anymore (I've yet to test this because I'm lazy at the moment), I don't see you have to follow that approach to resolve it. But then again, if latest version still has the issue remains unresolved, I'll agree with you in a heart beat.
I really believe people should upgrade to avoid many buggy issues that have been fixed in the latest version. Thus they won't have to come up with a workaround or go the extra mile to bypass the so-called bugs... I don't understand why some are saying they're waiting for a "stable" version to release before they can take action. Until then, good luck. :p
oh, for some reason i failed to make that connection. you're absolutely right, general purpose and utility functions such as $htmlfree() should always operate in a way that impacts the scripting environment as minimally as possible. there was, up until fairly recently, a bug with nested unnamed $regsubex() calls; i can't remember the exact nature of the bug, but the modification you suggested may even have been necessary on an older mIRC version.
Example of confilcting Regular Expressions with aliases:
alias regextest {
noop $regex(Here is my regex,/(.+)/)
echo -a $!regml(1): $regml(1)
var %a = $regedit($regml(1))
var %b = $regml(1)
echo -a % $+ a - %a
echo -a % $+ b - %b
}
alias regedit return $regsubex(abc,/D/,lol)
that kills the original $regml(1), and replaces it with nothing, as there is no $regml to be captured in that alias.
However; adding a regex name to the identifier solves this problem.
alias regextest2 {
noop $regex(Here is my regex,/(.+)/)
echo -a $!regml(1): $regml(1)
var %a = $regedit2($regml(1))
var %b = $regml(1)
echo -a % $+ a - %a
echo -a % $+ b - %b
}
alias regedit2 return $regsubex($ticks,abc,/D/,lol)
Jethro_, at your first comment, I did directly get the info; the whole purpose of the $htmlfree ($hhfree) was used to alter the html entities, not to remove html tags. Of course, I could have just done it in the actual script, but I felt that wasn't needed as I already had my alias $hhfree to change the htmlentities (N; ones, not &namehere; ones).
That doesn't mean the site is going to alter its source code. Some sites never changed a thing for ages. That aside, almost all socket scripts I've seen require a touch-up every once in a while to ensure its workability, regardless of a htmlfree alias is used. It's an unpredictable matter really, and that's the deal you have to keep when you make a socket.