aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZoffix Znet <zoffixznet@users.noreply.github.com>2015-12-21 09:52:42 -0500
committerZoffix Znet <zoffixznet@users.noreply.github.com>2015-12-21 09:52:42 -0500
commit3be97d3be43be4a40737fa21c033763b29361bea (patch)
tree5ba5df3fcbeb2f640f2dcc9373f2a730a0f80fdc
parentb8035c1c7840ecb3f6ee2fd46560f41589d846aa (diff)
parentc525790efcc8f1b45c3d236a08da1f8ed122fc9b (diff)
Merge pull request #2 from zoffixznet/bleed
Bleed v 2.001001
-rw-r--r--Changes10
-rw-r--r--DESIGN-NOTES.md2
-rw-r--r--META.info2
-rw-r--r--README.md449
-rw-r--r--examples/bot.pl69
-rw-r--r--lib/IRC/Client.pm668
-rw-r--r--lib/IRC/Client/Plugin.pm63
-rw-r--r--lib/IRC/Client/Plugin/Debugger.pm610
-rw-r--r--lib/IRC/Client/Plugin/PingPong.pm612
-rw-r--r--lib/IRC/Grammar.pm62
-rw-r--r--lib/IRC/Grammar/Actions.pm62
-rw-r--r--lib/IRC/Parser.pm62
12 files changed, 479 insertions, 92 deletions
diff --git a/Changes b/Changes
index 2ea7f5e..0ac6bda 100644
--- a/Changes
+++ b/Changes
@@ -1,4 +1,14 @@
Revision History for 'IRC::Client' Perl 6 Distribution
+2.001001 2015-12-21
+ [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` and `msg` plugin methods.
+ - Added `irc-start-up` and `irc-connected` plugin methods
+ [Other]
+ - Improved debug output
+
1.001001 2015-11-19
- First version released on an unsuspecting world
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/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/README.md b/README.md
index b2bcad9..328bfe1 100644
--- a/README.md
+++ b/README.md
@@ -6,17 +6,116 @@ IRC::Client - Extendable Internet Relay Chat client
# SYNOPSIS
+## Client script
+
```perl6
use IRC::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;
```
+## Custom plugins
+
+### Basic response to an IRC command:
+
+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<params>[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.
+
+```perl6
+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<command> eq 'PRIVMSG' and $e<params>[0] eq $irc.nick;
+
+ # Store arbitrary data in the `pipe` for other plugins to use
+ $e<pipe><respond-to-notice> = True
+ if $e<command> eq 'PRIVMSG';
+
+ say $e, :indent(4);
+ return IRC_NOT_HANDLED;
+}
+
+```
+
+# 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)
+- [TABLE OF CONTENTS](#table-of-contents)
+- [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-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)
+ - [`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)
+
# DESCRIPTION
***Note: this is a preview dev release. Things might change and new things
@@ -28,6 +127,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`
@@ -142,94 +248,323 @@ 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
+# 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:
-## Writing your own
+## IRC::Client::Plugin::Debugger
```perl6
- unit class IRC::Client::Plugin::Foo:ver<1.001001>;
+ use IRC::Client;
+ use IRC::Client::Plugin::Debugger;
- multi method msg () { True }
- multi method msg ($irc, $msg) {
- $irc.privmsg( Zoffix => Dump $msg, :indent(4) );
- }
+ IRC::Client.new(
+ :host('localhost'),
+ :debug,
+ plugins => [ IRC::Client::Plugin::Debugger.new ]
+ ).run;
+```
- multi method interval () { 6 }
- multi method interval ($irc) {
- $irc.privmsg(
- $irc.channels[0], "5 seconds passed. Time is now " ~ now
- );
- }
+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
```
-Above is a sample plugin. You can choose to respond either to server
-messages or do things at a specific interval.
+This plugin makes IRC::Client respond to server's C<PING> 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.
-### Responding to server messages
+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
- multi method msg () { True }
- multi method msg ($irc, $msg) {
- $irc.privmsg( Zoffix => Dump $msg, :indent(4) );
- }
+ use IRC::Client::Plugin;
+ unit class IRC::Client::Plugin::Foo is IRC::Client::Plugin;
+ ...
```
-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.
+To make the constants available in your class, simply `use` IRC::Client::Plugin
+class.
-### Acting in intervals
+### `IRC_HANDLED`
```perl6
- multi method interval () { 6 }
- multi method interval ($irc) {
- $irc.privmsg(
- $irc.channels[0], "5 seconds passed. Time is now " ~ now
- );
- }
+ # Returned by default
+ method irc-ping ($irc, $e) { $irc.ssay("PONG {$irc.nick} $e<params>[0]") }
+
+ # Explicit return
+ method irc-privmsg ($irc, $e) { return IRC_HANDLED; }
```
-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.
+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.
-## Methods for plugins
+### `IRC_NOT_HANDLED`
-You can make use of these `IRC::Client` methods in your plugins:
+```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.
+
+## Subscribing to IRC events
-### `.ssay`
+### Standard IRC commands
```perl6
- $irc.ssay("Foo bar!");
+ method irc-privmsg ($irc, $e) { ... }
+ method irc-notice ($irc, $e) { ... }
+ method irc-353 ($irc, $e) { ... }
```
-Sends a message to the server, automatically appending `\r\n`.
+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
+response.
-### `.privmsg`
+## Special Events
```perl6
- $irc.privmsg( Zoffix => "Hallo!" );
+ 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) { ... }
+ ... # all other handlers for standard IRC commands
+ method irc-unhandled ($irc, $e) { ... }
```
-Sends a `PRIVMSG` message specified in the second argument
-to the user/channel specified as the first argument.
+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 (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.
-## Included Plugins
+The available special events are as follows:
-### `IRC::Client::Plugin::Debugger`
+### `irc-start-up`
- plugins => [IRC::Client::Plugin::Debugger.new]
+```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.
-Including this plugin will pretty-print parsed IRC messages on STDOUT.
+### `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::Client::Plugin::PingPong`
+### `irc-all-events`
- plugins-essential => [IRC::Client::Plugin::PingPong.new]
+```perl6
+ method irc-all-events ($irc, $e) { ... }
+```
+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
+***
+
+### `irc-privmsg-me`
+
+```perl6
+ method irc-privmsg-me ($irc, $e) { ... }
+```
+Triggered when the IRC `PRIVMSG` command is received, where the recipient
+is the client (as opposed to some channel).
+
+### `irc-notice-me`
+
+```perl6
+ method irc-notice-me ($irc, $e) { ... }
+```
+Triggered when the IRC `NOTICE` command is received, where the recipient
+is the client (as opposed to some channel).
+
+### `irc-unhandled`
+
+```perl6
+ method irc-unhandled ($irc, $e) { ... }
+```
-This plugin responds to server's `PING` requests and is automatically
-included in the `plugins-essential` by default.
+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
@@ -243,7 +578,7 @@ https://github.com/zoffixznet/perl6-IRC-Client/issues
# AUTHOR
-http://zoffix.com/
+Zoffix Znet (http://zoffix.com/)
# LICENSE
diff --git a/examples/bot.pl6 b/examples/bot.pl6
index 20bcb39..34528c7 100644
--- a/examples/bot.pl6
+++ b/examples/bot.pl6
@@ -4,9 +4,8 @@ use IRC::Client;
use IRC::Client::Plugin::Debugger;
my $irc = 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/lib/IRC/Client.pm6 b/lib/IRC/Client.pm6
index 55d4262..65f80e7 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<2.001001> {
has Bool:D $.debug = False;
has Str:D $.host = 'localhost';
has Int:D $.port where 0 <= $_ <= 65535 = 6667;
@@ -16,24 +16,59 @@ class IRC::Client:ver<1.001001> {
has @.plugins-essential = [
IRC::Client::Plugin::PingPong.new
];
+ 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;
- Supply.interval( .interval ).tap({ $OUTER::_.interval(self) })
- for @!plugins.grep(*.interval);
+ .irc-connected: self for @!plugs.grep(*.^can: 'irc-connected');
react {
whenever $!sock.Supply -> $str is copy {
- $!debug and $str.say;
- my $messages = parse-irc $str;
- for @$messages -> $message {
- .msg(self, $message)
- for (@!plugins-essential, @!plugins).flat.grep(*.msg);
+ $!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;
+ }
}
}
}
@@ -44,14 +79,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] ";
+}
diff --git a/lib/IRC/Client/Plugin.pm6 b/lib/IRC/Client/Plugin.pm6
new file mode 100644
index 0000000..83703d7
--- /dev/null
+++ b/lib/IRC/Client/Plugin.pm6
@@ -0,0 +1,3 @@
+constant IRC_HANDLED = "irc plugin handled \x1";
+constant IRC_NOT_HANDLED = "irc plugin not-handled \x2";
+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 5966ca0..c959cc2 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<2.001001> is IRC::Client::Plugin;
-multi method msg () { True }
-multi method msg ($irc, $msg) {
- say Dump $msg, :indent(4);
+method irc-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 7ba977d..b499051 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<command> eq 'PING';
- my $res = "PONG {$irc.nick} $msg<params>[0]";
- $irc.debug and say $res;
- $irc.ssay($res);
-}
+unit class IRC::Client::Plugin::PingPong:ver<2.001001>;
+method irc-ping ($irc, $e) { $irc.ssay("PONG {$irc.nick} $e<params>[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 { <message>+ }
token SPACE { ' '+ }
token message { [':' <prefix> <SPACE> ]? <command> <params> \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: $<message>>>.made }
method message ($/) {
my $pref = $/<prefix>;
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 // [];