Alice
view release on metacpan or search on metacpan
lib/Alice/Role/IRCEvents.pm view on Meta::CPAN
my @commands = ();
push @commands, map {
my $command = $_;
sub {
$self->send_info($irc->name, "sending $command");
$irc->send_raw($command);
}
} @{$config->{on_connect}};
push @commands, map {
my $channel = $_;
sub {
$self->send_info($irc->name, "joining $channel");
$irc->send_srv("JOIN", split /\s+/, $channel);
}
} @{$config->{channels}};
my $t; $t = AE::timer 1, 0.5, sub {
if (my $command = shift @commands) {
$command->();
}
else {
undef $t;
}
};
my $name = $irc->name;
$irc->cl->enable_ping(300 => sub { $self->reconnect_irc($name) });
};
irc_event disconnect => sub {
my ($self, $irc, $reason) = @_;
my @windows = grep {$_->network eq $irc->name} $self->windows;
$self->broadcast({
type => "action",
event => "disconnect",
network => $irc->name,
windows => [map {$_->serialized} @windows],
});
$self->remove_window($_) for map {$_->id} @windows;
$reason = "" unless $reason;
return if $reason eq "reconnect requested.";
$self->send_info($irc->name, "disconnected: $reason");
# TODO - Object::Event bug that prevents object from getting destroyed
delete $irc->cl->{change_nick_cb_guard} if $irc->cl;
$irc->cl(undef);
$self->reconnect_irc($irc->name, 0) unless $irc->disabled;
if ($irc->removed) {
$self->remove_irc($irc->name);
}
};
irc_event publicmsg => sub {
my ($self, $irc, $channel, $msg) = @_;
if (my $window = $self->find_window($channel, $irc)) {
my ($nick) = split_prefix($msg->{prefix});
my $text = $msg->{params}[1];
return if $self->is_ignore(msg => $nick);
$self->send_message($window, $nick, $text);
}
};
irc_event privatemsg => sub {
my ($self, $irc, $nick, $msg) = @_;
my $text = $msg->{params}[1];
my ($from) = split_prefix($msg->{prefix});
if ($msg->{command} eq "PRIVMSG") {
return if $self->is_ignore(msg => $from);
my $window = $self->find_or_create_window($from, $irc);
$self->send_message($window, $from, $text);
$irc->send_srv(WHO => $from) unless $irc->nick_avatar($from);
}
elsif ($msg->{command} eq "NOTICE") {
$self->send_info($from, $text);
}
};
irc_event ctcp_action => sub {
my ($self, $irc, $nick, $channel, $msg, $type) = @_;
return unless $msg;
return if $self->is_ignore(msg => $nick);
my $dest = ($channel eq $irc->nick ? $nick : $channel);
if (my $window = $self->find_or_create_window($dest, $irc)) {
my $text = "\x{2022} $msg";
$self->send_message($window, $nick, $text);
}
};
irc_event nick_change => sub {
my ($self, $irc, $old_nick, $new_nick, $is_self) = @_;
my @channels = $irc->nick_channels($new_nick);
$self->broadcast(
grep {$_}
map {
if (my $window = $self->find_window($_, $irc)) {
$window->nicks_action($irc->channel_nicks($window->title)),
$self->is_ignore(nick => $_) ? ()
: $window->format_event("nick", $old_nick, $new_nick)
}
} @channels
);
if ($irc->avatars->{$old_nick}) {
( run in 2.788 seconds using v1.01-cache-2.11-cpan-e93a5daba3e )