aboutsummaryrefslogtreecommitdiff
path: root/lib/IRC/Client.pm6
diff options
context:
space:
mode:
authorZoffix Znet <cpan@zoffix.com>2016-06-04 19:18:31 -0400
committerZoffix Znet <cpan@zoffix.com>2016-06-04 19:18:31 -0400
commit5a2196b2c8f2ac2eacb3ddaf40b3e75b9c38bb62 (patch)
tree0241ad573b1db26be38dbd6396041643c04113a8 /lib/IRC/Client.pm6
parent791d7981cff0cd3a85fdd504f410a7c9833272dc (diff)
Stuff
Diffstat (limited to 'lib/IRC/Client.pm6')
-rw-r--r--lib/IRC/Client.pm657
1 files changed, 47 insertions, 10 deletions
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 ~~ /$<left>=(\N*)$/;
+ dd $str;
+ say "#### SHOULD Left over: `$<left>`";
+ 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: ' ';
}