on *:text:!help:*:{
cd.help
}
alias -l cd.help {
.msg $nick To set count down date, use !cd [month] [day] <year> <time> <am/pm>
.msg $nick Only [month] and [day] are required. <year> will default to the current year, or next if the date has already passed.
.msg $nick Midnight will be the default time, unless specified
.msg $nick <time> can be in 12 or 24 hour format. If the 12 hour format is used, am will be the default
.msg $nick $str($chr(46),20)
.msg $nick To see how much time is left, use !cd <count down number>
.msg $nick If <count down number> is left blank, then a list of all count downs will be shown
}
alias -l last.day {
return $gettok(31 28 31 30 31 30 31 31 30 31 30 31,$1,32)
}
alias count_down {
return $gettok($hget(count_down,$1).data,$3-,32)
}
on *:text:!cd*:*:{
set %nick $iif($chan,$chan,$nick)
if !$2 {
var %a = 1, %b = $hget(count_down,0).item
while %a <= %b {
.timer 1 %a .msg %nick Count down timer $hget(count_down,%a).item set for $count_down(%a) expires in $duration($timer($+(count.down,.,%a)).secs)
inc %a
}
}
elseif $2 isnum && $hget(count_down,$2) {
.msg %nick Count down timer $2 set for $gettok($hget(count_down,$2).data,$3-,32) expires in $duration($timer($+(count.down,.,$2)).secs)
}
else {
;get the month number in order to see how many days in the month
var %month = $findtok(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec,$left($2,3),32)
if !%month { cd.help }
else {
;is year specified? if not use current year
var %year = $iif($3 isnum,$3,$right($date,4))
;leap year?
if %last.day == 28 && ($calc(%year / 400) == $int($calc(%year / 400)) || $calc(%year / 4) == $int($calc(%year / 4))) {
inc %last.day
}
}
;year or expiry time?
var %time = $iif(!$3 || $3 isnum || $istok(am pm,$3,32),00:00:00,$3-)
var %hour = $gettok(%time,1,58), %min = $gettok(%time,2,58), %sec = $gettok(%time,3,58), %day = $2
if !%hour { %hour = 0 }
if !%min { %min = 0 }
if !%sec { %sec = 0 }
;recalculate the expiry date & time based on forwarding from invalid entries
while %sec > 59 {
inc %min
dec %sec 60
}
while %min > 59 {
inc %hour
dec %min 60
}
while %hour > 23 {
inc %day
dec %hour 24
}
while %day > $last.day(%month) {
inc %month
dec %day $last.day($calc(%month - 1))
}
while %month > 12 {
inc %year
dec %month 12
}
while %day > $last.day(%month) {
inc %month
dec %day $last.day($calc(%month - 1))
}
while %month > 12 {
inc %year
dec %month 12
}
inc %count_down
var %month.name $gettok(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec,%month,32)
;add entry to hash table for future reference
.hadd -m count_down %count_down %nick $nick %month.name %day %year $+(%hour,:,%min,:,%sec) $iif(am pm,$gettok($1-,-1,32),$v1)
activate_timer %count_down
}
}
alias -l activate_timer {
if !$1 {
var %a = 1, %b = $hget(count_down,0).item
while %a <= %b {
$+(.timer,count_down,.,%a) -o 1 $calc($ctime($gettok($hget(count_down,%a).data),$3-,32)) - $ctime) timer.up %a
inc %a
}
}
else {
$+(.timer,count_down,.,$1) -o 1 $calc($ctime($gettok($hget(count_down,$1).data,$3-,32)) - $ctime) timer.up $1
}
}
on *:start:{
if !$hget(count_down) { .hmake count_down 10 }
if $exists(count_down.hsh) { .hload count_down count_down.hsh }
activate_timer
}
on *:exit:{
.hsave -o count_down count_down.hsh
}
alias -l timer.up {
var %chan = $gettok($hget(count_down,$1).data,1,32), %nick = $gettok($hget(count_down,$1).data,2,32)
.msg %chan Timer set for $count_down($1) by %nick has now expired
}