aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/02-event-reference.md18
-rw-r--r--examples/08-numeric-bot.p632
-rw-r--r--lib/IRC/Client.pm65
3 files changed, 45 insertions, 10 deletions
diff --git a/docs/02-event-reference.md b/docs/02-event-reference.md
index a2c6fdd..fdf9d0a 100644
--- a/docs/02-event-reference.md
+++ b/docs/02-event-reference.md
@@ -28,7 +28,7 @@
- [`irc-started`](#irc-started)
- [`irc-to-me`](#irc-to-me)
- [`irc-unknown`](#irc-unknown)
- - [`irc-XXX`](#irc-xxx)
+ - [`irc-nXXX`](#irc-nXXX)
- [Up Next](#up-next)
---
@@ -61,7 +61,7 @@ that the returned value from the event handler should be discarded.
## Event Map
-In the chart below, `irc-XXX` stands for numeric events where `XXX` is a
+In the chart below, `irc-nXXX` stands for numeric events where `XXX` is a
three-digit number. See [this numerics
table](https://www.alien.net.au/irc/irc2numerics.html) for meaning of codes,
depending on the server used.
@@ -80,8 +80,8 @@ irc-addressed â–¶ irc-to-me â–¶ irc-notice-channel â–¶ irc-notice â
irc-mode-channel â–¶ irc-mode â–¶ irc-all
irc-mode-me â–¶ irc-mode â–¶ irc-all
- irc-connected â–¶ irc-XXX â–¶ irc-numeric â–¶ irc-all
- irc-XXX â–¶ irc-numeric â–¶ irc-all
+ irc-connected â–¶ irc-nXXX â–¶ irc-numeric â–¶ irc-all
+ irc-nXXX â–¶ irc-numeric â–¶ irc-all
irc-join â–¶ irc-all
irc-nick â–¶ irc-all
irc-part â–¶ irc-all
@@ -141,7 +141,7 @@ Possible message objects received by event handler:
### `irc-connected`
```
-irc-connected â–¶ irc-001 â–¶ irc-numeric â–¶ irc-all
+irc-connected â–¶ irc-n001 â–¶ irc-numeric â–¶ irc-all
```
Triggered on `001` numeric IRC command that indicates we successfully
@@ -256,7 +256,7 @@ Receives `IRC::Client::Message::Notice::Me` message object.
### `irc-numeric`
```
-irc-numeric â–¶ irc-XXX â–¶ irc-all
+irc-numeric â–¶ irc-nXXX â–¶ irc-all
```
Triggered on numeric IRC commands.
@@ -367,14 +367,14 @@ if possible.
Receives `IRC::Client::Message::Unknown` message object.
-### `irc-XXX`
+### `irc-nXXX`
**Note:*** `XXX` stands for a three-digit numeric code of the command that
-triggered the event, for example `irc-001`. See `irc-numeric` for event trigger
+triggered the event, for example `irc-n001`. See `irc-numeric` for event trigger
that responds to all numerics.
```
-irc-XXX â–¶ irc-numeric â–¶ irc-all
+irc-nXXX â–¶ irc-numeric â–¶ irc-all
```
Triggered on numeric IRC commands.
diff --git a/examples/08-numeric-bot.p6 b/examples/08-numeric-bot.p6
new file mode 100644
index 0000000..c8edac9
--- /dev/null
+++ b/examples/08-numeric-bot.p6
@@ -0,0 +1,32 @@
+use lib <lib>;
+use IRC::Client;
+
+.run with IRC::Client.new:
+ :nick<MahBot>
+ :host(%*ENV<IRC_CLIENT_HOST> // 'irc.freenode.net')
+ :channels<#zofbot>
+ :2debug
+ :plugins(class :: does IRC::Client::Plugin {
+ my class NameLookup { has $.channel; has @.users; has $.e; }
+ has %.lookups of NameLookup;
+
+ method irc-to-me ($e where /^ 'users in ' $<channel>=\S+/) {
+ my $channel = ~$<channel>;
+ return 'Look up of this channel is already in progress'
+ if %!lookups{$channel};
+
+ %!lookups{$channel} = NameLookup.new: :$channel :$e;
+ $.irc.send-cmd: 'NAMES', $channel;
+ Nil;
+ }
+ method irc-n353 ($e where so %!lookups{ $e.args[2] }) {
+ %!lookups{ $e.args[2] }.users.append: $e.args[3].words;
+ Nil;
+ }
+ method irc-n366 ($e where so %!lookups{ $e.args[1] }) {
+ my $lookup = %!lookups{ $e.args[1] }:delete;
+ $lookup.e.reply: "Users in $lookup.channel(): $lookup.users()[]";
+ Nil;
+ }
+
+ }.new)
diff --git a/lib/IRC/Client.pm6 b/lib/IRC/Client.pm6
index 3879ac9..e5696b4 100644
--- a/lib/IRC/Client.pm6
+++ b/lib/IRC/Client.pm6
@@ -267,7 +267,10 @@ method !handle-event ($e) {
$s.is-connected = True;
take 'irc-connected';
}
- take 'irc-' ~ $e.command, $event-name;
+
+ # prefix numerics with 'n' as irc-\d+ isn't a valid identifier
+ take 'irc-' ~ ('n' if $e ~~ IRC::Client::Message::Numeric)
+ ~ $e.command, $event-name;
}
default { take $event-name }
}