aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorZoffix Znet <cpan@zoffix.com>2016-01-01 19:41:35 -0500
committerZoffix Znet <cpan@zoffix.com>2016-01-01 19:41:35 -0500
commit7fd44a2042127044b5af9a0a80339ae9de7d8e91 (patch)
treee0ae673ff0200c1a2897f4e905118cf32b6942b8 /lib
parent25c018213454c4aee59a46d2d77adad4b73444b0 (diff)
Inter
Diffstat (limited to 'lib')
-rw-r--r--lib/IRC/Client.pm685
1 files changed, 48 insertions, 37 deletions
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<pipe> = {};
-
- 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<command> eq 'PRIVMSG'
- and $e<params>[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<command> eq 'NOTICE'
- and $e<params>[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<command>.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<pipe> = {};
+
+ 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<command> eq 'PRIVMSG' and $e<params>[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<command> eq 'NOTICE' and $e<params>[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<command> eq 'PRIVMSG' and $e<params>[0] eq $!nick )
+ or ( $e<command> eq 'NOTICE' and $e<params>[0] eq $!nick )
+ or ( $e<command> eq 'PRIVMSG'
+ and $e<params>[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<command>.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