From 175d70e3703caa05bcde9d1dc50e3ebe842fbedb Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Wed, 25 Nov 2015 15:47:36 -0500 Subject: Make stubbing work --- examples/bot.pl6 | 3 ++- lib/IRC/Client.pm6 | 28 +++++++++++++++++----------- lib/IRC/Client/Plugin/HNY.pm6 | 6 ++++-- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/examples/bot.pl6 b/examples/bot.pl6 index 42f9d77..00a8406 100644 --- a/examples/bot.pl6 +++ b/examples/bot.pl6 @@ -2,9 +2,10 @@ use v6; use lib 'lib'; use IRC::Client; use IRC::Client::Plugin::HNY; -say "42"; + my $irc = IRC::Client.new( :host('irc.freenode.net'), + :debug, plugins => [ IRC::Client::Plugin::HNY.new, ] diff --git a/lib/IRC/Client.pm6 b/lib/IRC/Client.pm6 index d4a00ca..ae8f245 100644 --- a/lib/IRC/Client.pm6 +++ b/lib/IRC/Client.pm6 @@ -1,16 +1,16 @@ use v6; -class IRC::Client::Plugin { ... } +role 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 = []; + has Bool $.debug = False; + 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 @.plugins = []; + has IO::Socket::Async $.sock; method run { await IO::Socket::Async.connect( $!host, $!port ).then({ @@ -36,7 +36,13 @@ class IRC::Client:ver<1.001001> { method ssay (Str:D $msg) { $!sock.print("$msg\n"); + self; + } + method privmsg (Str $who, Str $what) { + my $msg = ":$!nick!$!username\@$!userhost PRIVMSG $who :$what\n"; + $!debug and say ".privmsg({$msg.subst("\n", "␤", :g)})"; + self.ssay: $msg; self; } } diff --git a/lib/IRC/Client/Plugin/HNY.pm6 b/lib/IRC/Client/Plugin/HNY.pm6 index 7f52302..f9f7cbe 100644 --- a/lib/IRC/Client/Plugin/HNY.pm6 +++ b/lib/IRC/Client/Plugin/HNY.pm6 @@ -2,7 +2,9 @@ use v6; use IRC::Client; use IRC::Client::Plugin; unit class IRC::Client::Plugin::HNY:ver<1.001001> does IRC::Client::Plugin; -multi method interval ( ) { 2 } +multi method interval ( ) { 6 } multi method interval (IRC::Client $irc) { - $irc.ssay("5 seconds passed. Time is now " ~ now); + $irc.privmsg( + $irc.channels[0], "5 seconds passed. Time is now " ~ now + ); } -- cgit v1.1