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.

probs with gbash script

Help for those learning Tcl or writing their own scripts.
Post Reply
L
Ladykiller
Voice
Posts: 7
Joined: Sun Feb 18, 2007 4:24 pm

probs with gbash script

Post by Ladykiller »

Have that Script but get this error and dont know why
Tcl error [::rss::admin]: can't read "token": no such variable

Code: Select all

#

# - Namespace - #

namespace eval ::rss {

# - Packages - #

# Http

package require http

# - Settings - #

# Antispam Time (In Sekunden)

variable antispam "60"

# Feed

variable feed http://german-bash.org/latest-quotes.xml

# IDURL

variable idurl http://german-bash.org/index.php?id=%id%&action=show

# Style (Variablen: :title: :link

variable style "\[\002gBash Quote\002\] \037No.\037 %id% @ \037%link%\037 (%info%)"

# Zum Replacen

variable rep {
< <
> >
}


# - Setudef - #

# Flag

# RSS

setudef flag rss


# - Binds - #

# Pub

# Admin

bind pub nm|nm ".gbash" ::rss::admin

# Time

# Check

bind time -|- "13 *" ::rss::check



# - Procs - #

# Admin

proc admin { nick host hand chan arg } {

switch -- [string toupper [lindex $arg 0]] {

ON { 

channel set $chan +rss

putserv "notice $nick :\[\002RSS\002\] ist jetzt \037aktiviert\037"

}

OFF {

channel set $chan -rss

putserv "notice $nick :\[\002RSS\002\] ist jetzt \037deaktiviert\037"

}

STATUS {

putserv "notice $nick :\[\002RSS\002\] ist immoment \037[string map {1 aktiviert 2 deaktiviert} [channel get $chan rss]]\037"

}

default {

if {[string length $arg] < 1} {

putserv "privmsg $chan :\002Commands are\002 $::lastbind ON/OFF/STATUS/ID"

return 0

}

if {[info exists ::rss::as($chan)] && ($::rss::as($chan) >= [unixtime])} {

return 0

}

puthelp "notice $nick :\002Getting Quote...\002 please wait"

set ::rss::as($chan) [expr [unixtime] + $::rss::antispam]

::rss::getid $chan [lindex [split $arg] 0]

return 1

}

}

}

# GetID

proc getid { chan id } {

variable idurl

set curr [string map -nocase "%id% $id" $idurl]

if {[catch { set token [http::geturl $curr -timeout 10000]} error] == 1} {
putlog "$error"
} elseif {[http::status $token] == "ok"} {
set output [http::data $token]
} elseif {[http::status $token] == "timeout"} {
putlog "Timeout occurred"
::rss::send $chan "" $curr $id "" "Timeout"
} elseif {[http::status $token] == "error"} {
putlog [http::error $token]
return 0
}

http::cleanup $token

if {![info exists output]} { return 0 }

if {[string match -nocase "*Ein Zitat mit dieser id existiert leider nicht.*" $output]} {

::rss::send $chan "Ein Zitat mit dieser id existiert leider nicht." $curr $id "" "Ein Zitat mit dieser id existiert leider nicht."

return 0

}

regexp -nocase -- {<span class="date">.+?)</span>} $output -> date

regexp -nocase -- {<span class="network">.+?)</span>} $output -> net

set info [string trim [regsub -all -nocase -- {<.+?>} "$date - $net" ""]]

regexp -nocase -- {<div class="zitat">.+?)</div>} $output -> description

regsub -all -nocase -- {<.+?>} $description "" description

set description [string trim [string map -nocase $::rss::rep $description]]

::rss::send $chan l $curr $id $info $description

return 1

} 







# Check

proc check { args } {

variable feed

set curr $feed

if {![info exists ::rss::last($curr)]} {

set ::rss::last($curr) ""

}

putlog "\[\002RSS\002\] Checking \037$curr\037"

if {[catch { set token [http::geturl $curr -timeout 10000]} error] == 1} {
putlog "$error"
} elseif {[http::status $token] == "ok"} {
set output [http::data $token]
} elseif {[http::status $token] == "timeout"} {
putlog "Timeout occurred"
} elseif {[http::status $token] == "error"} {
putlog [http::error $token]
return 0
}

http::cleanup $token

if {![info exists output]} { return 0 }

if {![regexp -nocase -- {<item>.*?<title>.+?)</title>} $output -> title]} {

putlog "\[\002RSS\002\] Error! Nothing found at $curr"

return 0

}

regexp -nocase -- {Zitat \#([0-9]*)\s} $title -> id

regsub -all -nocase -- {Zitat \#[0-9]*\s-\s} $title "" title

regsub -all -nocase -- "\n" $title "" title

if {[string equal -nocase $::rss::last($curr) $title]} {

return 0

}

set ::rss::last($curr) $title

regexp -nocase -- {<item>.*?<link>.+?)</link>.*?<description>.+?)</description>} $output -> link description

set description [string range $description 9 end-3]

regexp -nocase -- {<p>.+?)</p>} $description -> info

regsub -all -nocase -- {<p>.+?</p>} $description "" description

regsub -all -nocase -- {<br />} $description "\n" description

set description [string map -nocase $::rss::rep $description] 

if {![info exists link]} { set link $curr }

foreach chan [channels] {

if {[channel get $chan rss]} {

utimer 5 [list ::rss::send $chan $title $link $id $info $description]

}

}

return 1

}

# Send

proc send { chan title link id info text } {

variable style

set style [string map -nocase [list %url% $link] $style]
set style [string map -nocase [list %link% $link] $style]
set style [string map -nocase [list %title% $title] $style]
set style [string map -nocase [list %line% $title] $style]
set style [string map -nocase [list %info% $info] $style]
set style [string map -nocase [list %id% $id] $style]

puthelp "privmsg $chan :[join $style]"

foreach line [split $text \n] {

if {[string trim $line] == ""} { continue }

puthelp "privmsg $chan :$line"

}

}


putlog "\[\002RSS\002\] by \037#p0wl\037 Loaded!"

}
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

You have to provide complete error info (.set errorInfo).
Post Reply