i was searching for a replace command but i could only find lreplace somehow, ahwell i tried to work around then with lreplace wich agve me this script:
proc iwa:topic {nick uhost handle chan arg} {
global iwas db mq
set flink ""
set iwas(topic) [lrange $arg 0 100]
set sitelink "\0030,3| http://www.iwaddicts.net/ |\003"
set newlist [list $iwas(topic)]
# check if we have db conection
if {[iwa:constructor $nick $uhost $handle $chan]} {
set qry "SELECT *
FROM phpbb3_posts AS p
LEFT JOIN phpbb3_users AS u ON p.poster_id=u.user_id
ORDER BY post_time DESC
LIMIT 1"
set row [lindex [mysqlsel $db(sqlhand) $qry -list] 0]
set toad [lindex $row 6]
set tijd [ctime $toad]
set user [lindex $row 33]
set flink "| Latest discussion http://board.iwaddicts.net/[lindex $row 2],[lindex $row 1]#p[lindex $row 0] |"
}
#if requested the latest topic
if([string first "--lt" [string tolower $arg]] != -1){
set npl [lsearch $newlist "--lt"]
set newlist [[lreplace $newlist $npl $npls $flink]]
}
#if requested the site url
if([string first "--url" [string tolower $arg]] != -1)
set npl [lsearch $newlist "--url"]
set newlist [[lreplace $newlist $npl $npls $sitelink]]
}
#make the topic and set it in the channel
set newtopic [join $newlist]
putserv "TOPIC $chan :$newtopic"
putlog "#$handle# changed the topic in $chan to $newtopic"
}
error:
12:04] can't read "newlist": no such variable
while executing
"join $newlist"
invoked from within
"set newtopic [join $newlist]"
(file "scripts/iwa.tcl" line 178)
invoked from within
"source scripts/iwa.tcl"
proc iwa:topic {nick uhost handle chan arg} {
global iwas db mq
set flink ""
set iwas(topic) [lrange $arg 0 100]
set sitelink "\0030,3 http://www.iwaddicts.net/\003"
set newlist [lrange $arg 0 100]
# check if we have db conection
if {[iwa:constructor $nick $uhost $handle $chan]} {
set qry "SELECT *
FROM phpbb3_posts AS p
LEFT JOIN phpbb3_users AS u ON p.poster_id=u.user_id
ORDER BY post_time DESC
LIMIT 1"
set row [lindex [mysqlsel $db(sqlhand) $qry -list] 0]
set toad [lindex $row 6]
set tijd [ctime $toad]
set user [lindex $row 33]
set flink "Latest discussion http://board.iwaddicts.net/[lindex $row 2],[lindex $row 1]#p[lindex $row 0]"
}
##if requested the latest topic
#if([string first "--lt" [string tolower $arg]] != -1){
# set npl [lsearch $newlist "--lt"]
# set newlist [lreplace $newlist $npl $npls $flink]
#}
##if requested the site url
#if([string first "--url" [string tolower $arg]] != -1)
# set npl [lsearch $newlist "--url"]
# set newlist [lreplace $newlist $npl $npls $sitelink]
#}
#make the topic and set it in the channel
#set newtopic [join $newlist]
putserv "TOPIC $chan :$newlist"
putlog "#$handle# changed the topic in $chan to $newtopic"
}
Error:
[12:18] can't read "chan": no such variable
while executing
"putserv "TOPIC $chan :$newlist""
(file "scripts/iwa.tcl" line 179)
invoked from within
"source scripts/iwa.tcl"
This would create a list with one single list-item, I'm quite sure this is not what you intended. If you wish to convert a string into a list, use the split command with suitable splitcharacters (works in a similar fashion to explode() in php).
if ([string first "--lt" [string tolower $arg]] != -1) {
This would be php-syntax, not tcl-syntax. Very simplified, if expects the "test" to be a string containing one or more tcl-expressions. This string will then be passed to the tcl-interpreter and the result-code is then tested. As a rule of thumb, you (almost) always want to enclose the string with {} (to prevent early evaluation).
set newlist [[lreplace $newlist $npl $npls $flink]]
This is very dangerous code, as it will try to execute the result from the lreplace-operation as a separate command, and set newlist to the result of this. In the tcl-preprocessor, [string] means execute string in the current interpreter, and replace [string] with whatever it returns, before the whole commandline is then passed to the current interpreter.
[12:18] can't read "chan": no such variable
while executing
"putserv "TOPIC $chan :$newlist""
(file "scripts/iwa.tcl" line 179)
invoked from within
"source scripts/iwa.tcl"
This error would suggest that the line putserv "TOPIC $chan :$newlist" was executed as the script was loaded, and not as part of the proc. That is, it would seem there are some unbalanced {} within your script, one of those being this part:
#if requested the site url
if([string first "--url" [string tolower $arg]] != -1)
set npl [lsearch $newlist "--url"]
set newlist [[lreplace $newlist $npl $npls $sitelink]]
}
Here, there is no leading { to start the conditional code block, yet there is one } to terminate it -- which in this case terminates the whole proc instead.
I think this covers most of the issues in the posted code...