aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorZoffix Znet <cpan@zoffix.com>2015-11-25 15:47:36 -0500
committerZoffix Znet <cpan@zoffix.com>2015-11-25 15:47:36 -0500
commit175d70e3703caa05bcde9d1dc50e3ebe842fbedb (patch)
treefbc75dffb2957dd03c267e229fa98c66e011f048 /lib
parent4e394a6fa9d8f838917dbc9196f0ef367d5e9ae9 (diff)
Make stubbing work
Diffstat (limited to 'lib')
-rw-r--r--lib/IRC/Client.pm628
-rw-r--r--lib/IRC/Client/Plugin/HNY.pm66
2 files changed, 21 insertions, 13 deletions
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
+ );
}