package BettIrssiEvent; use strict; use Irssi; use Data::Dumper; sub new { my $class = shift; my $self = {@_}; return bless($self, $class); } sub message { my $self = shift; return $self->{'MESSAGE'}; } sub channel { my $self = shift; return $self->{'EVWITEM'}; } sub sender { my $self = shift; return $self->{'SENDER'}; } sub ewpf { my $self = shift; return sub {$self->ewprint(@_)}; } sub ewprint { my $self = shift; my $data = shift; if (defined($self->{'EVWITEM'})) { $self->{'EVWITEM'}->print($data); } else { # No witem. This probably means that the event fired # in the status window. Irssi::print($data); } } sub awpf { my $self = shift; return sub {$self->awprint(@_)}; } sub awprint { my $self = shift; my $data = shift; my $w; $w = Irssi::active_win(); if (defined($w)) { foreach ($w->items()) { if ($_->is_active()) { $_->print($data); return; } } # # No active window item found. Write to the window directly. $w->print($data); } else { # No active win. This should not happen, but nonetheless. # Write to the status window. Irssi::print($data); } } sub swpf { my $self = shift; return sub { $self->swprint(@_) }; } sub swprint { my $self = shift; Irssi::print(shift); } 1;