From b1e795877f2447bc634cbb4b269f9ac8bebd67f3 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Sun, 7 Aug 2016 22:58:46 -0400 Subject: Add `:alias` feature Closes #22 --- lib/IRC/Client.pm6 | 15 +++++++++++---- lib/IRC/Client/Server.pm6 | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/IRC/Client.pm6 b/lib/IRC/Client.pm6 index 7dbadf9..34e6f54 100644 --- a/lib/IRC/Client.pm6 +++ b/lib/IRC/Client.pm6 @@ -41,6 +41,7 @@ submethod BUILD ( Str :$password, Str:D :$host = 'localhost', :$nick = ['P6Bot'], + :$alias = [], Str:D :$username = 'Perl6IRC', Str:D :$userhost = 'localhost', Str:D :$userreal = 'Perl6 IRC Client', @@ -50,7 +51,7 @@ submethod BUILD ( @!plugins = @$plugins; my %servers = %$servers; - my %all-conf = :$port, :$password, :$host, :$nick, + my %all-conf = :$port, :$password, :$host, :$nick, :$alias, :$username, :$userhost, :$userreal, :$channels; %servers = '_' => {} unless %servers; @@ -61,6 +62,7 @@ submethod BUILD ( :$label, :channels( @($conf // %all-conf) ), :nick[ |($conf // %all-conf) ], + :alias[ |($conf // %all-conf) ], |%( .map: { $_ => $conf{$_} // %all-conf{$_} } @@ -234,11 +236,16 @@ method !handle-event ($e) { my @events = flat gather { given $event-name { when 'irc-privmsg-channel' | 'irc-notice-channel' { - my $nick = $s.current-nick; - if $e.text.subst-mutate: /^ $nick <[,:]> \s* /, '' { + my $nick = $s.current-nick; + my @aliases = $s.alias; + if $e.text.subst-mutate: + /^ [ $nick | @aliases ] <[,:]> \s* /, '' + { take 'irc-addressed', ('irc-to-me' if $s.is-connected); } - elsif $e.text ~~ / << $nick >> / and $s.is-connected { + elsif $e.text ~~ / << [ $nick | @aliases ] >> / + and $s.is-connected + { take 'irc-mentioned'; } take $event-name, $event-name eq 'irc-privmsg-channel' diff --git a/lib/IRC/Client/Server.pm6 b/lib/IRC/Client/Server.pm6 index f438d6d..2ed5d69 100644 --- a/lib/IRC/Client/Server.pm6 +++ b/lib/IRC/Client/Server.pm6 @@ -2,6 +2,7 @@ unit class IRC::Client::Server; has @.channels where .all ~~ Str|Pair; has @.nick where .all ~~ Str; +has @.alias where .all ~~ Str|Regex; has Int $.port where 0 <= $_ <= 65535; has Str $.label; has Str $.host; -- cgit v1.1