1 | use warnings; |
---|
2 | use strict; |
---|
3 | |
---|
4 | =head1 NAME |
---|
5 | |
---|
6 | BarnOwl::Message::IRC |
---|
7 | |
---|
8 | =head1 DESCRIPTION |
---|
9 | |
---|
10 | A subclass of BarnOwl::Message for IRC messages |
---|
11 | |
---|
12 | =cut |
---|
13 | |
---|
14 | package BarnOwl::Message::IRC; |
---|
15 | |
---|
16 | use base qw( BarnOwl::Message ); |
---|
17 | |
---|
18 | sub smartfilter { |
---|
19 | my $self = shift; |
---|
20 | my $inst = shift; |
---|
21 | |
---|
22 | my $filter; |
---|
23 | my @filter; |
---|
24 | |
---|
25 | if($self->is_private) { |
---|
26 | my $who; |
---|
27 | if($self->direction eq 'out') { |
---|
28 | $who = $self->recipient; |
---|
29 | } else { |
---|
30 | $who = $self->sender; |
---|
31 | } |
---|
32 | $filter = "irc-user-$who"; |
---|
33 | @filter = |
---|
34 | (qw{( type ^irc$ and filter personal and }, |
---|
35 | qw{( ( direction ^in$ and sender}, "^\Q$who\E\$", |
---|
36 | qw{ ) or ( direction ^out$ and recipient}, "^\Q$who\E\$", |
---|
37 | qw{) ) ) }); |
---|
38 | BarnOwl::command("filter", "$filter", @filter); |
---|
39 | return $filter; |
---|
40 | } else { |
---|
41 | # To a Channel |
---|
42 | my $network = $self->network; |
---|
43 | my $channel = $self->channel; |
---|
44 | my $sender = $self->sender; |
---|
45 | my ($filter, $ftext); |
---|
46 | if ($inst && $self->body =~ /^(\S+):/) { |
---|
47 | $filter = "irc-$network-channel-$channel-$sender-$1"; |
---|
48 | @filter = |
---|
49 | (qw{type ^irc$ and network}, "^\Q$network\E\$", |
---|
50 | qw{and channel}, "^\Q$channel\E\$", |
---|
51 | qw{and ( sender}, "^\Q$sender\E\$", |
---|
52 | qw{or sender}, "^\Q$1\E\$",qq{)}); |
---|
53 | } else { |
---|
54 | $filter = "irc-$network-channel-$channel"; |
---|
55 | @filter = (qw{type ^irc$ and network}, "^\Q$network\E\$", |
---|
56 | qw{and channel}, "^\Q$channel\E\$"); |
---|
57 | } |
---|
58 | BarnOwl::command("filter", "$filter", @filter); |
---|
59 | return $filter; |
---|
60 | } |
---|
61 | } |
---|
62 | |
---|
63 | sub server {shift->{server}} |
---|
64 | sub network {shift->{network}} |
---|
65 | sub channel {shift->{channel}} |
---|
66 | sub action {shift->{action}} |
---|
67 | sub reason {shift->{reason}} |
---|
68 | sub old_nick {shift->{old_nick}}; |
---|
69 | |
---|
70 | # display |
---|
71 | sub context {shift->{network};} |
---|
72 | sub subcontext {shift->{recipient};} |
---|
73 | sub personal_context {"on " . shift->{network};} |
---|
74 | sub short_personal_context { shift->{network};} |
---|
75 | |
---|
76 | sub long_sender {shift->{from} || ""}; |
---|
77 | |
---|
78 | sub login_type { |
---|
79 | my $self = shift; |
---|
80 | return " (" . uc $self->action . ")"; |
---|
81 | } |
---|
82 | |
---|
83 | sub login_extra { |
---|
84 | my $self = shift; |
---|
85 | if ($self->action eq "quit") { |
---|
86 | return $self->reason; |
---|
87 | } elsif ($self->action eq 'nick change') { |
---|
88 | return "was: " . $self->old_nick; |
---|
89 | } else { |
---|
90 | return $self->channel; |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | # logging |
---|
95 | sub log_filenames { |
---|
96 | my ($m) = @_; |
---|
97 | die "IRC should not be handling non-IRC messages" if lc($m->type) ne "irc"; |
---|
98 | BarnOwl::error("IRC message without a network") if !defined($m->network) || $m->network eq ''; |
---|
99 | my $filename = lc($m->network); |
---|
100 | # Note: Channel names generally start with '#', which |
---|
101 | # disambiguates channels from individuals; for example, personals |
---|
102 | # will look like, e.g., "~/zlog/irc/freenode:john-doe", whereas |
---|
103 | # channels will look like, e.g., "~/zlog/irc/freenode:#barnowl" |
---|
104 | if ($m->is_personal) { |
---|
105 | if ($m->is_incoming) { |
---|
106 | $filename .= ":" . $m->sender; |
---|
107 | } elsif ($m->is_outgoing) { |
---|
108 | $filename .= ":" . $m->recipient; |
---|
109 | } |
---|
110 | } else { |
---|
111 | $filename .= ":" . $m->channel; |
---|
112 | } |
---|
113 | return ($filename); |
---|
114 | } |
---|
115 | |
---|
116 | sub log { |
---|
117 | my ($m) = @_; |
---|
118 | my $sender = $m->sender; |
---|
119 | my $timestr = $m->time; |
---|
120 | my $body = $m->body; |
---|
121 | if ($m->is_loginout) { |
---|
122 | return BarnOwl::Message::log($m); |
---|
123 | } else { |
---|
124 | return "[$timestr] <$sender> $body\n"; |
---|
125 | } |
---|
126 | } |
---|
127 | |
---|
128 | 1; |
---|