aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md89
-rw-r--r--lib/IRC/Client.pm64
-rw-r--r--lib/IRC/Client/Plugin/Debugger.pm67
3 files changed, 91 insertions, 9 deletions
diff --git a/README.md b/README.md
index 298b2f3..c7636e4 100644
--- a/README.md
+++ b/README.md
@@ -142,6 +142,95 @@ 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
+
+Currently, this distribution comes with two IRC Client plugins:
+
+## Writing your own
+
+```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
+ );
+ }
+```
+
+Above is a sample plugin. You can choose to respond either to server
+messages or do things at a specific interval.
+
+### Responding to server messages
+
+```perl6
+ multi method msg () { True }
+ multi method msg ($irc, $msg) {
+ $irc.privmsg( Zoffix => Dump $msg, :indent(4) );
+ }
+```
+
+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.
+
+### Acting in intervals
+
+```perl6
+ multi method interval () { 6 }
+ multi method interval ($irc) {
+ $irc.privmsg(
+ $irc.channels[0], "5 seconds passed. Time is now " ~ now
+ );
+ }
+```
+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.
+
+## 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`.
+
+### `.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
+
+### `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:
diff --git a/lib/IRC/Client.pm6 b/lib/IRC/Client.pm6
index a27c18d..55d4262 100644
--- a/lib/IRC/Client.pm6
+++ b/lib/IRC/Client.pm6
@@ -24,8 +24,8 @@ 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);
+ Supply.interval( .interval ).tap({ $OUTER::_.interval(self) })
+ for @!plugins.grep(*.interval);
react {
whenever $!sock.Supply -> $str is copy {
diff --git a/lib/IRC/Client/Plugin/Debugger.pm6 b/lib/IRC/Client/Plugin/Debugger.pm6
index dabb353..5966ca0 100644
--- a/lib/IRC/Client/Plugin/Debugger.pm6
+++ b/lib/IRC/Client/Plugin/Debugger.pm6
@@ -6,10 +6,3 @@ multi method msg () { True }
multi method msg ($irc, $msg) {
say Dump $msg, :indent(4);
}
-
-multi method interval ( ) { 6 }
-multi method interval ($irc) {
- $irc.privmsg(
- $irc.channels[0], "5 seconds passed. Time is now " ~ now
- );
-}