diff --git a/lib/Whateverable.pm6 b/lib/Whateverable.pm6 index e48f780..200be3c 100644 --- a/lib/Whateverable.pm6 +++ b/lib/Whateverable.pm6 @@ -108,6 +108,29 @@ multi method irc-to-me(Message $msg where .text ~~ /:i^ uptime \s* $/) { ~ “implementing {.language_name} {.language_version}.” }) } +#| Get the oldest commit DateTime for $*PROGRAM. Needs $*CWD to point to the whateverable git repository. +sub term: { + my $dates = run :out, ‘git’, ‘log’, ‘--follow’, ‘--date-order’, ‘--format=%aI’, $*PROGRAM.relative; + try { $dates.out.lines(:close).tail.&{ DateTime.new($_) }.Date } \ + or fail ‘no birthday data available’ +} +#| Proper answer to “how old are you?” +sub my-age is export { + with birthday { + “I was created on $_” + } + else { + .exception.message + } +} +#| Replying to age inquiry +multi method irc-to-me(Message $ where .text ~~ /:i^ [‘how old are you’|‘age’] /) { + my-age +} +#| Replying to age inquiry +multi method irc-privmsg-channel($msg where .text ~~ /:i [‘how old are you’|‘age’] .* $($msg.server.current-nick) /) { + my-age +} #| You're welcome! sub you're-welcome is export { « diff --git a/xt/lib/Testable.pm6 b/xt/lib/Testable.pm6 index b6eb000..2633513 100644 --- a/xt/lib/Testable.pm6 +++ b/xt/lib/Testable.pm6 @@ -234,6 +234,14 @@ class Testable { “$.bot-nick,url”, “$.our-nick, https://github.com/perl6/whateverable”); + self.test(‘age inquiry (directly)’, + “$.bot-nick, how old are you?”, + /^“{$.our-nick}, ” ‘I was created on ’ [ \d**4 ‘-’ \d**2 ‘-’ \d**2 ] /); + + self.test(‘age inquiry (indirectly)’, + “age, {$.bot-nick}?”, + /^“{$.our-nick}, ” ‘I was created on ’ [ \d**4 ‘-’ \d**2 ‘-’ \d**2 ] /); + use Whateverable; self.test(‘thank you (directly)’, “$.bot-nick: thank you!”,