aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorZoffix Znet <cpan@zoffix.com>2016-06-05 11:17:15 -0400
committerZoffix Znet <cpan@zoffix.com>2016-06-05 11:17:15 -0400
commit16056e8af837a4d982d23728adf24b4cc406576c (patch)
treec124b0d77711ef4d903a67d05969a35c84a766e4 /lib
parenta1ea399a2e4c36949959fa22ecfac5fe583f1775 (diff)
Bug commit
Diffstat (limited to 'lib')
-rw-r--r--lib/IRC/Client.pm632
-rw-r--r--lib/IRC/Client/Message.pm68
2 files changed, 22 insertions, 18 deletions
diff --git a/lib/IRC/Client.pm6 b/lib/IRC/Client.pm6
index cc18db2..96580cf 100644
--- a/lib/IRC/Client.pm6
+++ b/lib/IRC/Client.pm6
@@ -15,14 +15,20 @@ has Str:D @.channels = ['#perl6'];
has @.plugins;
has %.servers;
+my &colored = try {
+ require Terminal::ANSIColor;
+ &colored
+ = GLOBAL::Terminal::ANSIColor::EXPORT::DEFAULT::<&colored>;
+} // sub (Str $s, $) { $s };
+
method run {
self!prep-servers;
my $lock = Lock.new;
for %!servers.kv -> $s-name, $s-conf {
$s-conf<promise>
- = IO::Socket::Async.connect($s-conf<host>, $s-conf<port>).then: -> $v {
- $lock.protect: { $s-conf<sock> = $v.result; };
+ = IO::Socket::Async.connect($s-conf<host>, $s-conf<port>).then: {
+ $lock.protect: { $s-conf<sock> = .result; };
self!ssay: "PASS $!password", :server($s-name)
if $!password.defined;
@@ -43,8 +49,8 @@ method run {
(my $events, $left-overs)
= self!parse: $str, :server($s-name);
for $events.grep: *.defined -> $e {
- $!debug and debug-print $e, :in;
- self!handle-event: $e;
+ $!debug and debug-print $e, :in, :server($e.server);
+ $lock.protect: { self!handle-event: $e; };
}
}
}
@@ -66,16 +72,20 @@ method !prep-servers {
$s{$_} //= self."$_"()
for <host password port nick username userhost userreal>;
$s<channels> = @.channels;
+ $s<socket> = Nil;
}
}
method !handle-event ($e) {
given $e.command {
- when '001' { self!ssay: "JOIN @.channels[]", :server($e.server); }
+ when '001' {
+ %!servers{ $e.server }<nick> = $e.args[0];
+ self!ssay: "JOIN @.channels[]", :server($e.server);
+ }
when 'PING' { $e.reply }
when 'JOIN' {
say "Joined channel $e.channel()"
- if $e.nick eq $!nick;
+ if $e.nick eq %!servers{ $e.server }<nick>;
}
}
@@ -92,7 +102,7 @@ method !plugs-that-can ($method) {
}
method !ssay (Str:D $msg, :$server = '*') {
- # $!debug and debug-print $msg, :out, :$server;
+ $!debug and debug-print $msg, :out, :$server;
%!servers{ $server }<sock>.print("$msg\n");
self;
}
@@ -108,14 +118,8 @@ method !parse (Str:D $str, :$server) {
}
sub debug-print (Str(Any) $str, :$in, :$out, :$sys, :$server) {
- state &colored = try {
- require Terminal::ANSIColor;
- &colored
- = GLOBAL::Terminal::ANSIColor::EXPORT::DEFAULT::<&colored>;
- } // sub (Str $s, $) { $s };
-
my $server-str = $server
- ?? colored($server, 'bold white on_green') ~ ' ' !! '';
+ ?? colored($server, 'bold white on_cyan') ~ ' ' !! '';
my @bits = $str.split: ' ';
if $in {
diff --git a/lib/IRC/Client/Message.pm6 b/lib/IRC/Client/Message.pm6
index e7478de..9a51803 100644
--- a/lib/IRC/Client/Message.pm6
+++ b/lib/IRC/Client/Message.pm6
@@ -8,9 +8,9 @@ role IRC::Client::Message {
has Str:D $.usermask is required;
has Str:D $.command is required;
has Str:D $.server is required;
- has @.args is required;
+ has $.args is required;
- method Str { ":$!usermask $!command @!args[]" }
+ method Str { ":$!usermask $!command $!args[]" }
}
constant M = IRC::Client::Message;
@@ -26,11 +26,11 @@ role Numeric does M { }
role Part does M { has $.channel; }
role Quit does M { }
role Unknown does M {
- method Str { "❚⚠❚ :$.usermask $.command @.args[]" }
+ method Str { "❚⚠❚ :$.usermask $.command $.args[]" }
}
role Ping does M {
- method reply { $.irc.send-cmd: 'PONG', @.args; }
+ method reply { $.irc.send-cmd: 'PONG', $.args, :$.server; }
}
role Privmsg does M { has $.text; }