Permalink
Browse files

initial commit: perl 6 release date IRC bots

  • Loading branch information...
0 parents commit c3eb9aee1f65dee66938ae17e6f6f46ae3f20056 @moritz committed Jul 29, 2012
Showing with 60 additions and 0 deletions.
  1. +2 −0 README
  2. +58 −0 release-dates.pl
2 README
@@ -0,0 +1,2 @@
+Perl 6 IRC bot which informs about release dates of Perl 6 projects
+with regular releases (currently parrot, rakudo and niecza)
@@ -0,0 +1,58 @@
+use v6;
+
+use Net::IRC::Bot;
+
+sub parrot-release-after(Date $date is copy = Date.today) {
+ $date++ until $date.day-of-week == 2;
+ $date += 7 until ($date - $date.truncated-to(:month)) div 7 == 2;
+ $date;
+}
+
+sub rakudo-release-after(Date $date = Date.today) {
+ parrot-release-after($date) + 2;
+}
+
+sub niecza-release-after(Date $date = Date.today) {
+ my $d = $date.truncated-to(:week);
+ $d += 7 if $d.month < $date.month;
+ $d += 7 while $d.month == ($d + 7).month;
+ $d;
+}
+
+my $nick = 'p6rd';
+
+class ReleaseDates {
+ method !msg($from = Date.today) {
+ my @dates = <rakudo parrot niecza>.map(
+ { ; $_ => ::("&{$_}-release-after")($from) }
+ ).sort: *.value;
+ return join ', ', @dates.map: -> $d { $d.key ~ ' ' ~ $d.value };
+ }
+ multi method said($e where { $e.what ~~ /^ $nick ':' <.ws> [ '?' | 'help' | 'h'] /}) {
+ $e.msg: "Perl 6 release dates. Usage: $nick: [ 'next' | 'next month' | YYYY-MM | YYYY-MM-DD ]";
+ }
+ multi method said($e where { $e.what ~~ /^ $nick ':' <.ws> [ 'next' | 'this month' | upcoming | soon ] \s* $ / }) {
+ $e.msg: self!msg();
+ }
+ multi method said($e where { $e.what ~~ /^ $nick ':' <.ws> 'next month' \s* $ / }) {
+ my $next-month = (Date.today.truncated-to(:month) + 31).truncated-to(:month);
+ $e.msg: self!msg($next-month);
+ }
+ multi method said($e where { $e.what ~~ /^ $nick ':' <.ws> \d**4 '-' \d ** 2 / }) {
+ if $e.what ~~ /^ $nick ':' <.ws> (\d**4) '-' (\d\d) [ '-' (\d\d)]? / {
+ my $from = Date.new(+$0, +$1, +($2[0] // 1));
+ $e.msg: self!msg($from);
+ }
+ else {
+ die "Internal error: can't match {$e.what}";
+ }
+ }
+
+}
+
+Net::IRC::Bot.new(
+ :$nick,
+ server => 'irc.freenode.net',
+ channels => <#perl6 #bottest>,
+ modules => [ ReleaseDates.new ],
+).run;

0 comments on commit c3eb9ae

Please sign in to comment.