This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

urban.tcl

Support & discussion of released scripts, and announcements of new releases.
Post Reply
User avatar
starryeyedhaze
Voice
Posts: 4
Joined: Fri Oct 29, 2010 2:43 pm

urban.tcl

Post by starryeyedhaze »

I'm stumped. Today the urban dictionary script stopped working. It doesn't look like UD changed their formatting or anything and the regexes in the tcl look fine.


[UD]: Getting defintion for vagina...
[UD]: Word not found or doesn't exist.

I get this error every time no matter what word I choose. I have tested that I can get to UD from my bot's host... just confused. Can anybody help?
User avatar
starryeyedhaze
Voice
Posts: 4
Joined: Fri Oct 29, 2010 2:43 pm

nevermind.

Post by starryeyedhaze »

It looks like urban dictionary changed their single quotes to double quotes. All fixed :)
User avatar
Trixar_za
Op
Posts: 143
Joined: Wed Nov 18, 2009 1:44 pm
Location: South Africa
Contact:

Post by Trixar_za »

Thank you for the fix - It's updated on the website now too :)
User avatar
Anahel
Halfop
Posts: 48
Joined: Fri Jul 03, 2009 6:18 pm
Location: Dom!

Post by Anahel »

could you post fixed code?
User avatar
Trixar_za
Op
Posts: 143
Joined: Wed Nov 18, 2009 1:44 pm
Location: South Africa
Contact:

Post by Trixar_za »

Code: Select all

# Urban Dictionary Script by Trixar_za
# Based on the Twitter script by Warlord v1.0
# Type in partyline: ".chanset #channel +urban" to enable it.

# Sets the logo
set urban(logo) "\002\[UD\]:\002"

# Sets the user agent
set urban(agent) "Mozilla/4.75 (X11; U; Linux 2.2.17; i586; Nav)"

setudef flag urban

if {[catch {package require http 2.5} e] != 0} {
  set urban(noutf8) 1
  package require http
}

bind pub - !urban proc:urban
bind pub - .urban proc:urban
bind pub - !ud proc:urban
bind pub - .ud proc:urban

# wordwrap code by speechless
proc msg {type dest data} {
   set len [expr {500-[string len ":$::botname $type $dest :\r\n"]}]
   foreach line [wordwrap $data $len] {
      putserv "$type $dest :$line"
   }
}

proc wordwrap {data len} {
   set out {}
   foreach line [split [string trim $data] \n] {
      set curr {}
      set i 0
      foreach word [split [string trim $line]] {
         if {[incr i [string len $word]]>$len} {
            lappend out [join $curr]
            set curr [list $word]
            set i [string len $word]
         } {
            lappend curr $word
         }
         incr i
      }
      if {[llength $curr]} {
         lappend out [join $curr]
      }
   }
   set out
} 

proc proc:urban {nick uhand handle chan input} {
  if {[channel get $chan urban]} {
     global urban

    if {![llength [split $input]]} {
       msg "PRIVMSG" $chan "$urban(logo) Please be more specific. Ex: !urban word"
    } else {
       putquick "PRIVMSG $chan :$urban(logo) Getting defintion for $input..."
  
       if {[info exists urban(noutf8)]} {
          set http [::http::config -useragent $urban(agent)]
       } else {
          set http [::http::config -useragent $urban(agent) -urlencoding "utf-8"]
       }

       foreach word [split $input] {
          lappend query [lindex [split [http::formatQuery a $word] =] 1]
       }

       catch { set http [::http::geturl "http://www.urbandictionary.com/define.php?term=[join $query %20]" -timeout 10000]} error
 
       if {![string match -nocase "::http::*" $error]} {
          msg "PRIVMSG" $chan "$urban(logo) [string totitle [string map {"\n" " | "} $error]] \( $query \)"
          return 0
       }

       if {![string equal -nocase [::http::status $http] "ok"]} {
          msg "PRIVMSG" $chan "$urban(logo) [string totitle [::http::status $http]] \( $query \)"
          return 0
       }

       set html [::http::data $http]

       # Clean up :P
       regsub -all {\n} $html { } html
       regsub -all {\t} $html { } html
       regsub -all {<br/>} $html { } html
       regsub -all { } $html { } html
       regsub -all {    } $html { } html
       regsub -all {   } $html { } html
       regsub -all {  } $html { } html
       regsub -all {<a.+?>} $html {} html
       regsub -all {</a>} $html {} html
       regsub -all {<strong.+?>} $html {} html
       regsub -all {</strong>} $html {} html
       regsub -all {—} $html {-} html
       regsub -all {>} $html {>} html
       regsub -all {<} $html {<} html
       regsub -all {&} $html {\&} html
       regsub -all {×} $html {*} html
       regsub -all {(?:\x91|\x92|’|‘|')} $html {'} html
       regsub -all {(?:\x93|\x94|“|”|")} $html {"} html
       regsub -all {×} $html {x} html
       regsub -all {(?:<!\[CDATA\[)} $html {} html

       if {[regexp -- {<div class="definition">(.+?)</div>} $html - uddef]} {
          set uddef [string trim $uddef]
       }

       if {[regexp -- {<div class="example"></div>} $html - -]} {
          set uddex "None"
       } elseif {[regexp -- {<div class="example">(.+?)</div>} $html - uddex] && $uddex != "None"} {
          set uddex [string trim $uddex]
       }

       if {[info exists uddef]} {
          msg "PRIVMSG" $chan "$urban(logo) \002Definition:\002 $uddef"
          if {$uddex != "None"} {
             msg "PRIVMSG" $chan "$urban(logo) \002Example:\002 $uddex"
          }
       } else {
          msg "PRIVMSG" $chan "$urban(logo) Word not found or doesn't exist."
       }
    }
  }
}

putlog "Urban Dictionary Script by Trixar_za Loaded"
I'm still trying to fix my website. The IP got changed without notice and I only realised it now...
a
anotheruser
Voice
Posts: 8
Joined: Wed Sep 14, 2005 6:26 pm

Post by anotheruser »

Code: Select all

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 {" ""} $deff]
  set example [string map {" "\""} $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"
For those still looking here is a working update
Source: http://www.hawkee.com/snippet/9545/

This is not my work but thanks to the original poster/writer
Post Reply