This work below is yet another forum request that I've decided to submit as a part of my snippet collection. For those who find this snippet useful, It's for the bot client, and the trigger is either !facts, @facts, .facts or !jokes, @jokes, .jokes.
on $*:text:/^[!@.](fact|joke)s$/iS:#:{
if (!%f) {
inc -u3 %f
var %s = $+(rjf,$str($ticks,2),$site)
if ($sock(%s)) sockclose $v1
sockopen %s www.randomfunfacts.com 80
sockmark %s .msg # $regml(1)
}
}
on *:sockclose:rjf*:{
tokenize 32 $sock($sockname).mark
var %s = $+(rjf,$str($ticks,2),$site)
if ($sock(%s)) sockclose $v1
sockopen %s www.jokesclean.com 80
sockmark %s $1-2
}
on *:sockopen:rjf*:{
tokenize 32 $sock($sockname).mark
if ($sockerr) {
$1-2 Error: Connection Issue...
sockclose $sockname
}
else {
if ($3 == fact) {
var %rjf = sockwrite -nt $sockname
%rjf GET / HTTP/1.1
%rjf Connection: close
%rjf Host: $+($sock($sockname).addr,$str($crlf,2))
}
else {
var %rjf = sockwrite -nt $sockname
%rjf GET /OneLiner/Random/ HTTP/1.0
%rjf Host: $+($sock($sockname).addr,$str($crlf,2))
}
}
}
on *:sockread:rjf*:{
tokenize 32 $sock($sockname).mark
if ($sockerr) {
$1-2 Error: Issues in Reading...
sockclose $sockname
halt
}
goto $iif($3 == fact,fact,joke)
:fact
sockread &rjf
var %info = $regsubex($bvar(&rjf,1-).text,/<[^>]*>|\t$&
$+ RLOpenInNewWindow|"1";|var RLRepeatKeywords/g,$chr(32))
if ($gettok($replace(%info, ,$chr(94)),2,94)) {
$1-2 $remove($gettok($v1,11-,32),24c6)
sockclose $sockname | halt
:joke
var %jokes
sockread %jokes
if ($regex(%jokes,/(.*)<\/font><\/p>/)) {
$sock($sockname).mark $replace($gettok($regml(1),3-,62), ,$chr(32))
sockclose $sockname
}
halt
}
}
The !jokes part still works well. However, the !facts command will only return the first 27 characters of the random fact. Any idea on how to have it display the entire random fact? Thanks!
Example:
A giraffe has a 20-inch ton
The U.S. ranks 29th in over
"Tom Sawyer" was the first
The world's largest amphibi
You didn't phrase the question very well.
$regml(1) on line 7 would contain either "joke" or "fact". The script needs to know that later. That's not where you should be making changes.
They tokenized $sock($sockname).mark on line 18, so $1-2 contains '.msg #'. I haven't fully examined the script, but I believe you should be focusing on lines 50 & 56.
How would you phrase the qestion instead of "How can I change the output to channel?"?
And you obviously saw I was tampering with the wrong line in the script. I don't see anything wrong with the question itself though.
I am not very good at scripting so of course I made that mistake.
Ah okay. Thanks. Not even sure where I can add the extra text that I want there either. I'll just try randomly and see what works.
Edit: Added the extra text I wanted with some random testing. Thanks for pointing out which lines.
it is already set to msg the channel