role Net::IRC::SeenExt[: Bool ?$public = 1]; has %!seen; submethod BUILD() { self.add_handler("PRIVMSG", -> $event { my $sent_to_a_chan = $event ~~ rx:Perl5/^[#+&]/; # Only record if the message was sent to a channel. %!seen{self.normalize($event)} = { date => time, text => $event, } if $sent_to_a_chan; if $public and $event ~~ rx:Perl5/^\?seen\s+([^ ]+)/ { my $reply_to = $sent_to_a_chan ?? $event !! $event; my $reply_msg = %!seen{$0} ?? "$0 was last seen {time() - %!seen{self.normalize($0)}} seconds ago, saying: %seen{self.normalize($0)}" !! "Never seen $0."; self.notice(to => $reply_to, text => $reply_msg); } }); } method seen(Str $nick) { %!seen{self.normalize($nick)} } 1; =head1 NAME Net::IRC::SeenExt - Tracks the times people spoke lastly =head1 SYNOPSIS use Net::IRC; use Net::IRC::SeenExt; my $bot = Net::IRC.new(...); $bot does Net::IRC::SeenExt[public => 0]; # or class MyBot does Net::IRC::SeenExt[public => 0] {...} my $bot = MyBot.new(...); my :(date => $date, text => $text) := $bot.seen("iblech"); say "iblech was last seen {time - $date}s ago, saying: $text"; =head1 DESCRIPTION C is a role which installs a event handler listening for all Cs. Each time people say something (in public), the current time and the text they said is saved. If the (optional) role parameter C is set to a true value, C installs a public command handler matching ?seen nick There's also the C method, which can be used to query C for the time C<$nick> was last seen, too. =head1 BUGS Beware: This role uses syntax which is not yet accepted, see thread "Syntax for specifying role parameters" on p6l. =head1 AUTHOR Ingo Blechschmidt Eiblech@web.deE =head1 LICENSE This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L and L for details. =cut