view release on metacpan or search on metacpan
# extlib present
if (-e "$bin/../extlib") {
eval "use lib '$bin/../extlib/lib/perl5'";
eval "use local::lib '$bin/../extlib'";
}
}
require Alice::Standalone;
}
$0 = "aliced\0";
binmode(STDERR, ":utf8");
binmode(STDOUT, ":utf8");
Alice::Standalone->new->run;
lib/Alice.pm view on Meta::CPAN
sub _build_window_buffer {
my ($self, $id) = @_;
Alice::MessageBuffer->new(
id => $id,
store => $self->message_store,
);
}
sub _build_window_id {
my ($self, $title, $network) = @_;
md5_hex(encode_utf8(lc $self->user."-$title-$network"));
}
sub find_or_create_window {
my ($self, $title, $irc) = @_;
return $self->info_window if $title eq "info";
if (my $window = $self->find_window($title, $irc)) {
return $window;
}
lib/Alice/HTTP/Request.pm view on Meta::CPAN
}
sub new_response {
my $self = shift;
Alice::HTTP::Response->new($self->{cb}, @_);
}
sub param {
my $self = shift;
if (wantarray) {
return map {decode("utf8", $_)} $self->SUPER::param(@_);
}
else {
return decode("utf8", $self->SUPER::param(@_));
}
}
1;
lib/Alice/HTTP/Response.pm view on Meta::CPAN
$self->status($rc) if defined $rc;
$self->headers($headers) if defined $headers;
$self->body($content) if defined $content;
$self;
}
sub send {
my $self = shift;
my $res = $self->SUPER::finalize;
$res->[2] = [map encode("utf8", $_), @{$res->[2]}];
return $self->{cb}->($res);
}
sub notfound {
my $self = shift;
return $self->{cb}->([404, ["Content-Type", "text/plain", "Content-Length", 9], ['not found']]);
}
sub ok {
my $self = shift;
lib/Alice/HTTP/Server.pm view on Meta::CPAN
$req->env->{"psgix.session"} = {
is_logged_in => 1,
username => $user,
userid => $app->user,
};
$res->redirect($dest);
}
else {
$req->env->{"psgix.session"}{is_logged_in} = 0;
$req->env->{"psgix.session.options"}{expire} = 1;
$res->content_type("text/html; charset=utf-8");
$res->body($self->render("login", $dest, "bad username or password"));
}
$res->send;
});
}
# render the login page
else {
$res->content_type("text/html; charset=utf-8");
$res->body($self->render("login", $dest));
$res->send;
}
}
sub logout {
my ($self, $req, $res) = @_;
$_->close for @{$self->app->streams};
if (!$self->auth_enabled) {
$res->redirect("/");
lib/Alice/HTTP/Server.pm view on Meta::CPAN
$req->parameters->{images} = "hide";
$req->parameters->{avatars} = "hide";
$self->send_index($req, $res);
}
sub send_index {
my ($self, $req, $res) = @_;
my $options = $self->merged_options($req);
my $app = $self->app;
$res->headers(["Content-type" => "text/html; charset=utf-8"]);
my $writer = $res->writer;
my @windows = $app->sorted_windows;
my @queue;
push @queue, sub {$app->render('index_head', @windows)};
for my $window (@windows) {
push @queue, sub {$app->render('window_head', $window)};
push @queue, sub {$app->render('window_footer', $window)};
}
push @queue, sub {
my $html = $app->render('index_footer', $options, @windows);
$app->config->first_run(0);
$app->config->write;
return $html;
};
my $idle_w; $idle_w = AE::idle sub {
if (my $cb = shift @queue) {
my $content = encode "utf8", $cb->();
$writer->write($content);
} else {
$writer->close;
undef $idle_w;
}
};
}
sub merged_options {
my ($self, $req) = @_;
lib/Alice/HTTP/Server.pm view on Meta::CPAN
$cb->($success ? $self->app : ());
}
sub render {
my $self = shift;
return $self->app->render(@_);
}
sub export_config {
my ($self, $req, $res) = @_;
$res->content_type("text/plain; charset=utf-8");
{
$res->body(to_json($self->app->config->serialized,
{utf8 => 1, pretty => 1}));
}
$res->send;
}
__PACKAGE__->meta->make_immutable;
1;
lib/Alice/HTTP/Stream/WebSocket.pm view on Meta::CPAN
$self->send([{type => "identify", id => $self->id}]);
}
sub send {
my ($self, $messages) = @_;
$messages = [$messages] unless ref $messages eq "ARRAY";
my $line = to_json(
{queue => $messages},
{utf8 => 1, shrink => 1}
);
$self->send_raw($line);
}
sub send_raw {
my ($self, $string) = @_;
$self->handle->push_write(
'AnyEvent::Handle::Message::WebSocket',
$string
lib/Alice/HTTP/Stream/XHR.pm view on Meta::CPAN
use JSON;
use Time::HiRes qw/time/;
use Any::Moose;
extends 'Alice::HTTP::Stream';
use strict;
use warnings;
my $separator = "xalicex";
our @headers = ('Content-Type' => "multipart/mixed; boundary=$separator; charset=utf-8");
has queue => (
is => 'rw',
isa => 'ArrayRef[HashRef]',
default => sub { [] },
);
sub clear_queue {$_[0]->queue([])}
sub enqueue {push @{shift->queue}, @_}
sub queue_empty {return @{$_[0]->queue} == 0}
lib/Alice/HTTP/Stream/XHR.pm view on Meta::CPAN
$self->clear_queue;
$self->last_send(time);
}
sub to_string {
my $self = shift;
return to_json({
queue => $self->queue,
time => time - $self->offset,
}, {utf8 => 1, shrink => 1});
}
__PACKAGE__->meta->make_immutable;
1;
lib/Alice/IRC.pm view on Meta::CPAN
my $email_re = qr/([^<\s]+@[^\s>]+\.[^\s>]+)/;
my $image_re = qr/(https?:\/\/\S+(?:jpe?g|png|gif))/i;
{
no warnings;
# YUCK!!!
*AnyEvent::IRC::Connection::_feed_irc_data = sub {
my ($self, $line) = @_;
my $m = parse_irc_msg (decode ("utf8", $line));
$self->event (read => $m);
$self->event ('irc_*' => $m);
$self->event ('irc_' . (lc $m->{command}), $m);
};
*AnyEvent::IRC::Connection::mk_msg = \&mk_msg;
*AnyEvent::IRC::Client::mk_msg = \&mk_msg;
}
has 'cl' => (is => 'rw');
lib/Alice/IRC.pm view on Meta::CPAN
my ($self, $cmd, @params) = @_;
my $msg = pop @params;
my $ident = $self->cl->nick_ident($self->cl->nick);
my $init_len = length mk_msg($ident, $cmd, @params, " ");
my $max_len = 500; # give 10 bytes extra margin
my $line_len = $max_len - $init_len;
# split up the multiple lines in the message:
my @lines = split /\n/, $msg;
@lines = map split_unicode_string ("utf-8", $_, $line_len), @lines;
$self->cl->send_srv($cmd => @params, $_) for @lines;
}
sub send_raw {
my $self = shift;
$self->cl->send_raw(encode "utf8", $_[0]);
}
sub is_connected {
my $self = shift;
$self->cl ? $self->cl->is_connected : 0;
}
sub is_disconnected {
my $self = shift;
return !($self->is_connected or $self->is_connecting);
lib/Alice/IRC.pm view on Meta::CPAN
$cur_out .= $word;
$word = '';
}
}
push @lines, $cur_out if length ($cur_out);
return @lines;
}
sub mk_msg {
encode "utf8", AnyEvent::IRC::Util::mk_msg(@_);
}
__PACKAGE__->meta->make_immutable;
1;
lib/Alice/Window.pm view on Meta::CPAN
package Alice::Window;
use Encode;
use utf8;
use Alice::MessageBuffer;
use Text::MicroTemplate qw/encoded_string/;
use IRC::Formatting::HTML qw/irc_to_html/;
use Any::Moose;
use AnyEvent;
my $url_regex = qr/\b(https?:\/\/(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»ââââ]))/i;
has buffer => (
is => 'rw',