aboutsummaryrefslogtreecommitdiff
path: root/examples/08-numeric-bot.p6
diff options
context:
space:
mode:
authorZoffix Znet <cpan@zoffix.com>2016-10-15 14:45:23 -0400
committerZoffix Znet <cpan@zoffix.com>2016-10-15 14:45:23 -0400
commit4411e6f5498beec81c95eb9810c37cd7ab56a0db (patch)
treeac86576b4d0b80e3a7df4faa1507a55fb5b88fa2 /examples/08-numeric-bot.p6
parentacd52a7219f7518355fe8e1216ea5faf3ff18bf7 (diff)
Fix numeric events being unsubscrabable due to incorrect identifiers
Fixes #31
Diffstat (limited to 'examples/08-numeric-bot.p6')
-rw-r--r--examples/08-numeric-bot.p632
1 files changed, 32 insertions, 0 deletions
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)