From a579b7896ddb10c988bfd4c948dc33cad64085c7 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Sun, 13 Dec 2015 13:54:16 -0500 Subject: Lotsa changews --- Changes | 10 +++++++ META.info | 2 +- lib/IRC/Client.pm6 | 60 +++++++++++++++++++++++++++++++------- lib/IRC/Client/Plugin.pm6 | 5 ++++ lib/IRC/Client/Plugin/Debugger.pm6 | 8 ++--- lib/IRC/Client/Plugin/PingPong.pm6 | 12 ++------ 6 files changed, 72 insertions(+), 25 deletions(-) create mode 100644 lib/IRC/Client/Plugin.pm6 diff --git a/Changes b/Changes index 2ea7f5e..e04841e 100644 --- a/Changes +++ b/Changes @@ -1,4 +1,14 @@ Revision History for 'IRC::Client' Perl 6 Distribution +1.002001 Unreleased + [Redesign plugin system] + - each IRC command can now be implemented with a specific method of + name 'irc_COMMAND' + - Added individual privmsg-me and notice-me methods + - Removed `interval` plugin methods. + - Added `register` plugin method that is called during client start up + [Other] + - Improved debug output + 1.001001 2015-11-19 - First version released on an unsuspecting world diff --git a/META.info b/META.info index 39e6093..02c3eab 100644 --- a/META.info +++ b/META.info @@ -1,7 +1,7 @@ { "perl" : "6.*", "name" : "IRC::Client", - "version" : "1.001001", + "version" : "1.002001", "description" : "Extendable Internet Relay Chat client", "depends" : [ "Data::Dump" ], "test-depends" : [ "Test" ], 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 diff --git a/lib/IRC/Client/Plugin.pm6 b/lib/IRC/Client/Plugin.pm6 new file mode 100644 index 0000000..deaef50 --- /dev/null +++ b/lib/IRC/Client/Plugin.pm6 @@ -0,0 +1,5 @@ +constant irc-handled = "irc plugin handled \x1"; +constant irc-not-handled = "irc plugin not-handled \x2"; +unit class IRC::Client::Plugin:ver<1.002002>; +has $.irc; + diff --git a/lib/IRC/Client/Plugin/Debugger.pm6 b/lib/IRC/Client/Plugin/Debugger.pm6 index 5966ca0..4c6775c 100644 --- a/lib/IRC/Client/Plugin/Debugger.pm6 +++ b/lib/IRC/Client/Plugin/Debugger.pm6 @@ -1,8 +1,8 @@ -use v6; use Data::Dump; -unit class IRC::Client::Plugin::Debugger:ver<1.001001>; +use IRC::Client::Plugin; +unit class IRC::Client::Plugin::Debugger:ver<1.002001> is IRC::Client::Plugin; -multi method msg () { True } -multi method msg ($irc, $msg) { +method msg ($irc, $msg) { say Dump $msg, :indent(4); + return irc-not-handled; } diff --git a/lib/IRC/Client/Plugin/PingPong.pm6 b/lib/IRC/Client/Plugin/PingPong.pm6 index 7ba977d..a85dc96 100644 --- a/lib/IRC/Client/Plugin/PingPong.pm6 +++ b/lib/IRC/Client/Plugin/PingPong.pm6 @@ -1,10 +1,2 @@ -use v6; -unit class IRC::Client::Plugin::PingPong:ver<1.001001>; - -multi method msg () { True } -multi method msg ($irc, $msg) { - return unless $msg eq 'PING'; - my $res = "PONG {$irc.nick} $msg[0]"; - $irc.debug and say $res; - $irc.ssay($res); -} +unit class IRC::Client::Plugin::PingPong:ver<1.002001>; +method irc-ping ($irc, $msg) { $irc.ssay("PONG {$irc.nick} $msg[0]") } -- 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 ++++----- lib/IRC/Client/Plugin.pm6 | 4 ++-- lib/IRC/Client/Plugin/Debugger.pm6 | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) 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; } } } diff --git a/lib/IRC/Client/Plugin.pm6 b/lib/IRC/Client/Plugin.pm6 index deaef50..eda7a0a 100644 --- a/lib/IRC/Client/Plugin.pm6 +++ b/lib/IRC/Client/Plugin.pm6 @@ -1,5 +1,5 @@ -constant irc-handled = "irc plugin handled \x1"; -constant irc-not-handled = "irc plugin not-handled \x2"; +constant IRC_HANDLED = "irc plugin handled \x1"; +constant IRC_NOT_HANDLED = "irc plugin not-handled \x2"; unit class IRC::Client::Plugin:ver<1.002002>; has $.irc; diff --git a/lib/IRC/Client/Plugin/Debugger.pm6 b/lib/IRC/Client/Plugin/Debugger.pm6 index 4c6775c..4ded968 100644 --- a/lib/IRC/Client/Plugin/Debugger.pm6 +++ b/lib/IRC/Client/Plugin/Debugger.pm6 @@ -4,5 +4,5 @@ unit class IRC::Client::Plugin::Debugger:ver<1.002001> is IRC::Client::Plugin; method msg ($irc, $msg) { say Dump $msg, :indent(4); - return irc-not-handled; + return 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 --- README.md | 45 ++++++++++++++++++++++++++++++++++++++ lib/IRC/Client.pm6 | 34 ++++++++++++++-------------- lib/IRC/Client/Plugin.pm6 | 1 - lib/IRC/Client/Plugin/Debugger.pm6 | 4 ++-- lib/IRC/Client/Plugin/PingPong.pm6 | 2 +- 5 files changed, 65 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index b2bcad9..0568858 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ IRC::Client - Extendable Internet Relay Chat client # SYNOPSIS +## Client script + ```perl6 use IRC::Client; use IRC::Client::Plugin::Debugger; @@ -17,6 +19,49 @@ IRC::Client - Extendable Internet Relay Chat client ).run; ``` +## Custom plugins + +### Basic response to an IRC command: + +The plugin chain handling the message will stop after this plugin. + +``` +unit class IRC::Client::Plugin::PingPong is IRC::Client::Plugin; +method irc-ping ($irc, $msg) { $irc.ssay("PONG {$irc.nick} $msg[0]") } +``` + +### More involved handling + +On startup, start sending message `I'm an annoying bot` to all channels +every five seconds. We also subscribe to all events and print some debugging +info. By returning a special constant, we tell other plugins to continue +processing the data. + +``` +use IRC::Client::Plugin; # import constants +unit class IRC::Client::Plugin::Debugger is IRC::Client::Plugin; + +method register($irc) { + Supply.interval( 5, 5 ).tap({ + $irc.privmsg($_, "I'm an annoying bot!") + for $irc.channels; + }) +} + +method all-events ($irc, $e) { + say "We've got a private message" + if $e eq 'PRIVMSG' and $e[0] eq $irc.nick; + + # Store arbitrary data in the `pipe` for other plugins to use + $e = True + if $e eq 'PRIVMSG'; + + say $e, :indent(4); + return IRC_NOT_HANDLED; +} + +``` + # DESCRIPTION ***Note: this is a preview dev release. Things might change and new things 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; } } } diff --git a/lib/IRC/Client/Plugin.pm6 b/lib/IRC/Client/Plugin.pm6 index eda7a0a..55db82c 100644 --- a/lib/IRC/Client/Plugin.pm6 +++ b/lib/IRC/Client/Plugin.pm6 @@ -1,5 +1,4 @@ constant IRC_HANDLED = "irc plugin handled \x1"; constant IRC_NOT_HANDLED = "irc plugin not-handled \x2"; unit class IRC::Client::Plugin:ver<1.002002>; -has $.irc; diff --git a/lib/IRC/Client/Plugin/Debugger.pm6 b/lib/IRC/Client/Plugin/Debugger.pm6 index 4ded968..17cf697 100644 --- a/lib/IRC/Client/Plugin/Debugger.pm6 +++ b/lib/IRC/Client/Plugin/Debugger.pm6 @@ -2,7 +2,7 @@ use Data::Dump; use IRC::Client::Plugin; unit class IRC::Client::Plugin::Debugger:ver<1.002001> is IRC::Client::Plugin; -method msg ($irc, $msg) { - say Dump $msg, :indent(4); +method all-events ($irc, $e) { + say Dump $e, :indent(4); return IRC_NOT_HANDLED; } diff --git a/lib/IRC/Client/Plugin/PingPong.pm6 b/lib/IRC/Client/Plugin/PingPong.pm6 index a85dc96..d6b8f28 100644 --- a/lib/IRC/Client/Plugin/PingPong.pm6 +++ b/lib/IRC/Client/Plugin/PingPong.pm6 @@ -1,2 +1,2 @@ unit class IRC::Client::Plugin::PingPong:ver<1.002001>; -method irc-ping ($irc, $msg) { $irc.ssay("PONG {$irc.nick} $msg[0]") } +method irc-ping ($irc, $e) { $irc.ssay("PONG {$irc.nick} $e[0]") } -- 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(-) 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 512990b82b7129e9438d4a83b0a6a1d26a164285 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Mon, 21 Dec 2015 08:40:04 -0500 Subject: some docs --- README.md | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 83 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 0568858..5810376 100644 --- a/README.md +++ b/README.md @@ -187,11 +187,92 @@ working order of any IRC client. **Defaults to:** Takes no arguments. Starts the IRC client. Exits when the connection to the IRC server ends. -# PLUGINS +# INCLUDED PLUGINS Currently, this distribution comes with two IRC Client plugins: -## Writing your own +## IRC::Client::Plugin::Debugger + +```perl6 + use IRC::Client; + use IRC::Client::Plugin::Debugger; + + IRC::Client.new( + :host('localhost'), + :debug, + plugins => [ IRC::Client::Plugin::Debugger.new ] + ).run; +``` + +When run, it will pretty-print all of the events received by the client. It +does not stop plugin processing loop after handling a message. + +## IRC::Client::Plugin::PingPong + +```perl6 + use IRC::Client; + IRC::Client.new.run; # automatically included in plugins-essential +``` + +This plugin makes IRC::Client respond to server's C messages and is +included in the [`plugins-essential`](#plugins-essential) by default. + +# EXTENDING IRC::Client / WRITING YOUR OWN PLUGINS + +## Overview of the plugin system + +The core IRC::Client receives and parses IRC protocol messages from the +server that it then passes through a plugin chain. The plugins declared in +[`plugins-essential`](#plugins-essential) are executed first, followed by +plugins in [`plugins`](#plugins). The order is the same as the order specified +in those two lists. + +A plugin can return a [special constant](#return-value-constants) that +indicates it handled the message and the plugin chain processing should stop. + +To subscribe to handle a particular IRC command, a plugin simply declares a +method `irc-COMMAND`, where `COMMAND` is the name of the IRC command the +plugin wishes to handle. There are also a couple of +[special events](#special-events) the plugin can subscribe to, such as +intialization during start up or when the client receives a private message +or notice. + +## Return value constants + +```perl6 + use IRC::Client::Plugin; + unit class IRC::Client::Plugin::Foo is IRC::Client::Plugin; + ... +``` + +To make the constants available in your class, simply `use` IRC::Client::Plugin +class. + +### `IRC_HANDLED` + +```perl6 + # Returned by default + method irc-ping ($irc, $e) { $irc.ssay("PONG {$irc.nick} $e[0]") } + + # Explicit return + method irc-privmsg ($irc, $e) { return IRC_HANDLED; } +``` +Specifies that plugin handled the message and the plugin chain processing +should stop immediatelly. Plugins later in the chain won't know this +message ever came. Unless you explicitly return +[`IRC_NOT_HANDLED`](#IRC_NOT_HANDLED) constant, IRC::Client will assume +`IRC_HANDLED` was returned. + +### `IRC_NOT_HANDLED` + +```perl6 + return IRC_NOT_HANDLED; +``` +Returning this constant indicates to IRC::Client that your plugin did +not "handle" the message and it should be propagated further down the +plugin chain for other plugins to handle. + + ```perl6 unit class IRC::Client::Plugin::Foo:ver<1.001001>; @@ -261,21 +342,6 @@ Sends a message to the server, automatically appending `\r\n`. Sends a `PRIVMSG` message specified in the second argument to the user/channel specified as the first argument. -## Included Plugins - -### `IRC::Client::Plugin::Debugger` - - plugins => [IRC::Client::Plugin::Debugger.new] - -Including this plugin will pretty-print parsed IRC messages on STDOUT. - -### `IRC::Client::Plugin::PingPong` - - plugins-essential => [IRC::Client::Plugin::PingPong.new] - -This plugin responds to server's `PING` requests and is automatically -included in the `plugins-essential` by default. - # REPOSITORY Fork this module on GitHub: -- 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(-) 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 --- DESIGN-NOTES.md | 2 + README.md | 117 ++++++++++++++++++++++--------------- examples/bot.pl6 | 2 +- lib/IRC/Client.pm6 | 16 ++--- lib/IRC/Client/Plugin/Debugger.pm6 | 2 +- 5 files changed, 83 insertions(+), 56 deletions(-) diff --git a/DESIGN-NOTES.md b/DESIGN-NOTES.md index 84b93a7..eaed28b 100644 --- a/DESIGN-NOTES.md +++ b/DESIGN-NOTES.md @@ -1,5 +1,7 @@ ## Just some notes jotted down while reading RFCs +This is only for my own use and is not meant to be of any use to anyone else. + #### RFC 1459 http://irchelp.org/irchelp/rfc/rfc.html diff --git a/README.md b/README.md index 5810376..67cb299 100644 --- a/README.md +++ b/README.md @@ -187,6 +187,27 @@ working order of any IRC client. **Defaults to:** Takes no arguments. Starts the IRC client. Exits when the connection to the IRC server ends. +# METHODS FOR PLUGINS + +You can make use of these `IRC::Client` methods in your plugins: + +## `.ssay` + +```perl6 + $irc.ssay("Foo bar!"); +``` +Sends a message to the server, automatically appending `\r\n`. Mnemonic: +**s**erver **say**. + + +## `.privmsg` + +```perl6 + $irc.privmsg( 'Zoffix', 'Hallo!' ); +``` +Sends a `PRIVMSG` message specified in the second argument +to the user/channel specified as the first argument. + # INCLUDED PLUGINS Currently, this distribution comes with two IRC Client plugins: @@ -260,7 +281,7 @@ class. Specifies that plugin handled the message and the plugin chain processing should stop immediatelly. Plugins later in the chain won't know this message ever came. Unless you explicitly return -[`IRC_NOT_HANDLED`](#IRC_NOT_HANDLED) constant, IRC::Client will assume +[`IRC_NOT_HANDLED`](#irc_not_handled) constant, IRC::Client will assume `IRC_HANDLED` was returned. ### `IRC_NOT_HANDLED` @@ -272,75 +293,79 @@ Returning this constant indicates to IRC::Client that your plugin did not "handle" the message and it should be propagated further down the plugin chain for other plugins to handle. +## Subscribing to IRC events +### Standard IRC commands ```perl6 - unit class IRC::Client::Plugin::Foo:ver<1.001001>; - - multi method msg () { True } - multi method msg ($irc, $msg) { - $irc.privmsg( Zoffix => Dump $msg, :indent(4) ); - } - - multi method interval () { 6 } - multi method interval ($irc) { - $irc.privmsg( - $irc.channels[0], "5 seconds passed. Time is now " ~ now - ); - } + method irc-privmsg ($irc, $e) { ... } + method irc-notice ($irc, $e) { ... } ``` +To subscribe to an IRC event, simply declare a method named `irc-COMMAND`, +where `COMMAND` is the IRC command you want to handle. The method takes +two positional arguments: an `IRC::Client` object and the parsed IRC +message. -Above is a sample plugin. You can choose to respond either to server -messages or do things at a specific interval. +You'll likely generate a response based on the content of the parsed message +and use one of the [METHODS FOR PLUGINS](#methods-for-plugins) to send that +response. -### Responding to server messages +## Special Events ```perl6 - multi method msg () { True } - multi method msg ($irc, $msg) { - $irc.privmsg( Zoffix => Dump $msg, :indent(4) ); - } + method irc-all-events ($irc, $e) { ... } + method irc-privmsg-me ($irc, $e) { ... } + method irc-notice-me ($irc, $e) { ... } + ... # all other handlers for standard IRC commands + method irc-unhandled ($irc, $e) { ... } ``` +In addition to the [standard IRC commands](#standard-irc-commands), you can +register several special cases. They're handled in the event chain in the order +shown above. That is, if a plugin returns [`IRC_HANDLED`](#irc_handled) after +processing, say, [`irc-all-events`](#irc-all-events) event, its +[`irc-notice-me`](#irc-notice-me) handler won't be triggered, even if it would +otherwise. -If your plugin can resond to server messages, declare two multi methods -`msg` as seen above. The one without parameters needs to return `True` -(or `False`, if your plugin does not respond to messages). The second -gets the `IRC::Client` object as the first argument and the parsed message -as the second argument. +The available special events are as follows: -### Acting in intervals +### `irc-all-events` ```perl6 - multi method interval () { 6 } - multi method interval ($irc) { - $irc.privmsg( - $irc.channels[0], "5 seconds passed. Time is now " ~ now - ); - } + method irc-all-events ($irc, $e) { ... } ``` -Your plugin can also repsond in intervals. Declare an `interval` multi -that takes no arguments and returns an interval in seconds that your -action should happen in (return `0` if your plugin does not handle intervals). -The other multi method `interval` takes the `IRC::Client` as the argument. +Triggered for all IRC commands received, regardless of their content. As this +method will be triggered before any others, you can use this to +pre-process the message, for example. ***WARNING:*** **since +[`IRC_HANDLED` constant](#irc_handled) is returned by default, if you do not +explicitly return [`IRC_NOT_HANDLED`](#irc_not_handled), your client will +stop handling ALL other messages +*** -## Methods for plugins +### `irc-privmsg-me` -You can make use of these `IRC::Client` methods in your plugins: +```perl6 + method irc-privmsg-me ($irc, $e) { ... } +``` +Triggered when the IRC `PRIVMSG` command is received, where the receipient +is the client (as opposed to some channel). -### `.ssay` +### `irc-notice-me` ```perl6 - $irc.ssay("Foo bar!"); + method irc-notice-me ($irc, $e) { ... } ``` -Sends a message to the server, automatically appending `\r\n`. +Triggered when the IRC `NOTICE` command is received, where the receipient +is the client (as opposed to some channel). -### `.privmsg` +### `irc-unhandled` ```perl6 - $irc.privmsg( Zoffix => "Hallo!" ); + method irc-unhandled ($irc, $e) { ... } ``` -Sends a `PRIVMSG` message specified in the second argument -to the user/channel specified as the first argument. + +This is the same as [`irc-all-events`](#irc-all-events), except it's triggered +**after** all other events were tried. This method can be used to catch +any unhandled events. # REPOSITORY diff --git a/examples/bot.pl6 b/examples/bot.pl6 index 20bcb39..76c9fbb 100644 --- a/examples/bot.pl6 +++ b/examples/bot.pl6 @@ -4,7 +4,7 @@ use IRC::Client; use IRC::Client::Plugin::Debugger; my $irc = IRC::Client.new( - :host('localhost'), + :host('10.10.11.12'), :debug, plugins => [ IRC::Client::Plugin::Debugger.new 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; } diff --git a/lib/IRC/Client/Plugin/Debugger.pm6 b/lib/IRC/Client/Plugin/Debugger.pm6 index 17cf697..131bb35 100644 --- a/lib/IRC/Client/Plugin/Debugger.pm6 +++ b/lib/IRC/Client/Plugin/Debugger.pm6 @@ -2,7 +2,7 @@ use Data::Dump; use IRC::Client::Plugin; unit class IRC::Client::Plugin::Debugger:ver<1.002001> is IRC::Client::Plugin; -method all-events ($irc, $e) { +method irc-all-events ($irc, $e) { say Dump $e, :indent(4); return 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(-) 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 af537ca94aa97565dea47c6fc3d176627e7ea4cc Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Mon, 21 Dec 2015 09:24:01 -0500 Subject: Moar docs --- README.md | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 114 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 67cb299..1b9fd84 100644 --- a/README.md +++ b/README.md @@ -300,11 +300,12 @@ plugin chain for other plugins to handle. ```perl6 method irc-privmsg ($irc, $e) { ... } method irc-notice ($irc, $e) { ... } + method irc-353 ($irc, $e) { ... } ``` -To subscribe to an IRC event, simply declare a method named `irc-COMMAND`, -where `COMMAND` is the IRC command you want to handle. The method takes -two positional arguments: an `IRC::Client` object and the parsed IRC -message. +To subscribe to an IRC event, simply declare a method named `irc-command`, +where `command` is the IRC command you want to handle, in **lower case**. +The method takes two positional arguments: an `IRC::Client` object and +the [parsed IRC message](#contents-of-the-parsed-irc-message). You'll likely generate a response based on the content of the parsed message and use one of the [METHODS FOR PLUGINS](#methods-for-plugins) to send that @@ -367,6 +368,115 @@ This is the same as [`irc-all-events`](#irc-all-events), except it's triggered **after** all other events were tried. This method can be used to catch any unhandled events. +## Contents of the parsed IRC message + +```perl6 + # method irc-366 ($irc, $e) { ... } + { + command => "366".Str, + params => [ + "Perl6IRC".Str, + "#perl6bot".Str, + "End of NAMES list".Str, + ], + pipe => { }, + who => { + host => "irc.example.net".Str, + }, + } + + # method irc-join ($irc, $e) { ... } + { + command => "JOIN".Str, + params => [ + "#perl6bot".Str, + ], + pipe => { }, + who => { + host => "localhost".Str, + nick => "ZoffixW".Str, + user => "~ZoffixW".Str, + }, + } + + # method irc-privmsg ($irc, $e) { ... } + { + command => "PRIVMSG".Str, + params => [ + "#perl6bot".Str, + "Perl6IRC, hello!".Str, + ], + pipe => { }, + who => { + host => "localhost".Str, + nick => "ZoffixW".Str, + user => "~ZoffixW".Str, + }, + } + + # method irc-notice-me ($irc, $e) { ... } + { + command => "NOTICE".Str, + params => [ + "Perl6IRC".Str, + "you there?".Str, + ], + pipe => { }, + who => { + host => "localhost".Str, + nick => "ZoffixW".Str, + user => "~ZoffixW".Str, + }, + } +``` + +The second argument to event handlers is the parsed IRC message that is a +hash with the following keys: + +### `command` + +```perl6 + command => "NOTICE".Str, +``` +Contains the IRC command this message represents. + +### `params` + +```perl6 + params => [ + "Perl6IRC".Str, + "you there?".Str, + ], +``` +Constains the array of parameters for the IRC command. + +### pipe + +```perl6 + pipe => { }, +``` +This is a special key that can be used for communication between plugins. +While any plugin can modify any key of the parsed command's hash, the provided +`pipe` hash is simply a means to provide some standard, agreed-upon name +of a key to pass information around. + +### who + +```perl6 + #fdss + who => { + host => "localhost".Str, + nick => "ZoffixW".Str, + user => "~ZoffixW".Str, + }, + + who => { + host => "irc.example.net".Str, + }, +``` +A hash containing information on who sent the message. Messages sent by the +server do not have `nick`/`user` keys specified. + # REPOSITORY Fork this module on GitHub: -- cgit v1.1 From 3730baef0b8beba8750fc37908eb404d6b7b08fa Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Mon, 21 Dec 2015 09:26:00 -0500 Subject: Mention bleed branch --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 1b9fd84..feeb982 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,13 @@ This modules lets you create in Perl 6. The plugin system lets you work on the behaviour, without worrying about IRC layer. +# BLEED BRANCH + +The master branch of this repository contains the latest working version +of the module. To get the bleeding-edge version, you can install from the +[bleed branch](https://github.com/zoffixznet/perl6-IRC-Client/tree/bleed), but +that code is not always guaranteed to be in working order. + # METHODS ## `new` -- cgit v1.1 From 92e69fbe171fea012c4e374d332768f1ef2f4173 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Mon, 21 Dec 2015 09:27:05 -0500 Subject: Add TOC --- README.md | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/README.md b/README.md index feeb982..809b418 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,56 @@ IRC::Client - Extendable Internet Relay Chat client ).run; ``` +# TABLE OF CONTENTS +- [NAME](#name) +- [SYNOPSIS](#synopsis) + - [Client script](#client-script) + - [Custom plugins](#custom-plugins) + - [Basic response to an IRC command:](#basic-response-to-an-irc-command) + - [More involved handling](#more-involved-handling) +- [DESCRIPTION](#description) +- [BLEED BRANCH](#bleed-branch) +- [METHODS](#methods) + - [`new`](#new) + - [`debug`](#debug) + - [`host`](#host) + - [`port`](#port) + - [`nick`](#nick) + - [`username`](#username) + - [`userhost`](#userhost) + - [`userreal`](#userreal) + - [`channels`](#channels) + - [`plugins`](#plugins) + - [`plugins-essential`](#plugins-essential) + - [`run`](#run) +- [METHODS FOR PLUGINS](#methods-for-plugins) + - [`.ssay`](#ssay) + - [`.privmsg`](#privmsg) +- [INCLUDED PLUGINS](#included-plugins) + - [IRC::Client::Plugin::Debugger](#ircclientplugindebugger) + - [IRC::Client::Plugin::PingPong](#ircclientpluginpingpong) +- [EXTENDING IRC::Client / WRITING YOUR OWN PLUGINS](#extending-ircclient--writing-your-own-plugins) + - [Overview of the plugin system](#overview-of-the-plugin-system) + - [Return value constants](#return-value-constants) + - [`IRC_HANDLED`](#irc_handled) + - [`IRC_NOT_HANDLED`](#irc_not_handled) + - [Subscribing to IRC events](#subscribing-to-irc-events) + - [Standard IRC commands](#standard-irc-commands) + - [Special Events](#special-events) + - [`irc-all-events`](#irc-all-events) + - [`irc-privmsg-me`](#irc-privmsg-me) + - [`irc-notice-me`](#irc-notice-me) + - [`irc-unhandled`](#irc-unhandled) + - [Contents of the parsed IRC message](#contents-of-the-parsed-irc-message) + - [`command`](#command) + - [`params`](#params) + - [pipe](#pipe) + - [who](#who) +- [REPOSITORY](#repository) +- [BUGS](#bugs) +- [AUTHOR](#author) +- [LICENSE](#license) + ## Custom plugins ### Basic response to an IRC command: -- cgit v1.1 From 90217bd857f1aed87e892921b7f8e5296086af40 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Mon, 21 Dec 2015 09:27:34 -0500 Subject: Formatting fixes --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 809b418..a61c5c9 100644 --- a/README.md +++ b/README.md @@ -62,8 +62,8 @@ IRC::Client - Extendable Internet Relay Chat client - [Contents of the parsed IRC message](#contents-of-the-parsed-irc-message) - [`command`](#command) - [`params`](#params) - - [pipe](#pipe) - - [who](#who) + - [`pipe`](#pipe) + - [`who`](#who) - [REPOSITORY](#repository) - [BUGS](#bugs) - [AUTHOR](#author) @@ -507,7 +507,7 @@ Contains the IRC command this message represents. ``` Constains the array of parameters for the IRC command. -### pipe +### `pipe` ```perl6 pipe => { }, @@ -517,7 +517,7 @@ While any plugin can modify any key of the parsed command's hash, the provided `pipe` hash is simply a means to provide some standard, agreed-upon name of a key to pass information around. -### who +### `who` ```perl6 #fdss -- cgit v1.1 From 90b0541926acb6ef39cb0ad5c854687662f32d0a Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Mon, 21 Dec 2015 09:28:29 -0500 Subject: Fix synopsis --- README.md | 86 +++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index a61c5c9..e32dec8 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,49 @@ IRC::Client - Extendable Internet Relay Chat client ).run; ``` +## Custom plugins + +### Basic response to an IRC command: + +The plugin chain handling the message will stop after this plugin. + +``` +unit class IRC::Client::Plugin::PingPong is IRC::Client::Plugin; +method irc-ping ($irc, $msg) { $irc.ssay("PONG {$irc.nick} $msg[0]") } +``` + +### More involved handling + +On startup, start sending message `I'm an annoying bot` to all channels +every five seconds. We also subscribe to all events and print some debugging +info. By returning a special constant, we tell other plugins to continue +processing the data. + +``` +use IRC::Client::Plugin; # import constants +unit class IRC::Client::Plugin::Debugger is IRC::Client::Plugin; + +method register($irc) { + Supply.interval( 5, 5 ).tap({ + $irc.privmsg($_, "I'm an annoying bot!") + for $irc.channels; + }) +} + +method all-events ($irc, $e) { + say "We've got a private message" + if $e eq 'PRIVMSG' and $e[0] eq $irc.nick; + + # Store arbitrary data in the `pipe` for other plugins to use + $e = True + if $e eq 'PRIVMSG'; + + say $e, :indent(4); + return IRC_NOT_HANDLED; +} + +``` + # TABLE OF CONTENTS - [NAME](#name) - [SYNOPSIS](#synopsis) @@ -69,49 +112,6 @@ IRC::Client - Extendable Internet Relay Chat client - [AUTHOR](#author) - [LICENSE](#license) -## Custom plugins - -### Basic response to an IRC command: - -The plugin chain handling the message will stop after this plugin. - -``` -unit class IRC::Client::Plugin::PingPong is IRC::Client::Plugin; -method irc-ping ($irc, $msg) { $irc.ssay("PONG {$irc.nick} $msg[0]") } -``` - -### More involved handling - -On startup, start sending message `I'm an annoying bot` to all channels -every five seconds. We also subscribe to all events and print some debugging -info. By returning a special constant, we tell other plugins to continue -processing the data. - -``` -use IRC::Client::Plugin; # import constants -unit class IRC::Client::Plugin::Debugger is IRC::Client::Plugin; - -method register($irc) { - Supply.interval( 5, 5 ).tap({ - $irc.privmsg($_, "I'm an annoying bot!") - for $irc.channels; - }) -} - -method all-events ($irc, $e) { - say "We've got a private message" - if $e eq 'PRIVMSG' and $e[0] eq $irc.nick; - - # Store arbitrary data in the `pipe` for other plugins to use - $e = True - if $e eq 'PRIVMSG'; - - say $e, :indent(4); - return IRC_NOT_HANDLED; -} - -``` - # DESCRIPTION ***Note: this is a preview dev release. Things might change and new things -- cgit v1.1 From 60ce4c8fab7770317de3ef83f87f0dba438777b3 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Mon, 21 Dec 2015 09:28:57 -0500 Subject: Indicate we"re running P6 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e32dec8..d99a834 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ IRC::Client - Extendable Internet Relay Chat client The plugin chain handling the message will stop after this plugin. -``` +```perl6 unit class IRC::Client::Plugin::PingPong is IRC::Client::Plugin; method irc-ping ($irc, $msg) { $irc.ssay("PONG {$irc.nick} $msg[0]") } ``` @@ -37,7 +37,7 @@ every five seconds. We also subscribe to all events and print some debugging info. By returning a special constant, we tell other plugins to continue processing the data. -``` +```perl6 use IRC::Client::Plugin; # import constants unit class IRC::Client::Plugin::Debugger is IRC::Client::Plugin; -- cgit v1.1 From b237e80bf44419a64d8ba43bf44e428563f2ac6e Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Mon, 21 Dec 2015 09:31:27 -0500 Subject: add Author name --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d99a834..78d3a7e 100644 --- a/README.md +++ b/README.md @@ -546,7 +546,7 @@ https://github.com/zoffixznet/perl6-IRC-Client/issues # AUTHOR -http://zoffix.com/ +Zoffix Znet (http://zoffix.com/) # LICENSE -- 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 --- README.md | 34 +++++++++++++++++++++++++++++++--- lib/IRC/Client.pm6 | 4 +++- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 78d3a7e..37840c9 100644 --- a/README.md +++ b/README.md @@ -371,6 +371,9 @@ response. ## Special Events ```perl6 + method irc-start-up ($irc) { ... } # once per client run + method irc-connected ($irc) { ... } # once per server connection + method irc-all-events ($irc, $e) { ... } method irc-privmsg-me ($irc, $e) { ... } method irc-notice-me ($irc, $e) { ... } @@ -379,13 +382,38 @@ response. ``` In addition to the [standard IRC commands](#standard-irc-commands), you can register several special cases. They're handled in the event chain in the order -shown above. That is, if a plugin returns [`IRC_HANDLED`](#irc_handled) after +shown above (except for [`irc-start-up`](#irc-start-up) and +[`irc-connected`](#irc-connected) that do not offect command-triggered events). +That is, if a plugin returns [`IRC_HANDLED`](#irc_handled) after processing, say, [`irc-all-events`](#irc-all-events) event, its [`irc-notice-me`](#irc-notice-me) handler won't be triggered, even if it would otherwise. The available special events are as follows: +### `irc-start-up` + +```perl6 + method irc-start-up ($irc) { ... } +``` +Passed IRC::Client object as the only argument. Triggered right when the +IRC::Client is [`.run`](#run), which means most of +[METHODS FOR PLUGINS](#methods-for-plugins) **cannot** be used, as no connection +has been made yet. This event will be issued only once per [`.run`](#run) +and the method's return value is discarded. + +### `irc-connected` + +```perl6 + method irc-connected ($irc) { ... } +``` +Passed IRC::Client object as the only argument. Triggered right when we +get a connection to the server, identify with it and issue `JOIN` commands +to enter the channels. Note that at this point it is not guaranteed that the +client is already in all the channels it's meant to join. +This event will be issued only once per connection to the server +and the method's return value is discarded. + ### `irc-all-events` ```perl6 @@ -404,7 +432,7 @@ stop handling ALL other messages ```perl6 method irc-privmsg-me ($irc, $e) { ... } ``` -Triggered when the IRC `PRIVMSG` command is received, where the receipient +Triggered when the IRC `PRIVMSG` command is received, where the recipient is the client (as opposed to some channel). ### `irc-notice-me` @@ -412,7 +440,7 @@ is the client (as opposed to some channel). ```perl6 method irc-notice-me ($irc, $e) { ... } ``` -Triggered when the IRC `NOTICE` command is received, where the receipient +Triggered when the IRC `NOTICE` command is received, where the recipient is the client (as opposed to some channel). ### `irc-unhandled` 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 ebb509e5b106fdf24640b11f32e776f033a314e8 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Mon, 21 Dec 2015 09:45:27 -0500 Subject: Update TOC --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 37840c9..75fd4ce 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ method all-events ($irc, $e) { - [Custom plugins](#custom-plugins) - [Basic response to an IRC command:](#basic-response-to-an-irc-command) - [More involved handling](#more-involved-handling) +- [TABLE OF CONTENTS](#table-of-contents) - [DESCRIPTION](#description) - [BLEED BRANCH](#bleed-branch) - [METHODS](#methods) @@ -98,6 +99,8 @@ method all-events ($irc, $e) { - [Subscribing to IRC events](#subscribing-to-irc-events) - [Standard IRC commands](#standard-irc-commands) - [Special Events](#special-events) + - [`irc-start-up`](#irc-start-up) + - [`irc-connected`](#irc-connected) - [`irc-all-events`](#irc-all-events) - [`irc-privmsg-me`](#irc-privmsg-me) - [`irc-notice-me`](#irc-notice-me) -- cgit v1.1 From 3ef85d79fec87c063aeb00a605fd8d40d2ec5cb4 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Mon, 21 Dec 2015 09:48:38 -0500 Subject: Use a better example --- README.md | 7 ++++--- examples/bot.pl6 | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 75fd4ce..77ab9d5 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,10 @@ IRC::Client - Extendable Internet Relay Chat client use IRC::Client::Plugin::Debugger; IRC::Client.new( - :host('localhost'), - :debug, - plugins => [ IRC::Client::Plugin::Debugger.new ] + :host('localhost') + :channels<#perl6bot #zofbot> + :debug + :plugins( IRC::Client::Plugin::Debugger.new ) ).run; ``` diff --git a/examples/bot.pl6 b/examples/bot.pl6 index 76c9fbb..b5adb16 100644 --- a/examples/bot.pl6 +++ b/examples/bot.pl6 @@ -5,6 +5,7 @@ use IRC::Client::Plugin::Debugger; my $irc = IRC::Client.new( :host('10.10.11.12'), + :channels<#perl6bot #zofbot> :debug, plugins => [ IRC::Client::Plugin::Debugger.new -- cgit v1.1 From ebdb216d4d47e1ab061e3719fe3af01856d2486f Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Mon, 21 Dec 2015 09:53:40 -0500 Subject: Use a more idomatic example --- README.md | 2 +- examples/bot.pl6 | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 77ab9d5..328bfe1 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ IRC::Client - Extendable Internet Relay Chat client use IRC::Client::Plugin::Debugger; IRC::Client.new( - :host('localhost') + :host :channels<#perl6bot #zofbot> :debug :plugins( IRC::Client::Plugin::Debugger.new ) diff --git a/examples/bot.pl6 b/examples/bot.pl6 index b5adb16..34528c7 100644 --- a/examples/bot.pl6 +++ b/examples/bot.pl6 @@ -4,10 +4,8 @@ use IRC::Client; use IRC::Client::Plugin::Debugger; my $irc = IRC::Client.new( - :host('10.10.11.12'), + :host :channels<#perl6bot #zofbot> - :debug, - plugins => [ - IRC::Client::Plugin::Debugger.new - ] + :debug + :plugins( IRC::Client::Plugin::Debugger.new ) ).run; -- 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 --- Changes | 8 ++++---- lib/IRC/Client.pm6 | 2 +- lib/IRC/Client/Plugin.pm6 | 3 +-- lib/IRC/Client/Plugin/Debugger.pm6 | 2 +- lib/IRC/Client/Plugin/PingPong.pm6 | 2 +- lib/IRC/Grammar.pm6 | 2 +- lib/IRC/Grammar/Actions.pm6 | 2 +- lib/IRC/Parser.pm6 | 2 +- 8 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Changes b/Changes index e04841e..0ac6bda 100644 --- a/Changes +++ b/Changes @@ -1,12 +1,12 @@ Revision History for 'IRC::Client' Perl 6 Distribution -1.002001 Unreleased +2.001001 2015-12-21 [Redesign plugin system] - each IRC command can now be implemented with a specific method of - name 'irc_COMMAND' + name 'irc-command' - Added individual privmsg-me and notice-me methods - - Removed `interval` plugin methods. - - Added `register` plugin method that is called during client start up + - Removed `interval` and `msg` plugin methods. + - Added `irc-start-up` and `irc-connected` plugin methods [Other] - Improved debug output 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; diff --git a/lib/IRC/Client/Plugin.pm6 b/lib/IRC/Client/Plugin.pm6 index 55db82c..83703d7 100644 --- a/lib/IRC/Client/Plugin.pm6 +++ b/lib/IRC/Client/Plugin.pm6 @@ -1,4 +1,3 @@ constant IRC_HANDLED = "irc plugin handled \x1"; constant IRC_NOT_HANDLED = "irc plugin not-handled \x2"; -unit class IRC::Client::Plugin:ver<1.002002>; - +unit class IRC::Client::Plugin:ver<2.001001>; diff --git a/lib/IRC/Client/Plugin/Debugger.pm6 b/lib/IRC/Client/Plugin/Debugger.pm6 index 131bb35..c959cc2 100644 --- a/lib/IRC/Client/Plugin/Debugger.pm6 +++ b/lib/IRC/Client/Plugin/Debugger.pm6 @@ -1,6 +1,6 @@ use Data::Dump; use IRC::Client::Plugin; -unit class IRC::Client::Plugin::Debugger:ver<1.002001> is IRC::Client::Plugin; +unit class IRC::Client::Plugin::Debugger:ver<2.001001> is IRC::Client::Plugin; method irc-all-events ($irc, $e) { say Dump $e, :indent(4); diff --git a/lib/IRC/Client/Plugin/PingPong.pm6 b/lib/IRC/Client/Plugin/PingPong.pm6 index d6b8f28..b499051 100644 --- a/lib/IRC/Client/Plugin/PingPong.pm6 +++ b/lib/IRC/Client/Plugin/PingPong.pm6 @@ -1,2 +1,2 @@ -unit class IRC::Client::Plugin::PingPong:ver<1.002001>; +unit class IRC::Client::Plugin::PingPong:ver<2.001001>; method irc-ping ($irc, $e) { $irc.ssay("PONG {$irc.nick} $e[0]") } diff --git a/lib/IRC/Grammar.pm6 b/lib/IRC/Grammar.pm6 index d26a3dc..241c497 100644 --- a/lib/IRC/Grammar.pm6 +++ b/lib/IRC/Grammar.pm6 @@ -1,4 +1,4 @@ -unit grammar IRC::Grammar:ver<1.001001>; +unit grammar IRC::Grammar:ver<2.001001>; token TOP { + } token SPACE { ' '+ } token message { [':' ]? \n } diff --git a/lib/IRC/Grammar/Actions.pm6 b/lib/IRC/Grammar/Actions.pm6 index 74a8f11..469f8f8 100644 --- a/lib/IRC/Grammar/Actions.pm6 +++ b/lib/IRC/Grammar/Actions.pm6 @@ -1,4 +1,4 @@ -unit class IRC::Grammar::Actions:ver<1.001001>; +unit class IRC::Grammar::Actions:ver<2.001001>; method TOP ($/) { $/.make: $>>.made } method message ($/) { my $pref = $/; diff --git a/lib/IRC/Parser.pm6 b/lib/IRC/Parser.pm6 index aa87fa7..77de768 100644 --- a/lib/IRC/Parser.pm6 +++ b/lib/IRC/Parser.pm6 @@ -1,6 +1,6 @@ use IRC::Grammar; use IRC::Grammar::Actions; -unit class IRC::Parser:ver<1.001001>; +unit class IRC::Parser:ver<2.001001>; sub parse-irc (Str:D $input) is export { IRC::Grammar.parse($input, actions => IRC::Grammar::Actions).made // []; -- cgit v1.1