From 5a2196b2c8f2ac2eacb3ddaf40b3e75b9c38bb62 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Sat, 4 Jun 2016 19:18:31 -0400 Subject: Stuff --- lib/IRC/Client.pm6 | 57 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 10 deletions(-) (limited to 'lib/IRC/Client.pm6') diff --git a/lib/IRC/Client.pm6 b/lib/IRC/Client.pm6 index 3fca5ae..0c836a4 100644 --- a/lib/IRC/Client.pm6 +++ b/lib/IRC/Client.pm6 @@ -25,26 +25,46 @@ method run { my $left-overs = ''; react { + CATCH { warn .backtrace } + whenever $!sock.Supply :bin -> $buf is copy { my $str = try $buf.decode: 'utf8'; $str or $str = $buf.decode: 'latin-1'; $str ~= $left-overs; (my $events, $left-overs) = self!parse: $str; + $str ~~ /$=(\N*)$/; + dd $str; + say "#### SHOULD Left over: `$`"; + say "#### LEFT OVERS: `$left-overs`"; for $events.grep: *.defined -> $e { - $!debug and debug-print $e; CATCH { warn .backtrace } + $!debug and debug-print $e, 'in'; + self!handle-event: $e; } } - - CATCH { warn .backtrace } } $!sock.close; }); } +method send-cmd ($cmd, *@args) { + @args[*-1] = ':' ~ @args[*-1]; + self!ssay: join ' ', $cmd, @args; +} + +method !handle-event ($e) { + given $e.command { + when '001' { self!ssay: "JOIN @.channels[]"; } + when 'PING' { $e.reply } + when 'JOIN' { + say "Joined channel $e.channel()"; + } + } +} + method !ssay (Str:D $msg) { - $!debug and debug-print $msg; + $!debug and debug-print $msg, 'out'; $!sock.print("$msg\n"); self; } @@ -59,14 +79,31 @@ method !parse (Str:D $str) { ).made; } -sub debug-print ($str, $dir where * eq 'in' | 'out') { - state $color = try { +sub debug-print (Str(Any) $str, $dir where * eq 'in' | 'out') { + state $colored = try { require Terminal::ANSIColor; - $color = GLOBAL::Terminal::ANSIColor::EXPORT::DEFAULT::<&color>; + $colored = GLOBAL::Terminal::ANSIColor::EXPORT::DEFAULT::<&colored>; } // sub (Str $s) { '' }; + my @out; + if $str ~~ /^ '❚⚠❚'/ { + @out = $str.split: ' ', 3; + @out[0] = $colored(@out[0], 'bold white on_red'); + @out[1] = @out[1] ~~ /^ <[0..9]>**3 $/ + ?? $colored(@out[1], 'bold red') + !! $colored(@out[1], 'bold magenta'); + @out[2] = $colored(@out[2], 'bold cyan'); + } + else { + @out = $str.split: ' ', 2; + @out[0] = @out[0] ~~ /^ <[0..9]>**3 $/ + ?? $colored(@out[0], 'bold red') + !! $colored(@out[0], 'bold magenta'); + @out[1] = $colored(@out[1], 'bold cyan'); + } + put ( $dir eq 'in' - ?? $color('bold blue' ) ~ '▬▬▬▶ ' - !! $color('bold green') ~ '◀▬▬▬ ' - ) ~ $color('bold red') ~ join $color('reset'), $str.split: ' ', 2; + ?? $colored('▬▬▶ ', 'bold blue' ) + !! $colored('◀▬▬ ', 'bold green') + ) ~ @out.join: ' '; } -- cgit v1.1