#!perl # Remind module for mozbot # This is an evil hack that will not work for you. Just thought I'd warn ya. # Copyright 2004 Dave O'Neill # This code may be redistributed under the same terms as Perl package BotModules::Remind; use vars qw(@ISA); @ISA = qw(BotModules); use Date::Calc qw( Add_Delta_Days ); 1; sub Help { my $self = shift; my ($event) = @_; return { '' => 'This module gets info from a remind file and display sit', 'support today' => 'Checks our support calendar to see who is on 2nd level support today', 'support tomorrow' => 'Checks our support calendar to see who is on 2nd level support tomorrow', 'support YYYY-MM-DD' => 'Checks our support calendar to see who is on 2nd level support for the given date', }; } sub Told { my $self = shift; my ($event, $message) = @_; unless ($self->parseMessage($event, $message) ) { return $self->SUPER::Told(@_); } return 0; # we've dealt with it, no need to do anything else. } sub Heard { my $self = shift; my ($event, $message) = @_; unless ( $self->parseMessage($event, $message) ) { return $self->SUPER::Heard(@_); } return 0; # we've dealt with it, no need to do anything else. } # Return 1 if message was parsed as one of ours, 0 otherwise sub parseMessage { my $self = shift; my ($event, $message) = @_; if( my($what,$year,$month,$day)= $message =~ m'support\s+(today|tomorrow|(?:(\d\d\d\d)[-/](\d\d)[-/](\d\d)))'i ) { # Fetch date firgt my %time; @time{"sec","min","hour","mday","mon","year","wday","yday","isdst"} = localtime(time); $time{year} += 1900; $time{mon}++; for($what) { /^today/ && do { $self->showReminderByDate($event, @time{"year","mon","mday"}); last; }; /^tomorrow/ && do { my($year,$month,$day) = Add_Delta_Days(@time{"year","mon","mday"}, 1); $self->showReminderByDate($event, $year, $month, $day); last; }; /^\d\d\d\d.\d\d.\d\d/ && do { $self->showReminderByDate($event, $year, $month, $day); last; }; } return 1; } return 0; } sub showReminderByDate { my $self = shift; my ($event, $year, $month, $day) = @_; # Ugh, evil hack my @mword = qw( none Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ); my $remind = `/usr/local/bin/remind -n /home/dmo/CanIt/InternalDoc/support-calendar.rem $day $mword[$month] $year`; my ($who) = $remind =~ m|$year/$month/$day (.*)|mg; if( ! defined($who) ) { $who = 'nobody'; } my $result = "My calendar says $who is on 2nd level support for $year/$month/$day"; $self->say($event, $result); }