aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md22
-rw-r--r--lib/IRC/Client.pm613
2 files changed, 25 insertions, 10 deletions
diff --git a/README.md b/README.md
index 616246d..4c4df78 100644
--- a/README.md
+++ b/README.md
@@ -511,19 +511,27 @@ stop handling ALL other messages
### `irc-to-me`
```perl6
- method irc-to-me ($irc, $e, $where, $who) {
- $irc.privmsg: $where, "$who, you talkin' to me?";
+ method irc-to-me ($irc, $e, %res) {
+ $irc.respond: |%res, :what("You told me: %res<what>");
}
```
Triggered when: the IRC `PRIVMSG` command is received, where the recipient
is the client (as opposed to some channel); the `NOTICE` command is
received, or the `PRIVMSG` command is received, where the recipient is the
channel and the message begins with client's nickname (i.e. the client
-was addressed in channel. Along with `IRC::Client` object and the event
-hash contained in `$e`, this method also receives two additional positional
-arguments: `$where`, which is where to send the response (will be the channel
-name or the name of the user who sent the message); and `$who`, which is the
-nickname of the user who sent the message.
+was addressed in channel.
+
+Along with `IRC::Client` object and the event
+hash contained in `$e`, this method also receives an additional positional
+argument that is a hash containing the correct `$where`, `$who`, `$how`, and
+`$what` arguments to generate a response using [`.respond method`](#respond).
+You'll likely want to change the `$what` argument. You can do that by
+specifying `:what('...')` after slipping the `|%res`, as shown in the example
+above.
+
+Also, note: the supplied `$what` argument will have the client's
+nickname removed from it. Use the params in `$e` if you want the exact message
+that was said.
### `irc-privmsg-me`
diff --git a/lib/IRC/Client.pm6 b/lib/IRC/Client.pm6
index 63a7e98..98c57ed 100644
--- a/lib/IRC/Client.pm6
+++ b/lib/IRC/Client.pm6
@@ -35,13 +35,20 @@ method handle-event ($e) {
and $e<params>[1] ~~ /:i ^ $nick <[,:]> \s+/
)
) {
- my @where = ($e<who><nick>, $e<who><nick>);
- @where[0] = $e<params>[0]
+ my %res = :where($e<who><nick> ),
+ :who( $e<who><nick> ),
+ :how( $e<command> ),
+ :what( $e<params>[1] );
+
+ %res<where> = $e<params>[0] # this message was said in the channel
unless ( $e<command> eq 'PRIVMSG' and $e<params>[0] eq $nick )
or ( $e<command> eq 'NOTICE' and $e<params>[0] eq $nick );
+ %res<what>.subst-mutate: /:i ^ $nick <[,:]> \s+/, ''
+ if %res<where> ~~ /^ <[#&]>/;
+
for @!plugs.grep(*.^can: 'irc-to-me') -> $p {
- my $res = $p.irc-to-me(self, $e, |@where);
+ my $res = $p.irc-to-me(self, $e, %res);
return unless $res === IRC_NOT_HANDLED;
}
}