############################################################# # # TODO.TCL v1.2 by stumper @ irc.MindForge.org # set todo_version "1.2" # ############################################################# ############################################################# # # Description : # This script allows to build a ToDo list # # Usage : # !todo # !addtodo # !remtodo # # Changelog : # v1.0 - stumper # Script creation # v1.1 - ToM # Added this header and comments # Added a channel selection configuration # Added a db file path configuration # # To Do : # # # ############################################################# ############################################################# # # Configuration # # List of channels where this script is active # Separate channels by spaces set todochans {#albator #naimphea} # The file where todos are saved in set todofile "scripts/data/todo.txt" # # End of configuration # DO NOT EDIT BELOW UNTIL YOU KNOW WHAT YOU ARE DOING # ############################################################# # Create a bind for each active channel foreach todochan $todochans { bind pubm - "$todochan !addtodo*" laddtodo bind pubm - "$todochan !remtodo*" lremtodo bind pubm - "$todochan !todo*" listtodo } ############################################## ####TRIGGER TO ADD A TODO IN THE TODO LIST#### ############################################## proc laddtodo { nick uhost handle chan arg } { global todofile if { [isop $nick $chan] } { if { [file exists $todofile] } { set readtodo [open $todofile r] while { ![eof $readtodo] } { gets $readtodo todlist if { $todlist!="" } { lappend linestodo [lrange $todlist 1 end] } } lappend linestodo "[date] $nick: [lrange $arg 1 end]" for { set write 0 } { $write<[llength $linestodo] } { incr write } { if { $write==0 } { set first [open $todofile w] puts $first "[expr $write+1] [lindex $linestodo $write]" close $first } else { set next [open $todofile a] puts $next "[expr $write+1] [lindex $linestodo $write]" close $next } } putserv "PRIVMSG $chan : Todo added" } else { set writefirst [open $todofile w] puts $writefirst "1 [date] $nick: [lrange $arg 1 end]" close $writefirst } } } ################################################# ####TRIGGER TO REMOVE A TODO IN THE TODO LIST#### ################################################# proc lremtodo { nick uhost handle chan arg } { global todofile if { [isop $nick $chan] } { if { [file exists $todofile] } { set readtodo [open $todofile r] while { ![eof $readtodo] } { gets $readtodo todlist if { $todlist!="" } { lappend linestodo [lrange $todlist 1 end] } } if { [isnumber [lindex $arg 1]] } { if { ([lindex $arg 1]>0 && [lindex $arg 1]<=[llength $linestodo]) } { set linestorem [expr [lindex $arg 1]-1] set linestodo [lreplace $linestodo $linestorem $linestorem] for { set write 0 } { $write<[llength $linestodo] } { incr write } { if { $write==0 } { set first [open $todofile w] puts $first "[expr $write+1] [lindex $linestodo $write]" close $first } else { set next [open $todofile a] puts $next "[expr $write+1] [lindex $linestodo $write]" close $next } } putserv "PRIVMSG $chan : Todo removed" } else { putserv "PRIMSG $chan : There is not such todo number" } } elseif {[lindex $arg 1]=="all" } { file del $todofile putserv "PRIVMSG $chan : Todo file removed successfully" } else { putserv "PRIVMSG $chan : This is not a valid request. I Cannot remove any line" } } else { putserv "PRIVMSG $chan : There is not any todo list to remove anything from" } } else { putserv "NOTICE $nick : Try to reop yourself as i don't recognize you as an op of this channel" } } ################################################ ####TRIGGER TO SEE THE LIST OF THE TODO LIST#### ################################################ proc listtodo { nick uhost handle chan arg } { global todofile if { [isop $nick $chan] } { if { [file exists $todofile] } { set readtodo [open $todofile r] while { ![eof $readtodo] } { gets $readtodo todlist if { $todlist!="" } { lappend linestodo [lrange $todlist 1 end] } } putserv "PRIVMSG $chan : --The todo list on date [date] is:--" for { set b 0 } { $b<[llength $linestodo] } { incr b } { putserv "PRIVMSG $chan : [expr $b+1]-[lindex $linestodo $b]" } putserv "PRIVMSG $chan : --End of the todo list--" } else { putserv "PRIVMSG $chan : Not any todo list" } } } putlog "todo.tcl by stumper v$todo_version successfully loaded"