[t/spec] Add tricky tests (which pass after latest Rakudo patch), unfudge old simple...
[pugs.git] / examples / network / bot_irc.pl
blob00f4513bd545dd3f5c9b6f9be054412ae43e193a
1 use v6;
3 # version 0.1, michael scherer, misc@zarb.org
4 # some additions by:
5 # stevan little <stevan@iinteractive.com>
6 # Luke Palmer
7 # the first perl6 irc bot ( or at least, what i hope to be the first ).
9 say "A irc perl 6 bot";
11 my $nick = @*ARGS[0] // "didie_p6";
12 my $server = "irc.freenode.net";
13 my $chan = "#perl6";
14 my $debug;
16 my $hdl = connect($server, 6667);
17 # no auto flush yet
18 #$hdl.autoflush(1);
20 $hdl.say("NICK $nick\nUSER $nick $nick $nick $nick\n");
21 $hdl.flush;
23 # first line is not so important, it can be discarded ( or i hope )
24 my $ligne = $hdl.get;
26 $hdl.say("JOIN $chan\n");
27 $hdl.flush;
29 say "Joined $chan";
31 while $ligne = $hdl.get {
32 say "Serveur said : $ligne"; # if $debug;
34 given $ligne {
36 when rx:P5/^PING/ {
37 say "Reply to ping";
38 $hdl.say("PONG $nick\n");
39 $hdl.flush;
42 when rx:P5/$nick/
43 && rx:P5/^\:(.*?)\!.*?\sPRIVMSG $chan/ {
44 my $writer = $0;
45 given $ligne {
46 when rx:P5/\b(?i:hello|hi)\b/ {
47 $hdl.say("PRIVMSG $chan :Hello $writer from a perl 6 irc bot\n");
48 $hdl.flush;