I found a solution, it is not very "orthodox", but is all I could to do with my limited knowledge of Tcl.
I share it to other users who may have the same doubts and I close this topic if no better ideas.
Code: Select all
bind cron - {* * * * *} cron:semanal
proc cron:semanal {min hour day month weekday} {
global canal_admin
if {![file exists radiochans1.txt]} {
return
} else {
set fname "radiochans1.txt"
set fp [open $fname "r"]
set data [read -nonewline $fp]
close $fp
set lines [split $data "\n"]
set onch1 0
foreach chan [channels] {
if {([lsearch -glob -ascii -nocase $lines $chan] != -1) && ([onchan $::botnick $chan])} { set onch1 [expr {$onch1 + 1}] }
}
if {$onch1 == 0} return
if {$min == "00" && $hour == "04" && $weekday == "00"} {unbinds;bind cron - {*/20 * * * *} advertise }
if {$min == "00" && $hour == "18" && $weekday == "00"} {unbinds;bind cron - {*/10 * * * *} advertise }
if {$min == "00" && $hour == "00" && $weekday == "01"} {unbinds;bind cron - {*/20 * * * *} advertise }
if {$min == "00" && $hour == "18" && $weekday == "01"} {unbinds;bind cron - {*/10 * * * *} advertise }
if {$min == "00" && $hour == "00" && $weekday == "02"} {unbinds;bind cron - {*/20 * * * *} advertise }
if {$min == "00" && $hour == "18" && $weekday == "02"} {unbinds;bind cron - {*/10 * * * *} advertise }
if {$min == "00" && $hour == "00" && $weekday == "03"} {unbinds;bind cron - {*/20 * * * *} advertise }
if {$min == "00" && $hour == "18" && $weekday == "03"} {unbinds;bind cron - {*/10 * * * *} advertise }
if {$min == "00" && $hour == "00" && $weekday == "04"} {unbinds;bind cron - {*/20 * * * *} advertise }
if {$min == "00" && $hour == "18" && $weekday == "04"} {unbinds;bind cron - {*/10 * * * *} advertise }
if {$min == "00" && $hour == "04" && $weekday == "05"} {unbinds;bind cron - {*/20 * * * *} advertise }
if {$min == "00" && $hour == "18" && $weekday == "05"} {unbinds;bind cron - {*/10 * * * *} advertise }
if {$min == "00" && $hour == "04" && $weekday == "06"} {unbinds;bind cron - {*/20 * * * *} advertise }
if {$min == "00" && $hour == "18" && $weekday == "06"} {unbinds;bind cron - {*/10 * * * *} advertise }
}
}
proc unbinds { } {
foreach ele [binds cron] {
foreach {type flags name hits proc} $ele {
if {[string match "advertise" $proc]} {
unbind $type $flags $name $proc
break
}
}
}
}
I used
unbind command because to put range time, not getting the desired results, by joining the previous timer to the next.
I tried:
Code: Select all
bind cron -|- {*/10 00-04 * * *} advertise
At 04:00 the process stopped , but continued to run advertising for 10 minutes (queue) and joined to the next.
The process is activated this way:
Sundays 04:00-18:00 every 20 min
Sundays 18:00-23:59 every 10 min
From Monday to Thursday from 00:00-18:00 every 20 min
From Monday to Thursday from 18:00-23:59 every 10 min
Friday 00:00-04:00 every 20 min
Friday 04:00-18:00 every 10 min
Friday 18:00-23:59 every 10 min
Saturday from 00:00-04:00 every 10 min
Saturday from 04:00-18:00 every 20 min
Saturday from 18:00-23:59 every 10 minutes until Sunday at 04:00 am returning every 20 min.