frishy commented on a Page, !define (slang)  -  Sep 16, 2011

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-,&amp;,&,&lt;,<,&gt;,>,&quot;,",<td>,$chr(32),<tr>,$chr(20)),/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x,&nbsp;)
  return %x
}
 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.