This is a script that searches what you enter in a slang dictionary site (so dont use if your easily offended) and returns the top few results (some of the results have just gotta crack ya up)
Just put this into your remotes section (Alt+R) of your bot.
Usage: type:
!define <word(s) to search>
Note: this cant be used in multiple channels at the same time, but however most of the time it will work as long as its not exactly the same time, it is also possible to mix up the definition with the results if done simultaneously (I think it won't mix them anymore though).
Updates:
Cleared up unneeded variable
Prevents multiple searches at one time to build up lag, defining is done after the previous one has finished.
Now returns top 5 results (if there is 5)
Minor improvement of html free
*Made sure that if there was no channel defined then the definition wasnt posted (often spammed in status)
If you want to change how many results it returns change:
if (%defresult5) {
to
if (%defresult<number of results>) {
alias dictionarysearch {
var %x = 1
while ($sock($+(dictionary,%x))) inc %x
sockopen $+(dictionary,%x) www.urbandictionary.com 80
sockmark $+(dictionary,%x) $1-
}
ON *:SOCKOPEN:dictionary*: {
if ($sockerr) {
var %cmd = $gettok($sock($sockname).mark,1,32)
%cmd Socket error $sockerr
return
}
sockwrite -n $sockname GET $+(/define.php?term=,$replace(%definition,$chr(32),+) HTTP/1.0)
sockwrite -n $sockname Host: www.urbandictionary.com
sockwrite $sockname $crlf
}
on *:SOCKREAD:dictionary*: {
var %g, %cmd
%cmd = $gettok($sock($sockname).mark,1,32)
if ($sockerr) {
%cmd Socket error $sockerr
return
}
while (1) {
sockread %g
if (!$sockbr) break
if (<p isin %g) {
var %dnext on
}
if (%dnext == on) {
if ($gettok($htmlfree(%g),1,32)) { inc %defnum }
if ($regex($gettok($htmlfree(%g),1,32),/^[1-6]/i)) {
set %defresult [ $+ [ %defnum ] ] %defresult [ $+ [ %defnum ] ] $replace($gettok($htmlfree(%g),1,32),$gettok($htmlfree(%g),1,32),%defnum $+ $chr(41)) $replace($htmlfree(%g),$gettok($htmlfree(%g),1,32),)
}
elseif (!$regex($gettok($htmlfree(%g),1,32),/^[1-6/i)) && ($gettok($htmlfree(%g),1,32)) {
set %defresult [ $+ [ %defnum ] ] %defresult [ $+ [ %defnum ] ] %defnum $+ $chr(41) $htmlfree(%g)
}
if (</p> isin %g) %dnext = off
}
if (%defresult5) {
sockclose $sockname
%cmd %defresult1
break
}
if (//--></script> isin %g) {
if (!%defresult1) { set %defresult1 No definition found! }
sockclose $sockname
%cmd %defresult1
break
}
}
}
alias dictionary3 {
if (%dictionary3) {
msg %dictionary3 $+(4Definition of %definition,:)
var %defnum2 1
while (%defresult [ $+ [ %defnum2 ] ]) {
msg %dictionary3 7 %defresult [ $+ [ %defnum2 ] ]
inc %defnum2
}
}
unset %dictionary3 | unset %defresult* | unset %definition | unset %defnum
}
on *:TEXT:!define*:#: {
if (%definition) { .notice $nick sorry please wait a sec, defining in progress }
elseif (!%defspam [ $+ [ $chan $+ [ $nick $+ [ $hash($1-,32) ] ] ] ]) {
inc -u20 %defspam [ $+ [ $chan $+ [ $nick $+ [ $hash($1-,32) ] ] ] ]
set %dictionary3 $chan
set %definition $2-
dictionarysearch dictionary3 $2-
}
else { .notice $nick sorry but you cant define that word again so quick! }
}
alias -l htmlfree {
var %x, %i = $regsub($replace($1-,&,&,<,<,>,>,",",<td>,$chr(32),<tr>,$chr(20)),/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x, )
return %x
}
well it has been 4 years since i did it, and i did quit using irc, i didnt know what went wrong with it and it confused me, I had a look since i got an email sayin this has been commented on and worked on it to bring definitions.
The code is below but has some issues but works.
(i cant log into my main account btw)
Updates:
17/9/11-fixed it to show if no definitions were found.
Known issues.
No spacing between examples from the same author
Sometimes sends commands to irc server (seems to be the first world from paragraphs from defining, unsure how to fix)
alias dictionarysearch {
var %x = 1
while ($sock($+(dictionary,%x))) inc %x
sockopen $+(dictionary,%x) www.urbandictionary.com 80
sockmark $+(dictionary,%x) $1-
}
ON *:SOCKOPEN:dictionary*: {
if ($sockerr) {
var %cmd = $gettok($sock($sockname).mark,1,32)
%cmd Socket error $sockerr
return
}
sockwrite -n $sockname GET $+(/define.php?term=,$replace(%definition,$chr(32),+) HTTP/1.0)
sockwrite -n $sockname Host: www.urbandictionary.com
sockwrite $sockname $crlf
}
on *:SOCKREAD:dictionary*: {
var %g, %cmd
%cmd = $gettok($sock($sockname).mark,1,32)
if ($sockerr) {
%cmd Socket error $sockerr
return
}
while (1) {
sockread %g
if (!$sockbr) break
if (<div class="definition"> isin %g) {
inc %defnum
set %defresult [ $+ [ %defnum ] ] %defresult [ $+ [ %defnum ] ] %defnum $+ $chr(41) $htmlfree($replace(%g,<div class="example">,- $chr(32)))
}
if (%defresult3) {
sockclose $sockname
%cmd %defresult1
break
}
if (</body> == %g) {
if (!%defresult1) { set %defresult1 No definition found! }
sockclose $sockname
%cmd %defresult1
break
}
}
}
alias dictionary3 {
if (%dictionary3) {
msg %dictionary3 $+(4Definition of %definition,:)
var %defnum2 1
while (%defresult [ $+ [ %defnum2 ] ]) {
msg %dictionary3 7 %defresult [ $+ [ %defnum2 ] ]
inc %defnum2
}
}
unset %dictionary3 | unset %defresult* | unset %definition | unset %defnum
}
on *:TEXT:!define*:#: {
if (%definition) { .notice $nick sorry please wait a sec, defining in progress }
elseif (!%defspam [ $+ [ $chan $+ [ $nick $+ [ $hash($1-,32) ] ] ] ]) {
inc -u20 %defspam [ $+ [ $chan $+ [ $nick $+ [ $hash($1-,32) ] ] ] ]
set %dictionary3 $chan
set %definition $2-
dictionarysearch dictionary3 $2-
}
else { .notice $nick sorry but you cant define that word again so quick! }
}
alias -l htmlfree {
var %x, %i = $regsub($replace($1-,&,&,<,<,>,>,",",<td>,$chr(32),<tr>,$chr(20)),/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x, )
return %x
}