From a579b7896ddb10c988bfd4c948dc33cad64085c7 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Sun, 13 Dec 2015 13:54:16 -0500 Subject: Lotsa changews --- lib/IRC/Client.pm6 | 60 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 10 deletions(-) (limited to 'lib/IRC/Client.pm6') diff --git a/lib/IRC/Client.pm6 b/lib/IRC/Client.pm6 index 55d4262..4e95aaf 100644 --- a/lib/IRC/Client.pm6 +++ b/lib/IRC/Client.pm6 @@ -1,8 +1,8 @@ use v6; use IRC::Parser; # parse-irc use IRC::Client::Plugin::PingPong; -role IRC::Client::Plugin { ... } -class IRC::Client:ver<1.001001> { +use IRC::Client::Plugin; +class IRC::Client:ver<1.002001> { has Bool:D $.debug = False; has Str:D $.host = 'localhost'; has Int:D $.port where 0 <= $_ <= 65535 = 6667; @@ -16,6 +16,7 @@ class IRC::Client:ver<1.001001> { has @.plugins-essential = [ IRC::Client::Plugin::PingPong.new ]; + has @!plugs = [|@!plugins-essential, |@!plugins]; method run { await IO::Socket::Async.connect( $!host, $!port ).then({ @@ -24,16 +25,44 @@ class IRC::Client:ver<1.001001> { $.ssay("USER $!username $!userhost $!host :$!userreal\n"); $.ssay("JOIN $_\n") for @!channels; - Supply.interval( .interval ).tap({ $OUTER::_.interval(self) }) - for @!plugins.grep(*.interval); + .register: self for @!plugs.grep(*.^can: 'register'); react { whenever $!sock.Supply -> $str is copy { - $!debug and $str.say; + $!debug and "[server {DateTime.now}] {$str}".put; my $messages = parse-irc $str; - for @$messages -> $message { - .msg(self, $message) - for (@!plugins-essential, @!plugins).flat.grep(*.msg); + MESSAGES: for @$messages -> $message { + $message = False; + $message = {}; + + if ( $message eq 'PRIVMSG' + and $message[0] eq $!nick + ) { + for @!plugs.grep(*.^can: 'privmsg-me') -> $p { + my $res = $p.privmsg-me(self, $message); + next MESSAGES unless $res === irc-not-handled; + } + } + + if ( $message eq 'NOTICE' + and $message[0] eq $!nick + ) { + for @!plugs.grep(*.^can: 'notice-me') -> $p { + my $res = $p.notice-me(self, $message); + next MESSAGES unless $res === irc-not-handled; + } + } + + my $cmd = 'irc-' ~ $message.lc; + for @!plugs.grep(*.^can: $cmd) -> $p { + my $res = $p."$cmd"(self, $message); + next MESSAGES unless $res === irc-not-handled; + } + + for @!plugs.grep(*.^can: 'msg') -> $p { + my $res = $p.msg(self, $message); + next MESSAGES unless $res === irc-not-handled; + } } } } @@ -44,14 +73,25 @@ class IRC::Client:ver<1.001001> { } method ssay (Str:D $msg) { + $!debug and "{plug-name}$msg".put; $!sock.print("$msg\n"); self; } method privmsg (Str $who, Str $what) { my $msg = ":$!nick!$!username\@$!userhost PRIVMSG $who :$what\n"; - $!debug and say ".privmsg({$msg.subst("\n", "␤", :g)})"; - self.ssay: $msg; + $!debug and "{plug-name}$msg".put; + $!sock.print("$msg\n"); self; } } + +sub plug-name { + my $plug = callframe(3).file; + my $cur = $?FILE; + return '[core] ' if $plug eq $cur; + $cur ~~ s/'.pm6'$//; + $plug ~~ s:g/^ $cur '/' | '.pm6'$//; + $plug ~~ s/'/'/::/; + return "[$plug] "; +} \ No newline at end of file -- cgit v1.1 From 22e34475c8fe5d6957525962adb4f65d910e46d0 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Sun, 13 Dec 2015 14:14:10 -0500 Subject: Rename constants to all-caps --- lib/IRC/Client.pm6 | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'lib/IRC/Client.pm6') diff --git a/lib/IRC/Client.pm6 b/lib/IRC/Client.pm6 index 4e95aaf..c8e6ac4 100644 --- a/lib/IRC/Client.pm6 +++ b/lib/IRC/Client.pm6 @@ -32,7 +32,6 @@ class IRC::Client:ver<1.002001> { $!debug and "[server {DateTime.now}] {$str}".put; my $messages = parse-irc $str; MESSAGES: for @$messages -> $message { - $message = False; $message = {}; if ( $message eq 'PRIVMSG' @@ -40,7 +39,7 @@ class IRC::Client:ver<1.002001> { ) { for @!plugs.grep(*.^can: 'privmsg-me') -> $p { my $res = $p.privmsg-me(self, $message); - next MESSAGES unless $res === irc-not-handled; + next MESSAGES unless $res === IRC_NOT_HANDLED; } } @@ -49,19 +48,19 @@ class IRC::Client:ver<1.002001> { ) { for @!plugs.grep(*.^can: 'notice-me') -> $p { my $res = $p.notice-me(self, $message); - next MESSAGES unless $res === irc-not-handled; + next MESSAGES unless $res === IRC_NOT_HANDLED; } } my $cmd = 'irc-' ~ $message.lc; for @!plugs.grep(*.^can: $cmd) -> $p { my $res = $p."$cmd"(self, $message); - next MESSAGES unless $res === irc-not-handled; + next MESSAGES unless $res === IRC_NOT_HANDLED; } for @!plugs.grep(*.^can: 'msg') -> $p { my $res = $p.msg(self, $message); - next MESSAGES unless $res === irc-not-handled; + next MESSAGES unless $res === IRC_NOT_HANDLED; } } } -- cgit v1.1 From 05647bd1f2312cc756f71152252a6349e86f43c5 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Sun, 13 Dec 2015 19:14:23 -0500 Subject: update docs --- lib/IRC/Client.pm6 | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'lib/IRC/Client.pm6') diff --git a/lib/IRC/Client.pm6 b/lib/IRC/Client.pm6 index c8e6ac4..2623dc2 100644 --- a/lib/IRC/Client.pm6 +++ b/lib/IRC/Client.pm6 @@ -30,37 +30,37 @@ class IRC::Client:ver<1.002001> { react { whenever $!sock.Supply -> $str is copy { $!debug and "[server {DateTime.now}] {$str}".put; - my $messages = parse-irc $str; - MESSAGES: for @$messages -> $message { - $message = {}; + my $event = parse-irc $str; + EVENTS: for @$events -> $e { + $e = {}; - if ( $message eq 'PRIVMSG' - and $message[0] eq $!nick + if ( $e eq 'PRIVMSG' + and $e[0] eq $!nick ) { for @!plugs.grep(*.^can: 'privmsg-me') -> $p { - my $res = $p.privmsg-me(self, $message); - next MESSAGES unless $res === IRC_NOT_HANDLED; + my $res = $p.privmsg-me(self, $e); + next EVENTS unless $res === IRC_NOT_HANDLED; } } - if ( $message eq 'NOTICE' - and $message[0] eq $!nick + if ( $e eq 'NOTICE' + and $e[0] eq $!nick ) { for @!plugs.grep(*.^can: 'notice-me') -> $p { - my $res = $p.notice-me(self, $message); - next MESSAGES unless $res === IRC_NOT_HANDLED; + my $res = $p.notice-me(self, $e); + next EVENTS unless $res === IRC_NOT_HANDLED; } } - my $cmd = 'irc-' ~ $message.lc; + my $cmd = 'irc-' ~ $e.lc; for @!plugs.grep(*.^can: $cmd) -> $p { - my $res = $p."$cmd"(self, $message); - next MESSAGES unless $res === IRC_NOT_HANDLED; + my $res = $p."$cmd"(self, $e); + next EVENTS unless $res === IRC_NOT_HANDLED; } - for @!plugs.grep(*.^can: 'msg') -> $p { - my $res = $p.msg(self, $message); - next MESSAGES unless $res === IRC_NOT_HANDLED; + for @!plugs.grep(*.^can: 'all-events') -> $p { + my $res = $p.all-events(self, $e); + next EVENTS unless $res === IRC_NOT_HANDLED; } } } -- cgit v1.1 From cdadd4d23b894d1f8b6e93094e2662332a9ae710 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Sun, 13 Dec 2015 20:07:47 -0500 Subject: fix error --- lib/IRC/Client.pm6 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/IRC/Client.pm6') diff --git a/lib/IRC/Client.pm6 b/lib/IRC/Client.pm6 index 2623dc2..fe6d962 100644 --- a/lib/IRC/Client.pm6 +++ b/lib/IRC/Client.pm6 @@ -30,7 +30,7 @@ class IRC::Client:ver<1.002001> { react { whenever $!sock.Supply -> $str is copy { $!debug and "[server {DateTime.now}] {$str}".put; - my $event = parse-irc $str; + my $events = parse-irc $str; EVENTS: for @$events -> $e { $e = {}; -- cgit v1.1 From c7e225793004a36b8af7d6a58986df31fdb60822 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Mon, 21 Dec 2015 08:43:04 -0500 Subject: Add `unhandled` event --- lib/IRC/Client.pm6 | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'lib/IRC/Client.pm6') diff --git a/lib/IRC/Client.pm6 b/lib/IRC/Client.pm6 index fe6d962..7b1c7e5 100644 --- a/lib/IRC/Client.pm6 +++ b/lib/IRC/Client.pm6 @@ -52,14 +52,19 @@ class IRC::Client:ver<1.002001> { } } + for @!plugs.grep(*.^can: 'all-events') -> $p { + my $res = $p.all-events(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: 'all-events') -> $p { - my $res = $p.all-events(self, $e); + for @!plugs.grep(*.^can: 'unhandled') -> $p { + my $res = $p.unhandled(self, $e); next EVENTS unless $res === IRC_NOT_HANDLED; } } @@ -93,4 +98,4 @@ sub plug-name { $plug ~~ s:g/^ $cur '/' | '.pm6'$//; $plug ~~ s/'/'/::/; return "[$plug] "; -} \ No newline at end of file +} -- cgit v1.1 From c97eb34b64788602713fcc77d3c18ab17b629318 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Mon, 21 Dec 2015 09:10:03 -0500 Subject: Some docs --- lib/IRC/Client.pm6 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'lib/IRC/Client.pm6') diff --git a/lib/IRC/Client.pm6 b/lib/IRC/Client.pm6 index 7b1c7e5..c781ef1 100644 --- a/lib/IRC/Client.pm6 +++ b/lib/IRC/Client.pm6 @@ -34,10 +34,15 @@ class IRC::Client:ver<1.002001> { EVENTS: for @$events -> $e { $e = {}; + for @!plugs.grep(*.^can: 'irc-all-events') -> $p { + my $res = $p.all-events(self, $e); + next EVENTS unless $res === IRC_NOT_HANDLED; + } + if ( $e eq 'PRIVMSG' and $e[0] eq $!nick ) { - for @!plugs.grep(*.^can: 'privmsg-me') -> $p { + for @!plugs.grep(*.^can: 'irc-privmsg-me') -> $p { my $res = $p.privmsg-me(self, $e); next EVENTS unless $res === IRC_NOT_HANDLED; } @@ -46,24 +51,19 @@ class IRC::Client:ver<1.002001> { if ( $e eq 'NOTICE' and $e[0] eq $!nick ) { - for @!plugs.grep(*.^can: 'notice-me') -> $p { + for @!plugs.grep(*.^can: 'irc-notice-me') -> $p { my $res = $p.notice-me(self, $e); next EVENTS unless $res === IRC_NOT_HANDLED; } } - for @!plugs.grep(*.^can: 'all-events') -> $p { - my $res = $p.all-events(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: 'unhandled') -> $p { + for @!plugs.grep(*.^can: 'irc-unhandled') -> $p { my $res = $p.unhandled(self, $e); next EVENTS unless $res === IRC_NOT_HANDLED; } -- cgit v1.1 From 1e3a40a23f5f7bce1e9512b0619b91986f001fa8 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Mon, 21 Dec 2015 09:11:45 -0500 Subject: Add missing irc- prefixes to special methods --- lib/IRC/Client.pm6 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/IRC/Client.pm6') diff --git a/lib/IRC/Client.pm6 b/lib/IRC/Client.pm6 index c781ef1..eaffb23 100644 --- a/lib/IRC/Client.pm6 +++ b/lib/IRC/Client.pm6 @@ -35,7 +35,7 @@ class IRC::Client:ver<1.002001> { $e = {}; for @!plugs.grep(*.^can: 'irc-all-events') -> $p { - my $res = $p.all-events(self, $e); + my $res = $p.irc-all-events(self, $e); next EVENTS unless $res === IRC_NOT_HANDLED; } @@ -43,7 +43,7 @@ class IRC::Client:ver<1.002001> { and $e[0] eq $!nick ) { for @!plugs.grep(*.^can: 'irc-privmsg-me') -> $p { - my $res = $p.privmsg-me(self, $e); + my $res = $p.irc-privmsg-me(self, $e); next EVENTS unless $res === IRC_NOT_HANDLED; } } @@ -52,7 +52,7 @@ class IRC::Client:ver<1.002001> { and $e[0] eq $!nick ) { for @!plugs.grep(*.^can: 'irc-notice-me') -> $p { - my $res = $p.notice-me(self, $e); + my $res = $p.irc-notice-me(self, $e); next EVENTS unless $res === IRC_NOT_HANDLED; } } @@ -64,7 +64,7 @@ class IRC::Client:ver<1.002001> { } for @!plugs.grep(*.^can: 'irc-unhandled') -> $p { - my $res = $p.unhandled(self, $e); + my $res = $p.irc-unhandled(self, $e); next EVENTS unless $res === IRC_NOT_HANDLED; } } -- cgit v1.1 From c3ac49e463440b318fa70cfddaed3f91c6797556 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Mon, 21 Dec 2015 09:43:30 -0500 Subject: Add irc-start-up and irc-connected methods. Toss irc-register --- lib/IRC/Client.pm6 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/IRC/Client.pm6') diff --git a/lib/IRC/Client.pm6 b/lib/IRC/Client.pm6 index eaffb23..59efa97 100644 --- a/lib/IRC/Client.pm6 +++ b/lib/IRC/Client.pm6 @@ -19,13 +19,15 @@ class IRC::Client:ver<1.002001> { has @!plugs = [|@!plugins-essential, |@!plugins]; method run { + .irc-start-up: self for @!plugs.grep(*.^can: 'irc-start-up'); + await IO::Socket::Async.connect( $!host, $!port ).then({ $!sock = .result; $.ssay("NICK $!nick\n"); $.ssay("USER $!username $!userhost $!host :$!userreal\n"); $.ssay("JOIN $_\n") for @!channels; - .register: self for @!plugs.grep(*.^can: 'register'); + .irc-connected: self for @!plugs.grep(*.^can: 'irc-connected'); react { whenever $!sock.Supply -> $str is copy { -- cgit v1.1 From c525790efcc8f1b45c3d236a08da1f8ed122fc9b Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Mon, 21 Dec 2015 09:56:38 -0500 Subject: Bump versions --- lib/IRC/Client.pm6 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/IRC/Client.pm6') diff --git a/lib/IRC/Client.pm6 b/lib/IRC/Client.pm6 index 59efa97..65f80e7 100644 --- a/lib/IRC/Client.pm6 +++ b/lib/IRC/Client.pm6 @@ -2,7 +2,7 @@ use v6; use IRC::Parser; # parse-irc use IRC::Client::Plugin::PingPong; use IRC::Client::Plugin; -class IRC::Client:ver<1.002001> { +class IRC::Client:ver<2.001001> { has Bool:D $.debug = False; has Str:D $.host = 'localhost'; has Int:D $.port where 0 <= $_ <= 65535 = 6667; -- cgit v1.1