All pastes #90478 Raw Edit

Princesse

public text v1 · immutable
#90478 ·published 2006-07-17 18:37 UTC
rendered paste body
#############################################################
#
# 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 des chan ou la tcl sera actif
# mettre les chans separé d'un espace entre deux
set todochans { #koute_channel }

# fichier ou vont s'enregister la memoire du todo
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 oh|oh "$todochan !addtodo*" laddtodo
	bind pubm n|n "$todochan !remtodo*" lremtodo 
	bind pubm oh|oh "$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 ajouté    (  tu  as  une  trop  petite  tête  pour  t'en  souvenir)"
		} 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 supprimé  avec  succés"
				} else {
					putserv "PRIMSG $chan : Desolé  nombre  inconnu"
				}
			} elseif {[lindex $arg 1]=="all" } {
				file del $todofile
				putserv "PRIVMSG $chan : Todo supprimé  avec  succés"
			} else {
				putserv "PRIVMSG $chan : .Requette  non valide I je  ne  peux pas  supprimer   cette  ligne"
			}
		} else {
			putserv "PRIVMSG $chan : lol  t'est   con  ou  quoi ??  y a pas  de  todos !"
		}
	} else {
		putserv "NOTICE $nick : Reop toi  je ne  te reconnnais  pas  comme  opé ( @ )  sur  ce chan"
	}
}



################################################
####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 : ¤¤ voici  la liste des   todos à la date  on date [date] :¤¤"
			for { set b 0 } { $b<[llength $linestodo] } { incr b } {
				putserv "PRIVMSG $chan : [expr $b+1]-[lindex $linestodo $b]"
			}
			putserv "PRIVMSG $chan : ¤¤ fin  de la liste  des  todos ¤¤"
		} else {
			putserv "PRIVMSG $chan : Liste  vide"
		}
	}
}


putlog "todo.tcl by stumper v$todo_version successfully ||  revue  est  traduite par  cestlemien  loaded"