#!/usr/bin/perl use strict; use JSONConnection; use POSIX qw(strftime); use CursesChatMainwindow; our $connections; our $buffer_counter = 0; our $known_channels; our $js; my $c = AnyEvent->condvar; my $d = 0; my $wt; sub timer { $wt = AnyEvent->timer (after => 3, cb => sub { printline (status => [0, "TEST $d"]); $d++; timer (); }); } #timer (); $js = JSONClientConnection->new (packet_cb => sub { my ($js, $data) = @_; require JSON::Syck; if ($data->{type} eq 'channels') { $connections = $data->{connections}; for my $host (keys %$connections) { for my $channel (@{$connections->{$host}}) { $known_channels->{"$buffer_counter"} = [$host, $channel]; printline (status => [0, "new buffer: $buffer_counter"]); $buffer_counter++; } } } elsif ($data->{type} eq 'public') { my ($con, $chan) = ($data->{con}, $data->{channel}); my ($id) = grep { $known_channels->{$_}->[0] eq $con and $known_channels->{$_}->[1] eq $chan } keys %$known_channels; my $ts = POSIX::strftime ("%T", localtime ($data->{timestamp})); $ts = "[$ts] $data->{from}->{nick}> "; my (@chatline) = (("p".length $ts), 0, "$ts$data->{message}"); printline (((defined $id) ? "$id" : 'status'), \@chatline); printline (status => [0, "FOUND LINE: $id"]); } printline (status => [0, JSON::Syck::Dump ($data)]); }); $js->connect (localhost => 1236); CursesChatMainwindow::init; printline (status => ['p0', 0, "Connected!fdweifoj wfiowj iof ejwiofe wfh weufh weiufwe1234567890"]); printline (statusline => [20, "[#blob]"]); CursesChatMainwindow::register_input_cb (sub { my ($input) = @_; if ($input =~ m/^\/b\s*(\S+)/) { if (exists $known_channels->{$1}) { select_buffer ("$1"); printline (statusline => [21, "[$known_channels->{$1}->[1]]"]); } else { printline (status => [0, "no such buffer '$1'"]); } } elsif ($input =~ m/^\/colors/) { CursesChatMainwindow::print_colors; } else { $js->send_data ({ type => 'public', con => "localhost:6667", channel => '#blob', message => $input }); } }); $c->wait; CursesChatMainwindow::end;