Frage zu TCL script für nen Windrop
kiu 28.12.2005 - 18:30 996 8
dethspank
the wall
|
Also ich hab nen windrop (eggdrop) laufen und will dort ein google script laufen lassn das mir aber dauernd folgenden fehler ausgibt tcl error [pub_google] can't find "nick": no such variablehier der source code: ## default number of returns
set google_def_num 4
## max number of returns
set google_max 10
## public bind
set glpubbind .google
set gl_output "NOTICE $nick"
##########binds######################
bind pub -|- $glpubbind pub_google
##########Procs######################
proc pub_google { nick uhost handle chan search } {
global gl_ouput
set gl_output "NOTICE $nick"
if {[llength $search] == 0} {
puthelp "$gl_output : Whatcha searchin for fool!?"
return 0
}
set url [google_url $search $nick $chan]
google_getpage $url
return 0
}
## Google_url #############################################
## Takes input and parses to set the url, returns the url
proc google_url {search nick chan} {
global google_def_num google_max gl_output
set google_num [lindex $search end]
if {[regexp { [0-9]+} $search match $google_num]} {
if {$google_num > $google_max} { set google_num $google_max }
set search [lrange $search 0 [expr {[llength $search] - 2}]]
} else {
set google_num $google_def_num
}
if {$google_num >= 5} {
set gl_output "NOTICE $nick"
} else {
set gl_output "PRIVMSG $chan"
}
regsub -all { } $search {+} search
set url "/search?hl=en&num=$google_num&lr=&ie=ISO-8859-1&q=$search"
return $url
}
## google_getpage ##########################################
## gets the webpage and parses for the returns
proc google_getpage {url} {
global gl_output
## Open socket
if {[catch {set glsock [socket -async [url]http://www.google.com[/url] 80]} sockerr]} {
puthelp "NOTICE $nick :$sockerr"
puthelp "NOTICE $nick :Try again later, look out the window till then!"
close $glsock
return 0
}
puts $glsock "GET $url"
flush $glsock
set i 0
set j 1
set glout [gets $glsock]
while {[regexp {Dissatisfied with your results?} $glout] == 0} {
set glout [gets $glsock]
incr i
if {$i >= 150} {
break
}
if {[regexp {#008000>(.*?) - } $glout match gl_result($j)]} {
puthelp "$gl_output :$j. [url]http://[/url]$gl_result($j)"
incr j
}
}
close $glsock
return 0
}
Bearbeitet von watchout am 29.12.2005, 20:28
|
CitizenX
Here to stay
|
proc pub_google zeile - gehört da nicht auch $ hin
|
dethspank
the wall
|
nein
|
dethspank
the wall
|
niemand der mir helfen kann??
|
watchout
Legendundead
|
hm, ich hab keine Erfahrung mit TCL, aber in proc google_getpage {url} {
kommt kein "nick" vor, daher liegt wohl nahe dass du darin auch kein "nick" verwenden kannst oder?
|
dethspank
the wall
|
ich glaub das is ne andere abfrage eben und hat mit der ausgabe an sich wenig zutun sondern is eine teil prozedur
|
watchout
Legendundead
|
keine Ahnung was du schreibst - wieso "glaubst" du?
Wie auch immer - was ich so von der Sprache seh' muss man globale variablen (was scheinbar "nick" ist) mit dem keyword "global" in einer Procedure lokalisieren, nick wurde aber weder übergeben noch lokalisiert.
|
dethspank
the wall
|
und was wär dein vorschlag?
|
watchout
Legendundead
|
na genau das Gegenteil zu dem was geschrieben hab - entweder du übergibst nick oder du lokalisierst nick
|