diff options
author | Zoffix Znet <cpan@zoffix.com> | 2015-11-25 13:32:59 -0500 |
---|---|---|
committer | Zoffix Znet <cpan@zoffix.com> | 2015-11-25 13:32:59 -0500 |
commit | ef0a9de8eb4a8c1bf3e82d18b1dadd54637a7c98 (patch) | |
tree | 0ff052a924543e0e1bd29465de865e0593ac006f /lib/IRC/Client.pm6 | |
parent | abc2ced0696edd2c8beba2eacd6c65d7854ac417 (diff) |
Intermediary
Diffstat (limited to 'lib/IRC/Client.pm6')
-rw-r--r-- | lib/IRC/Client.pm6 | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/lib/IRC/Client.pm6 b/lib/IRC/Client.pm6 index ff0243a..d4a00ca 100644 --- a/lib/IRC/Client.pm6 +++ b/lib/IRC/Client.pm6 @@ -1,2 +1,42 @@ use v6; -unit package IRC::Client:version<1.001001>; +class IRC::Client::Plugin { ... } +class IRC::Client:ver<1.001001> { + + has Str $.host = 'localhost'; + has Int $.port where 0 <= $_ <= 65535 = 6667; + has Str $.nick where 1 <= .chars <= 9 = 'Perl6IRC'; + has Str $.username = 'Perl6IRC'; + has Str $.userhost = 'localhost'; + has Str $.userreal = 'Perl6 IRC Client'; + has Str @.channels = ['#perl6bot']; + has IO::Socket::Async $.sock; + has IRC::Client::Plugin @.plugins = []; + + method run { + await IO::Socket::Async.connect( $!host, $!port ).then({ + $!sock = .result; + $.ssay("NICK $!nick\n"); + $.ssay("USER $!username $!userhost $!host :$!userreal\n"); + $.ssay("JOIN $_\n") for @!channels; + + Supply.interval( .interval ).tap({ $OUTER::_.interval(self) }) + for @!plugins.grep(*.interval); + + react { + whenever $!sock.chars-supply -> $str is copy { + $str.say; + .msg(self, $str) for @!plugins.grep(so *.msg); + } + } + + say "Closing connection"; + $!sock.close; + }); + } + + method ssay (Str:D $msg) { + $!sock.print("$msg\n"); + + self; + } +} |