###################################################################################################################### # # cdwn.pl - Very configurable countdown till target date/time script # originally ment to countdown to newyears... # # typing !cdwn (or whatever you set cdwn_trigger to) will report # type !cdwn UTC-5 for EST, !cdwn UTC-8, !cdwn utc+9 for some asian weirdness etc # # Settings (default values shown): # cdwn_target = 2007/1/1 00:00:00 // time/date to count down to USE THIS FORMAT!!! # cdwn_dly = 1 // time between calls (prevents flooding) # cdwn_utc = -5 // this computer's timezone in utc format MUST SET THIS!! # cdwn_trigger = !cdwn // trigger to use in channels # // These define what to say before and after the target date (can add colors or remove year etc etc) # cdwn_til_str = $year years $mon months $day (or $yday) days til $tyear/$tmon/$tday $thour:$tmin:$tsec ($utc) # cdwn_past_str =$year years $mon months $day (or $yday) days past $tyear/$tmon/$tday $thour:$tmin:$tsec ($utc) # # Note: $yday differs from $day (which is monthday) by displaying how many calendar days # till the target (as compared to monthdays which will never be > 30) # # Kallisti (K) 2006 All rights reversed. Mess with this program. Call it your own. Hail Eris. -><- # ###################################################################################################################### use strict; use vars qw($VERSION %IRSSI); use Irssi; use Irssi::Irc; my ($nexttime,$trigger,$delay,$utc,$ttime,$cdwn_til_str,$cdwn_past_str); $VERSION = '5.00'; %IRSSI = ( authors => 'Eris', contact => 'eris@servergirl.net', name => 'Countdown til date/time script', description => 'prints time till target date', license => 'Public Domain', ); #print countdown when trigger string is entered sub cdwn_printdate { my ($server, $msg, $nick, $address, $targetchan)=@_; #check for trigger phrase and holdoff timer if (($msg =~ /^$trigger.*/) && (time() >= $nexttime)){ my ($dutc,$tmpstr,$usetime); #check if utc is specified if(!(($dutc)=$msg=~/ UTC([-+][0-9]{1,2})/i)) { $dutc=$utc; } #Determine if its present or past if($ttime >= time+$dutc*3600) { $usetime=$ttime-(time+$dutc*3600); #target time $tmpstr=$cdwn_til_str; } else { #past $usetime=(time+$dutc*3600)-$ttime; $tmpstr=$cdwn_past_str; } # Use the groovy perl time interface. my ($tsec,$tmin,$thour,$tmday,$tmon,$tyear,$twday,$tyday,$tisdst) = gmtime($ttime); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($usetime); # Fix the screwed up results from the groovy perl time interface. $year-=70; $mday--; $tmon++; $tyear += 1900; $tmpstr=~s/\$year/sprintf('%04d',$year)/eg; $tmpstr=~s/\$mon/sprintf('%02d',$mon)/eg; $tmpstr=~s/\$day/sprintf('%02d',$mday)/eg; $tmpstr=~s/\$yday/sprintf('%02d',$yday)/eg; $tmpstr=~s/\$hour/sprintf('%02d',$hour)/eg; $tmpstr=~s/\$min/sprintf('%02d',$min)/eg; $tmpstr=~s/\$sec/sprintf('%02d',$sec)/eg; $tmpstr=~s/\$tyear/sprintf('%04d',$tyear)/eg; $tmpstr=~s/\$tmon/sprintf('%02d',$tmon)/eg; $tmpstr=~s/\$tday/sprintf('%02d',$tmday)/eg; $tmpstr=~s/\$thour/sprintf('%02d',$thour)/eg; $tmpstr=~s/\$tmin/sprintf('%02d',$tmin)/eg; $tmpstr=~s/\$tsec/sprintf('%02d',$tsec)/eg; $tmpstr=~s/\$utc/UTC$dutc/g; $server->command("/QUOTE PRIVMSG " . $targetchan ." :$tmpstr"); $server->print($targetchan,$tmpstr,MSGLEVEL_CLIENTCRAP); $nexttime = time()+$delay; } } #reply to triggers from client itself sub cdwn_own_pub_msg { my ($server,$msg,$targetchan)=@_; cdwn_printdate($server,$msg,'','',$targetchan); } #days in the month array my @ditm=(0,31,59,90,120,151,181,212,243,273,304,334); #Ran whever the settings change (or script loads) sub cdwn_change_settings { $delay=Irssi::settings_get_int('cdwn_dly'); $trigger=Irssi::settings_get_str('cdwn_trigger'); $utc=Irssi::settings_get_int('cdwn_utc'); my $targetdate=Irssi::settings_get_str('cdwn_target'); $cdwn_til_str=Irssi::settings_get_str('cdwn_til_str'); $cdwn_past_str=Irssi::settings_get_str('cdwn_past_str'); my ($year,$mon,$mday,$hour,$min,$sec)= $targetdate =~ /([0-9]{4})\/([0-9]{1,2})\/([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})/; $year-=1970; #unix time starts in 1970 $mday+=$ditm[$mon-1]+$year*365+int($year/4); #turn years/months/days into just days compensating for leap years and days in each month $ttime=$sec+$min*60+$hour*3600+($mday-1)*86400; # $nexttime=time(); } #setup signal hooks Irssi::signal_add_last('message public', 'cdwn_printdate'); Irssi::signal_add('message own_public','cdwn_own_pub_msg'); Irssi::signal_add('setup changed', 'cdwn_change_settings'); Irssi::signal_add('setup reread', 'cdwn_change_settings'); #add setting to irssi Irssi::settings_add_int('countdown', 'cdwn_dly', '1'); Irssi::settings_add_str('countdown', 'cdwn_trigger', '!cdwn'); Irssi::settings_add_str('countdown', 'cdwn_target', '2007/01/01 00:00:00'); Irssi::settings_add_int('countdown', 'cdwn_utc', '-5'); Irssi::settings_add_str('countdown', 'cdwn_til_str', '$year years $mon months $day days $hour hours $min mins $sec seconds til $tyear/$tmon/$tday $thour:$tmin:$tsec ($utc)'); Irssi::settings_add_str('countdown', 'cdwn_past_str', '$year years $mon months $day days $hour hours $min mins $sec seconds past $tyear/$tmon/$tday $thour:$tmin:$tsec ($utc)'); #call this when loaded plz cdwn_change_settings();