; if timers are enabled for this network, call the set-alias one minute after connect
; (1 minute delay if connecting at 00:00 to prevent "wrong" announcements)
on *:connect: {
if ($($+(%,radiotimer.,$network),2) == on) { .timer 1 $iif(($time(HHnn) == 0),60,0) radiotimer.set }
}
; setup your timers
alias -l radiotimer.set {
; ---------- SETUP 1: TIMERS ----------
; Add commands in the format: "radiotimer.init <network(s)> <day(s)> <time(s)> <channel(s)> <message-keyword>".
; - separate multiple networks/days/channels with commas (only commas, no spaces!)
; - you may use the abbreviations "Mon/Tue/Wed/Thu/Fri/Sat/Sun" for the day(s)
; To allow "midnight announcements" without conflict ("will the announcing timer or the refresh timer trigger first?"),
; a "new day" starts at 00:01 for the script. 00:00 will count to the day that just passed.
; Avoid setting timers to 00:01 - all other times should be fine.
; Examples:
; announce the message(s) for "request_hour" each friday/saturday/sunday at 20:00 in the channel "#netradio" on networks "efnet" and "anothernet"
radiotimer.init efnet,anothernet fri,sat,sun 20:00 #netradio request_hour
; announce the message(s) for "saturday's_cue" each friday at 22:00, 22:30 and 00:00 in the channels "#netradio" and "#radionet" on efnet
radiotimer.init efnet friday 22:00,22:30,0:00 #netradio,#radionet saturday's_cue
; ---------- SETUP 1 END ----------
; start the refresh timer (per network)
.timer.radiotimer.refresh. $+ $network 00:00 1 0 radiotimer.refresh
}
; refresh routine - triggered at 0:00 (a new $day) and refreshing at 0:01 (this ensures no "midnight" timer is overwritten or triggered twice)
alias -l radiotimer.refresh { .timer.radiotimer.refresh. $+ $network 00:01 1 0 radiotimer.set }
; setup your message(s) per keyword
alias -l radiotimer.msg {
var %chan = $gettok($ctimer,4,9), %key = $gettok($ctimer,5,9)
if ($me ison %chan) {
; ---------- SETUP 2: MESSAGES ----------
; create if-conditions: if (%key == <some_keyword>) { msg %chan <your message> }
; Examples:
if (%key == request_hour) { msg %chan <<< Now starting the !request hour! >>> }
elseif (%key == saturday's_cue) {
msg %chan ------------------------------------------
msg %chan Don't miss our big Saturday show
msg %chan ------------------------------------------
}
; ---------- SETUP 2 END ----------
}
}
; routine to process the commands set at "radiotimer.set"
alias -l radiotimer.init {
; all required parameters exist
if ($5 != $null) {
; timer definition matches current network and current day
if ($istok($1,$network,44)) && ($wildtok($2,$time(ddd) $+ *,1,44)) {
; loop the time(s) specified
var %a = 1
while ($gettok($3,%a,44)) {
var %t = $v1
; time is valid (e.g. not "24:00") and time hasn't passed, except 00:00
if ($ctime($date %t)) && (($istok(0:00 00:00,%t,32)) || ($ctime($date $time(HH:nn)) < $ctime($date %t))) {
; loop the channel(s) specified
var %b = 1
while ($gettok($4,%b,44)) {
; start a timer named ".radiotimer[TAB]<network>[TAB]<time>[TAB]<channel>[TAB]<keyword>"
; on execution the timer will call the alias "radiotimer.msg"
; (the alias in turn will get the required parameters <channel> and <keyword> out of the timer's name)
$+(.timer,.radiotimer,$chr(9),$network,$chr(9),%t,$chr(9),$v1,$chr(9),$5) %t 1 0 radiotimer.msg
inc %b
}
}
inc %a
}
}
}
}
; menu to enable/disable the timers (of the current network / of all connected networks)
menu status,menubar {
$iif(($status != connected),$style(2)) Radiotimer
.$network $+([,$iif(($($+(%,radiotimer.,$network),2) == on),enabled,disabled),]))
..$iif(($($+(%,radiotimer.,$network),2) == on),disable,enable) timer(s) : { radiotimer.switch }
.-
.enable timer(s) on all connected networks { scon -at1 radiotimer.switch on }
.disable timer(s) on all connected networks { scon -at1 radiotimer.switch off }
}
; switching routine (menu)
alias -l radiotimer.switch {
; set switch
var %v = $+(%,radiotimer.,$network)
set $(%v) $iif($1,$v1,$iif(($(%v,2) == on),off,on))
; start/stop timers acc. to state of switch
if ($(%v,2) == on) { radiotimer.set }
else {
$+(.timer.radiotimer,$chr(9),$network,$chr(9),*) off
.timer.radiotimer.refresh. $+ $network off
}
ECHO -s Radiotimer(s) for $network are now: $(%v,2)
}
; stop timers and delete variables on unload
on *:unload: {
.timer.radiotimer* off
unset %radiotimer.*
}