Initial commit
[BettIrssi.git] / BettIrssiEvent.pm
1 package BettIrssiEvent;
2
3 use strict;
4 use Irssi;
5 use Data::Dumper;
6
7 sub new {
8     my $class = shift;
9     my $self = {@_};
10
11     return bless($self, $class);
12 }
13
14 sub message {
15     my $self = shift;
16
17     return $self->{'MESSAGE'};
18 }
19
20 sub channel {
21     my $self = shift;
22
23     return $self->{'EVWITEM'};
24 }
25
26 sub sender {
27     my $self = shift;
28
29     return $self->{'SENDER'};
30 }
31
32
33 sub ewpf {
34     my $self = shift;
35
36     return sub {$self->ewprint(@_)};
37 }
38
39 sub ewprint {
40     my $self = shift;
41     my $data = shift;
42
43     if (defined($self->{'EVWITEM'})) {
44         $self->{'EVWITEM'}->print($data);
45     } else {
46         # No witem. This probably means that the event fired
47         # in the status window.
48         Irssi::print($data);
49     }
50 }
51
52 sub awpf {
53     my $self = shift;
54
55     return sub {$self->awprint(@_)};
56 }
57
58 sub awprint {
59     my $self = shift;
60     my $data = shift;
61     my $w;
62
63     $w = Irssi::active_win();
64
65     if (defined($w)) {
66         foreach ($w->items()) {
67             if ($_->is_active()) {
68                 $_->print($data);
69                 return;
70             }
71         }
72         #
73         # No active window item found. Write to the window directly.
74         $w->print($data);
75     } else {
76         # No active win. This should not happen, but nonetheless.
77         # Write to the status window.
78         Irssi::print($data);
79     }
80 }
81
82 sub swpf {
83     my $self = shift;
84
85     return sub { $self->swprint(@_) };
86 }
87
88 sub swprint {
89     my $self = shift;
90
91     Irssi::print(shift);
92 }
93
94
95 1;