Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

@AlexDaniel AlexDaniel Sep 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used to write run like this, but nowadays I'd do 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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? Bots automatically gist uncaught exceptions, there's no need. You can of course grumble ‘something went wrong’ but I don't see any good reason. In this case exception is totally fine, although I'm a bit confused as to when it'll trigger given that ‘no birthday data available’ message is there? Maybe wrap the whole thing in a try/catch and just output ‘no birthday data available no matter what goes wrong? The feature is more like an easter egg, so I'm not too concerned about debugging.

Also, change it to ‘I don't remember’, I think that's funnier.

.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