Hi !
Need Help please:
on Irc channel command
!todo #testchannel complete 1
get this error on bot
Tcl error [pub_todo]: cant read "channel": no such varaible
what can i do ? SOME TCL NEWBIE !
# Todo list
#
# Description: Todo list to track work and accomplished work.
# keeps history and what not.
#
# Features: History Storing. Startup and Completion tracking.
#
# Usage: !todo (It'll display commands and options)
#
# Author: eRUPT(
erupt@ruptbot.com)
##################
# Version History
#
# - v0.1 -
# First Release
# - v0.1a -
# Fixed missing shortcut proc(putnot).
# - v0.2 -
# Added channel specific lists.
# Added move command to help support new channel specific lists.
# - v0.3 -
# Added channel allow lists.
#
############
#Channels allowed to use ToDo list.
#*TIP* If you have eggdrop1.5 or above use the channel set method *TIP*
#[Alternatively you can use "channel set #channel +todo" to turn on and "-todo" to turn off]
#[If you have the .tcl prompt on in dcc chat you can use .tcl channel set #channel +todo]
set todo_channels {
#testchannel
}
set todo_ver "v0.3"
if {![file exists scripts/todo.lst]} {
set wfile [open scripts/todo.lst w]
puts $wfile ""
close $wfile
}
if {![file exists scripts/todo_history.lst]} {
set wfile [open scripts/todo_history.lst w]
puts $wfile ""
close $wfile
}
if {[lindex $version 1]>=1050000} { setudef flag todo }
proc putnot {nick msg} { putserv "NOTICE $nick :$msg" }
proc load_todo {} {
global todo
set rfile [open scripts/todo.lst r]
set upgrade 0
while {![eof $rfile]} {
set line [gets $rfile]
if {$line==""} { continue }
set err ""
if {![string equal {g} [string index $line 0]] && ![string equal {#} [string index $line 0]]} {
set line [linsert $line 0 global]
set upgrade 1
}
set channel [lindex $line 0]
if {[info exists temp($channel)]} {
append temp($channel) " " [list [lindex $line 1] [lrange $line 2 end]]
} else {
set temp($channel) [list [lindex $line 1] [lrange $line 2 end]]
}
}
close $rfile
array set todo [array get temp]
if {$upgrade} { putlog "Upgraded Todo list files." ; save_todo }
}
proc load_history {} {
global todo_history
set rfile [open scripts/todo_history.lst r]
set upgrade 0
while {![eof $rfile]} {
set line [gets $rfile]
if {$line==""} { continue }
set err ""
if {![string equal {g} [string index $line 0]] && ![string equal {#} [string index $line 0]]} {
set line [linsert $line 0 global]
set upgrade 1
}
set channel [lindex $line 0]
if {[info exists temp($channel)]} {
append temp($channel) " " [list [lindex $line 1] [lrange $line 2 end]]
} else {
set temp($channel) [list [lindex $line 1] [lrange $line 2 end]]
}
}
close $rfile
array set todo_history [array get temp]
if {$upgrade} { putlog "Upgraded Todo_History list files." ; save_todo }
}
proc save_todo {} {
global todo
set wfile [open scripts/todo.lst w]
foreach channel [array names todo] {
catch {unset temp}
array set temp $todo($channel)
foreach entry [array names temp] {
puts $wfile "$channel $entry $temp($entry)"
}
}
close $wfile
}
proc save_history {} {
global todo_history
set wfile [open scripts/todo_history.lst w]
foreach entry [array names todo_history] {
catch {unset temp}
array set temp $todo_history($channel)
foreach entry [array names temp] {
puts $wfile "$channel $entry $temp($entry)"
}
}
close $wfile
}
bind pub m|o !todo pub_todo
proc pub_todo {nick uhost hand chan arg} {
global todo todo_history todo_channels version
if {[lindex $version 1]>1050000} {
if {![channel get $chan todo]} { if {[lsearch $todo_channels [string tolower $chan]] == -1} { return 0 } }
} else { if {[lsearch $todo_channels [string tolower $chan]] == -1} { return 0 } }
if {$arg==""} {
putnot $nick " Usage: !todo \[#channel\] <option> \[arguments\]"
putnot $nick "Options: add delete move list complete history"
return 0
}
set channel "global"
if {[string equal [string index $arg 0] #]} {
set channel [lindex $arg 0]
set arg [lrange $arg 1 end]
if {[lsearch [string tolower [channels]] $channel] == -1} {
putnot $nick "Invalid channel requested!"
return 0
}
}
set option [lindex $arg 0]
set args [lrange $arg 1 end]
switch $option {
add {
if {[string equal {} $args]} {
putnot $nick "Usage: !todo \[#channel\] add <message>"
return 0
}
if {[string equal {*} $hand]} { set who $nick } else { set who $hand }
if {[info exists todo($channel)]} { array set local_todo $todo($channel) }
set local_todo([clock seconds]) "$who $args"
set todo($channel) [array get local_todo]
save_todo
putnot $nick "Added new Todo item \002$args\002"
return 0
}
delete {
if {[string equal {} $args]} {
putnot $nick "Usage: !todo \[#channel\] delete <number> \[history\]"
putnot $nick "*TIP* Use !todo list to view numbers *TIP*"
putnot $nick "Valid Number Formats: #-#(Number Range) , #,#,#(Set of Numbers) , #(Single Number)"
return 0
}
if {[info exists todo($channel)]} {
array set local_todo $todo($channel)
}
if {[info exists todo_history($channel)]} {
array set local_todo_history $todo_history($channel)
}
if {[string equal -nocase {history} [lindex $args end]]} {
set arraylist [lsort -increasing [array names local_todo_history]]
} else { set arraylist [lsort -increasing [array names local_todo]] }
if {[string match *-* [lindex $args 0]]} {
set start [lindex [split [lindex $args 0] -] 0]
set end [lindex [split [lindex $args 0] -] 1]
if {$start>$end} {
putnot $nick "\002$start\002 can't be larger then \002$end\002 retard. Use a correct range."
return 0
}
if {[string equal {} [lindex $arraylist [expr $end - 1]]]} {
putnot $nick "Illegal range specified"
return 0
}
foreach stamp [lrange $arraylist [expr $start - 1] [expr $end - 1]] {
if {[string equal -nocase {history} [lindex $args end]]} {
unset local_todo_history($stamp)
} else { unset local_todo($stamp) }
}
if {[string equal -nocase {history} [lindex $args end]]} {
set todo_history($channel) [array get local_todo_history]
} else {
set todo($channel) [array get local_todo]
}
putnot $nick "Entries $start -> $end deleted"
save_todo ; save_history
return 1
}
if {[string match *,* [lindex $args 0]]} {
set unable ""
set usable ""
set list [split [lindex $args 0] ,]
foreach num $list {
if {[regexp {[^0-9]} $num]} { lappend unable $num } else { if {$num>[llength $arraylist]} { lappend unable $num } else { lappend usable $num } }
}
if {[string equal {} $usable]} {
putnot $nick "Nothing valid to delete."
putnot $nick "Invalid Entries: \002$unable\002"
return 0
}
putnot $nick "Deleting entries \002$usable\002"
foreach num $usable {
set key [lindex $arraylist [expr $num - 1]]
if {[string equal -nocase {history} [string tolower [lindex $args end]]]} {
unset local_todo_history($key)
} else {
unset local_todo($key)
}
}
if {[string equal -nocase {history} [lindex $args end]]} {
set todo_history($channel) [array get local_todo_history]
} else {
set todo($channel) [array get local_todo]
}
if {$unable!=""} {
putnot $nick "Invalid Entries: \002$unable\002"
}
save_todo ; save_history
return 1
}
set num [lindex $args 0]
if {$num>[llength $arraylist]} {
putnot $nick "Invalid Entry: \002$num\002"
}
set key [lindex $arraylist [expr $num - 1]]
if {[string equal -nocase {history} [lindex $args end]]} {
unset local_todo_history($key)
} else { unset local_todo($key) }
if {[string equal -nocase {history} [lindex $args end]]} {
set todo_history($channel) [array get local_todo_history]
} else {
set todo($channel) [array get local_todo]
}
putnot $nick "Deleted $num"
save_todo ; save_history
}
move {
if {[string equal {} $args]} {
putnot $nick "Usage: !todo move <entry number> <from_channel_list> <to_channel_list>"
putnot $nick "*NOTE* Use global as channel name to move from and to global area *NOTE*"
putnot $nick "Valid Number Formats: #-#(Number Range) , #,#,#(Set of Numbers) , #(Single Number)"
return 0
}
set from_channel [lindex $args 1]
set to_channel [lindex $args 2]
if {[string equal -nocase $from_channel $to_channel]} {
putnot $nick "Won't move to the same channel, waste of my brain power."
return 0
}
if {(![string equal {#} [string index $from_channel 0]] && ![string equal -nocase {global} $from_channel]) || (![string equal {#} [string index $to_channel 0]] && ![string equal -nocase {global} $to_channel])} {
putnot $nick "You need to specify channels, or otherwise the global area."
return 0
}
if {[string equal -nocase {global} $to_channel]} {
set to_channel "global"
} else {
if {[lsearch [string tolower [channels]] $to_channel] == -1} {
putnot $nick "Invalid channel requested!"
return 0
}
}
if {[string equal -nocase {global} $from_channel]} {
set from_channel "global"
} else {
if {[lsearch [string tolower [channels]] $from_channel] == -1} {
putnot $nick "Invalid channel requested!"
return 0
}
}
if {[info exists todo($to_channel)]} {
array set local_to_todo $todo($to_channel)
}
if {![info exists todo($from_channel)]} {
putnot $nick "No items in current todo list."
} else {
array set local_from_todo $todo($from_channel)
set from_arraylist [lsort -increasing [array names local_from_todo]]
}
if {[string match *-* [lindex $args 0]]} {
set start [lindex [split [lindex $args 0] -] 0]
set end [lindex [split [lindex $args 0] -] 1]
if {$start>$end} {
putnot $nick "\002$start\002 can't be larger then \002$end\002 retard. Use a correct range."
return 0
}
if {[string equal {} [lindex $from_arraylist [expr $end - 1]]]} {
putnot $nick "Illegal range specified"
return 0
}
foreach stamp [lrange $from_arraylist [expr $start - 1] [expr $end - 1]] {
set local_to_todo($stamp) $local_from_todo($stamp)
unset local_from_todo($stamp)
}
set todo($from_channel) [array get local_from_todo]
set todo($to_channel) [array get local_to_todo]
putnot $nick "Entries $start -> $end moved from $from_channel -> $to_channel"
save_todo ; save_history
return 1
}
if {[string match *,* [lindex $args 0]]} {
set unable ""
set usable ""
set list [split [lindex $args 0] ,]
foreach num $list {
if {[regexp {[^0-9]} $num]} { lappend unable $num } else { if {$num>[llength $from_arraylist]} { lappend unable $num } else { lappend usable $num } }
}
if {[string equal {} $usable]} {
putnot $nick "Nothing valid to move."
putnot $nick "Invalid Entries: \002$unable\002"
return 0
}
putnot $nick "Moving entries \002$usable\002"
foreach num [lsort -decreasing $usable] {
set key [lindex $from_arraylist [expr $num - 1]]
set local_to_todo($key) $local_from_todo($key)
unset local_from_todo($key)
}
set todo($from_channel) [array get local_from_todo]
set todo($to_channel) [array get local_to_todo]
if {$unable!=""} {
putnot $nick "Invalid Entries: \002$unable\002"
}
save_todo ; save_history
return 1
}
set num [lindex $args 0]
if {$num>[llength $from_arraylist]} {
putnot $nick "Invalid Entry: \002$num\002"
}
set key [lindex $from_arraylist [expr $num - 1]]
set local_to_todo($key) $local_from_todo($key)
unset local_from_todo($key)
set todo($from_channel) [array get local_from_todo]
set todo($to_channel) [array get local_to_todo]
putnot $nick "Moved $num from $from_channel -> $to_channel"
save_todo ; save_history
}
list {
if {![info exists todo($channel)]} {
putnot $nick "No items in current todo list."
return 0
}
array set local_todo $todo($channel)
set keys [array names local_todo]
if {[llength $keys]==0} {
putnot $nick "No items in current todo list."
return 0
}
set count 1
foreach key [lsort -increasing $keys] {
set curr [join $local_todo($key)]
putnot $nick "$count.) \002[lrange $curr 1 end]\002 by \002[lindex $curr 0]\002 at [clock format $key -format %m/%d/%Y-%l:%M]"
incr count
}
}
complete {
if {$args==""} {
putnot $nick "Usage: !todo \[#channel\] complete <number>"
putnot $nick "*TIP* Use !todo list to view numbers *TIP*"
putnot $nick "Valid Number Formats: #-#(Number Range) , #,#,#(Set of Numbers) , #(Single Number)"
return 0
}
if {![info exists todo($channel)]} {
putnot $nick "No items in current todo list."
}
array set local_todo $todo($channel)
if {[info exists todo_history($channel)]} { array set local_todo_history $todo_history($channel) }
set arraylist [lsort -increasing [array names local_todo]]
if {[string match *-* [lindex $args 0]]} {
set start [lindex [split [lindex $args 0] -] 0]
set end [lindex [split [lindex $args 0] -] 1]
if {$start>$end} {
putnot $nick "\002$start\002 can't be larger then \002$end\002 retard. Use a correct range."
return 0
}
if {[string equal {} [lindex $arraylist [expr $end - 1]]]} {
putnot $nick "Illegal range specified"
return 0
}
foreach stamp [lrange $arraylist [expr $start - 1] [expr $end - 1]] {
set local_todo_history($stamp) "[unixtime] $todo($stamp)"
unset local_todo($stamp)
}
set todo_history($channel) [array get local_todo_history]
set todo($channel) [array get local_todo]
putnot $nick "Entries $start -> $end completed"
save_todo ; save_history
return 1
}
if {[string match *,* [lindex $args 0]]} {
set unable ""
set usable ""
set list [split [lindex $args 0] ,]
foreach num $list {
if {[regexp {[^0-9]} $num]} { lappend unable $num } else { if {$num>[llength $arraylist]} { lappend unable $num } else { lappend usable $num } }
}
if {$usable==""} {
putnot $nick "Nothing valid to complete."
putnot $nick "Invalid Entries: \002$unable\002"
return 0
}
putnot $nick "Completing entries \002$usable\002"
foreach num $usable {
set key [lindex $arraylist [expr $num - 1]]
set local_todo_history($key) "[unixtime] $todo($key)"
unset local_todo($key)
}
if {$unable!=""} {
putnot $nick "Invalid Entries: \002$unable\002"
}
set todo_history($channel) [array get local_todo_history]
set todo($channel) [array get local_todo]
save_todo ; save_history
return 1
}
set num [lindex $args 0]
if {$num>[llength $arraylist]} {
putnot $nick "Invalid Entry: \002$num\002"
}
set key [lindex $arraylist [expr $num - 1]]
set local_todo_history($key) "[unixtime] $local_todo($key)"
unset local_todo($key)
putnot $nick "Completed $num"
set todo_history($channel) [array get local_todo_history]
set todo($channel) [array get local_todo]
save_todo
save_history
}
history {
if {[info exists todo_history($channel)]} {
array set local_todo_history $todo_history($channel)
} else {
putnot $nick "No items in current history list."
return 0
}
set keys [array names local_todo_history]
if {[llength $keys]=="0"} {
putnot $nick "No items in current history list."
return 0
}
set count 1
foreach key [lsort -increasing $keys] {
set curr $local_todo_history($key)
putnot $nick "$count.) \002[lrange $curr 2 end]\002 by \002[lindex $curr 1]\002 at [clock format $key -format %m/%d/%Y-%l:%M] Completed on: [clock format [lindex $curr 0] -format %m/%d/%Y-%l:%M]"
incr count
}
}
}
}
load_todo
load_history
putlog "Todo list tracking by eRUPT(
erupt@ruptbot.com) $todo_ver"