Skip to content

Commit

Permalink
Bug commit
Browse files Browse the repository at this point in the history
  • Loading branch information
zoffixznet committed Jun 5, 2016
1 parent a1ea399 commit 16056e8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
32 changes: 18 additions & 14 deletions lib/IRC/Client.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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; };
}
}
}
Expand All @@ -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>;
}
}

Expand All @@ -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;
}
Expand All @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions lib/IRC/Client/Message.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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; }
Expand Down

0 comments on commit 16056e8

Please sign in to comment.