This snippet defines stuff (duh) using define, definition, or def. I know there's other ones but I wanted to post mine :P. Thanks to Scakk for one of the $replace lines and Jethro_ for the regex statement. Gooshie fixed the regex up a little more too.
on $*:text:/^[!.@]def(ine|inition)? \w+$/Si:#:{
if (!$sock(definition)) {
set %definitionword $2
set %defchan $chan
msg # Looking up results for $+([,$chr(3),12,%definitionword,$chr(15),],:)
sockopen definition lookwayup.com 80
}
}
on *:sockopen:definition: {
sockwrite -n $sockname GET /lwu.exe/lwu/d?s=f&w= $+ %definitionword HTTP/1.1
sockwrite -n $sockname Host: lookwayup.com
sockwrite -n $sockname Connection: Close
sockwrite -n $sockname $crlf
}
on *:sockread:definition: {
sockread %define
if (not found. isin %define) { msg %defchan No results found for $+([,$chr(3),12,%definitionword,$chr(15),],.) | sockclose definition }
if (Spelling corrected isin %define) { msg %defchan No results found for $+([,$chr(3),12,%definitionword,$chr(15),],.) | sockclose definition }
if ($chr(90) isin %define) && ($chr(91) isin %define) { set %definition $nohtml(%define) | set %defyesono yes | set %defyes yes }
elseif (%defyesono == yes) { msg %defchan $gettok(%definition,1,46) $+ $chr(46) $+($chr(91),$chr(3),7,$gettok($gettok(%definition,1,93),2,91),$chr(15),$chr(93)) $remove($replace($nohtml(%define),$("),$chr(34),$('),$chr(39)),$chr(9)) | unset %defyesono }
}
on *:sockclose:definition: {
if (%defyes == yes) { msg %defchan End of results for $+([,$chr(3),12,%definitionword,$chr(15),],.) | unset %def* }
}
alias nohtml {
var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x, )
return %x
}
here is one way of making it
trigger @def <number of def's> Ex:" @def cat 2 " to message the channel
or " !def cat 2 " to notice the user
on $*:text:/^([@!])def\s(\w+)\s(\d+)$/iS:#: {
if ($sock(def)) sockclose def
if ($hget(def)) .hfree def
sockopen def lookwayup.com 80
sockmark def $iif($regml(1) == @,msg #,.notice $nick) $regml(2) $regml(3)
}
on *:sockopen:def: {
sockwrite -nt $sockname GET $+(/lwu.exe/lwu/d?s=f&w=,$gettok($sock(def).mark,3,32)) HTTP/1.1
sockwrite -nt $sockname Host: $+(lookwayup.com,$str($crlf,2))
}
on *:sockread:def: {
var %def | sockread %def
if ($regex(%def,/^(not found.)/)) { $gettok($sock(def).mark,1-3,32) $regml(1) | sockclose def }
if ($regex(%def,/<tr><td class="dict_text">.+">\d\.<\/b>(.+)/)) { $gettok($sock(def).mark,1-3,32) $regml(1) }
if ($regex(%def,/^\t<b>(.+)<\/b>$/)) { $gettok($sock(def).mark,1-2,32) $regsubex($regml(1),/&#(\d+);/g,$chr(\1)) | .hinc -m def num 1 }
if ($hget(def,num) == $gettok($sock(def).mark,4,32)) { sockclose def | if ($hget(def)) .hfree def }
}
Just one of many ways to make this.
also one way to replace them " i did
$regsubex($regml(1),/&#(\d+);/g,$chr(\1))
in my version
but if you wanted to use it as a alias you can do
alias -l rchr { var %rchr = $1- | return $regsubex(%rchr,/&#(\d+);/g,$chr(\1)) }
that way you dont need to do all them $replace(%define,,,$chr(44)) and so on you can just do $rchr(%define) or w/e you use to hold the info.
also look into using sockmark so you don't have to set global vars.
as well if you are going to use $regex why not use $regml as well?
also the script is a bit floody maybe make it notice instead of msg or have it list a number of results like maybe 3
cuz !def cat gave back 10 lines thats more then enough to get you banned from some channels.