Urban Dictionary

By Gecko321 on Jun 19, 2012

Based on FordLawnmowers verison.

Commands:
!ud - Gives random word definition
!ud - Gives the definition of the word

bind pub - !ud ud

proc ud {nick host hand chan arg} {
package require http  

  set arg [string map { " " "+" } $arg]
  puts $arg
  if {[string length $arg] != 0 } { set url "http://www.urbandictionary.com/define.php?term=$arg"
  } else {
    set url "http://www.urbandictionary.com/random.php"
    set page [http::data [http::geturl $url]]
    regexp {href="(.*?)"} $page => url
  }
  set page [http::data [http::geturl $url]]
  regexp {'word'>(.*?)<\/td>} $page => word
  regexp {definition">(.*?)(<br\/>|<\/div>)} $page => deff
  regexp {author">(.*?)<\/a>} $page => author
  regexp {example">(.*?)</div>} $page => example
  regexp {'not_defined_yet'>} $page => notfound
  set deff [string map {&quot; ""} $deff]
  set example [string map {&quot; "\""} $example]
  regsub -all {(<.*?>)} $example "" example
  if {[info exists deff]} {
    putserv "PRIVMSG $chan :Word: [string trim $word]"
    putserv "PRIVMSG $chan :Definition: [string trim $deff]"  
    if {[info exists example]} { putserv "PRIVMSG $chan :Example: [string trim $example]" }
    putserv "PRIVMSG $chan :By: ([string trim $author]) Link: $url"
  }
}

putlog "Urban Dictionary"

Comments

Sign in to comment.
prashant179   -  Jan 12, 2014

Fix this Error Buddy
Tcl error [ud]: can't read "deff": no such variable

play4free2  -  Feb 08, 2014

Try changing line 16

From:

 regexp {definition">(.*?)(<br\/>|<\/div>)} $page => deff

To:

 regexp {meaning">(.*?)(<br\/>|<\/div>)} $page => deff
Sign in to comment

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.