Code: Select all
foreach bind [binds topic_holiday] {lassign $bind type flags mask num proc; unbind $type $flags $mask $proc}
foreach bind [binds pubholiday] {lassign $bind type flags mask num proc; unbind $type $flags $mask $proc}
bind time - "00 00 * * *" topic_holiday
bind pub - .date pubholiday
set date_file "date.txt"
if {![file exists $date_file]} {
fconfigure [set datefile [open $date_file w]] -encoding binary
close $datefile
}
proc topic_holiday {min hour day month year} {
global date_file
fconfigure [set datefile [open $date_file r]] -encoding binary
set today [clock format [clock seconds] -format "%d %m"]
set holidays [list]
while {![eof $datefile]} {
set CurEntry "[gets $datefile]"
set date [lrange $CurEntry 0 1]
if {[string match -nocase $today $date]} {
lappend holidays "[lrange $CurEntry 2 end]"
}
}
close $datefile
if {[string length $holidays] > 0} {
foreach channel [channels] {
if {[validchan $channel] && [botonchan $channel] && [botisop $channel]} {
putserv "TOPIC $channel :[join $holidays]"
}
}
}
putlog "Changing topic to [join $holidays]"
}
proc pubholiday {nick uhost hand chan text} {
set choice [lindex $text 0]
set dd [lindex $text 1]
set mm [lindex $text 2]
set desc [lrange $text 3 end]
if {[string equal -nocase "delete" $choice]} {
if {[GetDate $dd $mm] == "There are no events loaded for that date" || [GetDate $dd $mm] == "That date / month combination doesn't exist"} {
puthelp "PRIVMSG $chan :ERROR: [GetDate $dd $mm]"
return 1
}
DeleteDate $dd $mm
puthelp "PRIVMSG $chan :$nick deleted $dd $mm"
} elseif {[string equal -nocase "get" $choice]} {
puthelp "PRIVMSG $chan :[GetDate $dd $mm]"
return 1
} elseif {[string equal -nocase "set" $choice]} {
if {$desc==""} {
puthelp "PRIVMSG $chan :ERROR: Add a description for the event"
return 1
}
if {[GetDate $dd $mm] == "That date / month combination doesn't exist"} {
puthelp "PRIVMSG $chan :ERROR: [GetDate $dd $mm]"
return 1
} elseif {[GetDate $dd $mm] != "There are no events loaded for that date"} {
puthelp "PRIVMSG $chan :ERROR: An event already exists for that date"
return 1
}
SetDate $dd $mm "$desc"
puthelp "PRIVMSG $chan :Ahora: $dd $mm == [GetDate $dd $mm]"
return 1
} else {
puthelp "PRIVMSG $chan :\[DATE sintaxis\]"
puthelp "PRIVMSG $chan :Use: .date get <DD> <MM> - Shows the event on the calendar for the specified date"
puthelp "PRIVMSG $chan :Use: .date set <DD> <MM> <Description> - Changes the channel topic to <Description> on the specified date"
puthelp "PRIVMSG $chan :Use: .date delete <DD> <MM> - Deletes the event on the calendar for the specified date"
puthelp "PRIVMSG $chan :\[DATE sintaxis\]"
return 1
}
return 1
}
proc GetDate {dd mm} {
regsub -all {[0-9]} $mm {1} myresult
if {$myresult != 11 && $myresult != 1 } {
return "That date / month combination doesn't exist"
}
if {$myresult == 1 } {
set mm 0$mm
}
if {$mm > 12 || $mm == 0} {
return "That date / month combination doesn't exist"
}
regsub -all {[0-9]} $dd {1} myresult
if {$myresult != 11 && $myresult != 1 } {
return "That date / month combination doesn't exist"
}
if {$myresult == 1 } {
set dd 0$dd
}
if {[string index $mm 0] eq 0} {
set month [string index $mm 1]
} else {
set month $mm
}
set days "31 29 31 30 31 30 31 31 30 31 30 31"
if {[lindex $days ${month}-1] < $dd || $dd == 0} {
return "That date / month combination doesn't exist"
}
global date_file
fconfigure [set datefile [open $date_file r]] -encoding binary
set retval "There are no events loaded for that date"
set entry "$dd $mm"
while {![eof $datefile]} {
set CurEntry "[gets $datefile]"
set EntryName [string tolower [lrange $CurEntry 0 1]]
if {$EntryName==$entry} {
set retval "[lrange $CurEntry 2 end]"
}
}
close $datefile
return $retval
}
proc DeleteDate {dd mm} {
global date_file
regsub -all {[0-9]} $mm {1} myresult
if {$myresult == 1 } { set mm 0$mm }
regsub -all {[0-9]} $dd {1} myresult
if {$myresult == 1 } { set dd 0$dd }
fconfigure [set datefile [open $date_file r]] -encoding binary
set entry "$dd $mm"
while {![eof $datefile]} {
set CurLine "[gets $datefile]"
if {[lrange $CurLine 0 1]!=$entry} {lappend dateList $CurLine}
}
close $datefile
fconfigure [set datefile [open $date_file w]] -encoding binary
foreach CurLine $dateList {
if {$CurLine!=""} {puts $datefile $CurLine}
}
close $datefile
SortDate 1
}
proc SetDate {dd mm definition} {
global date_file
regsub -all {[0-9]} $mm {1} myresult
if {$myresult == 1 } { set mm 0$mm }
regsub -all {[0-9]} $dd {1} myresult
if {$myresult == 1 } { set dd 0$dd }
set entry "$dd $mm"
set entry [string trim [string tolower $entry] \=]
fconfigure [set datefile [open $date_file r]] -encoding binary
while {![eof $datefile]} {
set CurLine "[gets $datefile]"
if {[lrange $CurLine 0 1]!=$entry} {
lappend dateList $CurLine
}
}
close $datefile
fconfigure [set datefile [open $date_file w]] -encoding binary
foreach CurLine $dateList {
if {$CurLine!=""} {puts $datefile $CurLine}
}
puts $datefile "$dd $mm $definition"
close $datefile
SortDate 1
}
proc SortDate {type} {
global date_file
set t [clock clicks -milliseconds]
fconfigure [set datefile [open $date_file r]] -encoding binary
set txt ""
while {![eof $datefile]} {
set tmp "[gets $datefile]"
if {[info exists tmp]&&$tmp!=""} {
set a [lindex $tmp 1][lindex $tmp 0]
lappend txt [list $a $tmp]
}
}
close $datefile
set txt [lsort -index 0 $txt]
fconfigure [set datefile [open $date_file w]] -encoding binary
foreach tmp $txt {
puts $datefile [lindex $tmp 1]
}
close $datefile
putlog "Sorting done of data on the database ($date_file)->[expr double([clock clicks -milliseconds]-$t)/1000]s"
}
putlog "Holiday topic changer... Loaded"