From 7fd44a2042127044b5af9a0a80339ae9de7d8e91 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Fri, 1 Jan 2016 19:41:35 -0500 Subject: Inter --- lib/IRC/Client.pm6 | 85 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 37 deletions(-) (limited to 'lib') diff --git a/lib/IRC/Client.pm6 b/lib/IRC/Client.pm6 index 8ef75b8..0b64cab 100644 --- a/lib/IRC/Client.pm6 +++ b/lib/IRC/Client.pm6 @@ -40,42 +40,7 @@ class IRC::Client:ver<2.002001> { $!debug and "[server {DateTime.now}] {$str}".put; my $events = parse-irc $str; EVENTS: for @$events -> $e { - $e = {}; - - for @!plugs.grep(*.^can: 'irc-all-events') -> $p { - my $res = $p.irc-all-events(self, $e); - next EVENTS unless $res === IRC_NOT_HANDLED; - } - - if ( $e eq 'PRIVMSG' - and $e[0] eq $!nick - ) { - for @!plugs.grep(*.^can: 'irc-privmsg-me') -> $p { - my $res = $p.irc-privmsg-me(self, $e); - next EVENTS unless $res === IRC_NOT_HANDLED; - } - } - - if ( $e eq 'NOTICE' - and $e[0] eq $!nick - ) { - for @!plugs.grep(*.^can: 'irc-notice-me') -> $p { - my $res = $p.irc-notice-me(self, $e); - next EVENTS unless $res === IRC_NOT_HANDLED; - } - } - - my $cmd = 'irc-' ~ $e.lc; - for @!plugs.grep(*.^can: $cmd) -> $p { - my $res = $p."$cmd"(self, $e); - next EVENTS unless $res === IRC_NOT_HANDLED; - } - - for @!plugs.grep(*.^can: 'irc-unhandled') -> $p { - my $res = $p.irc-unhandled(self, $e); - next EVENTS unless $res === IRC_NOT_HANDLED; - } - + self.handle-event: $e; CATCH { warn .backtrace } } } @@ -104,6 +69,52 @@ class IRC::Client:ver<2.002001> { } } +method handle-event ($e) { + $e = {}; + + for @!plugs.grep(*.^can: 'irc-all-events') -> $p { + my $res = $p.irc-all-events(self, $e); + next EVENTS unless $res === IRC_NOT_HANDLED; + } + + if ( $e eq 'PRIVMSG' and $e[0] eq $!nick ) { + for @!plugs.grep(*.^can: 'irc-privmsg-me') -> $p { + my $res = $p.irc-privmsg-me(self, $e); + next EVENTS unless $res === IRC_NOT_HANDLED; + } + } + + if ( $e eq 'NOTICE' and $e[0] eq $!nick ) { + for @!plugs.grep(*.^can: 'irc-notice-me') -> $p { + my $res = $p.irc-notice-me(self, $e); + next EVENTS unless $res === IRC_NOT_HANDLED; + } + } + + if ( ( $e eq 'PRIVMSG' and $e[0] eq $!nick ) + or ( $e eq 'NOTICE' and $e[0] eq $!nick ) + or ( $e eq 'PRIVMSG' + and $e[1] ~~ /:i ^ "$!nick" <[,:]> \s+/ + ) + ) { + for @!plugs.grep(*.^can: 'irc-addressed') -> $p { + my $res = $p.irc-notice-me(self, $e); + next EVENTS unless $res === IRC_NOT_HANDLED; + } + } + + my $cmd = 'irc-' ~ $e.lc; + for @!plugs.grep(*.^can: $cmd) -> $p { + my $res = $p."$cmd"(self, $e); + next EVENTS unless $res === IRC_NOT_HANDLED; + } + + for @!plugs.grep(*.^can: 'irc-unhandled') -> $p { + my $res = $p.irc-unhandled(self, $e); + next EVENTS unless $res === IRC_NOT_HANDLED; + } +} + sub plug-name { my $plug = callframe(3).file; my $cur = $?FILE; @@ -112,4 +123,4 @@ sub plug-name { $plug ~~ s:g/^ $cur '/' | '.pm6'$//; $plug ~~ s/'/'/::/; return "[$plug] "; -} +} \ No newline at end of file -- cgit v1.1