egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

urban dictionary problem

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases
View previous topic :: View next topic  
Author Message
Angel
Voice


Joined: 31 Jul 2010
Posts: 13

PostPosted: Mon Aug 23, 2010 8:25 pm    Post subject: urban dictionary problem Reply with quote

Code:
# 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 {&nbsp;} $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 {&gt;} $html {>} html
       regsub -all {&lt;} $html {<} html
       regsub -all {&amp;} $html {\&} html
       regsub -all {&times;} $html {*} html
       regsub -all {(?:\x91|\x92|’|‘|')} $html {'} html
       regsub -all {(?:\x93|\x94|“|”|&quot;)} $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."
       }
    }
  }
 }






i got this error msg

Code:
[21:24:43] invalid command name "}"
    while executing
"}"
    (file "scripts/urban.tcl" line 127)
    invoked from within
"source scripts/urban.tcl"



i think this tcl is not tested yet...

edit:already fixed now but there's another error again about the "else" clause "if"

please help
Back to top
View user's profile Send private message
Trixar_za
Op


Joined: 18 Nov 2009
Posts: 143
Location: South Africa

PostPosted: Tue Aug 24, 2010 8:43 pm    Post subject: Reply with quote

It's in current use, so you can say it's tested...

I noticed a few inconsitancies between it and the one you posted like the last closing bracket having a space before it where there should be none). Going on the error, I'm guessing it's expecting atleast one command before the program loads - probably the putlog which you removed. Try leaving it in and see if it works this time.

Anyway, this is the script I'm using with my bot:
Code:
# 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 {&nbsp;} $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 {&gt;} $html {>} html
       regsub -all {&lt;} $html {<} html
       regsub -all {&amp;} $html {\&} html
       regsub -all {&times;} $html {*} html
       regsub -all {(?:\x91|\x92|’|‘|')} $html {'} html
       regsub -all {(?:\x93|\x94|“|”|&quot;)} $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 also updated the one on my website with this one. Hopefully it works now, otherwise it might be a issue with the latest eggdrop (which will mean bug hunting for me Razz)
_________________
http://www.trixarian.net/Projects
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber