Skip to content

Commit

Permalink
Answer “how old are you” and “age” queries
Browse files Browse the repository at this point in the history
The script creation date is obtained from the git history. Resolves Raku#361.
  • Loading branch information
taboege committed Sep 18, 2019
1 parent 0357ee5 commit 0e7ec6d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/Whateverable.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -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:<birthday> {
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 {
«
Expand Down
8 changes: 8 additions & 0 deletions xt/lib/Testable.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -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!,
Expand Down

0 comments on commit 0e7ec6d

Please sign in to comment.