1 | use strict; |
---|
2 | use Irssi; |
---|
3 | use vars qw($VERSION %IRSSI); |
---|
4 | $VERSION = "1"; |
---|
5 | %IRSSI = ( |
---|
6 | authors => "Simon Ward", |
---|
7 | contact => "simon\@bleah.co.uk", |
---|
8 | name => "Greynick", |
---|
9 | description => "grey out lines written by nick", |
---|
10 | license => "GPL", |
---|
11 | changed => "2008-05-26T23:15+0100" |
---|
12 | ); |
---|
13 | |
---|
14 | my $greyfile = "$ENV{HOME}/.irssi/greylist"; |
---|
15 | my %saved_greylist; |
---|
16 | my %session_greylist = {}; |
---|
17 | |
---|
18 | sub load_greylist { |
---|
19 | open GREYLIST, $greyfile; |
---|
20 | while (<GREYLIST>) { |
---|
21 | s/#.*$//; # strip comment |
---|
22 | next if /^(\s)*$/; # skip blank line |
---|
23 | chomp; |
---|
24 | $saved_greylist{$_} = 1; |
---|
25 | } |
---|
26 | close GREYLIST; |
---|
27 | } |
---|
28 | |
---|
29 | sub save_greylist { |
---|
30 | open GREYLIST, ">$greyfile"; |
---|
31 | foreach my $nick (keys %saved_greylist) { |
---|
32 | print GREYLIST "$nick\n"; |
---|
33 | } |
---|
34 | close GREYLIST; |
---|
35 | } |
---|
36 | |
---|
37 | # Keep track of nick changes per session |
---|
38 | sub sig_event_nick { |
---|
39 | my ($server, $newnick, $nick, $address) = @_; |
---|
40 | |
---|
41 | $newnick = substr ($newnick, 1) if ($newnick =~ /^:/); |
---|
42 | if ($saved_greylist{$nick} or $session_greylist{$nick}) { |
---|
43 | $session_greylist{$newnick} = 1; |
---|
44 | } |
---|
45 | } |
---|
46 | |
---|
47 | sub sig_message_public { |
---|
48 | my ($server, $msg, $nick, $addr, $target) = @_; |
---|
49 | my $chanrec = $server->channel_find($target); |
---|
50 | return unless $chanrec; |
---|
51 | my $nickrec = $chanrec->nick_find($nick); |
---|
52 | return unless $nickrec; |
---|
53 | |
---|
54 | if ($saved_greylist{$nick} or $session_greylist{$nick}) { |
---|
55 | $server->command('/^format pubmsg %K{pubmsgnick $2 {pubnick %K$0}}$1'); |
---|
56 | $server->command('/^format pubmsg_me %K{pubmsgmenick $2 {menick %y$0}}$1'); |
---|
57 | $server->command('/^format pubmsg_hilight %K{pubmsghinick $0 $3 %y$1}$2'); |
---|
58 | } else { |
---|
59 | $server->command('/^format -reset pubmsg'); |
---|
60 | $server->command('/^format -reset pubmsg_me'); |
---|
61 | $server->command('/^format -reset pubmsg_hilight'); |
---|
62 | } |
---|
63 | } |
---|
64 | |
---|
65 | sub sig_message_irc_action { |
---|
66 | my ($server, $msg, $nick, $addr, $target) = @_; |
---|
67 | my $chanrec = $server->channel_find($target); |
---|
68 | return unless $chanrec; |
---|
69 | my $nickrec = $chanrec->nick_find($nick); |
---|
70 | return unless $nickrec; |
---|
71 | |
---|
72 | if ($saved_greylist{$nick} or $session_greylist{$nick}) { |
---|
73 | $server->command('/^format action_public %K{pubaction %K$0}$1'); |
---|
74 | } else { |
---|
75 | $server->command('/^format -reset action_public'); |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | sub cmd_greylist_load { |
---|
80 | load_greylist; |
---|
81 | } |
---|
82 | |
---|
83 | sub cmd_greylist_save { |
---|
84 | save_greylist; |
---|
85 | } |
---|
86 | |
---|
87 | sub cmd_greylist_add { |
---|
88 | my ($nick) = $_[0]; |
---|
89 | if ($nick) { |
---|
90 | $saved_greylist{$nick} = 1; |
---|
91 | } else { |
---|
92 | Irssi::print('No nick given'); |
---|
93 | } |
---|
94 | } |
---|
95 | |
---|
96 | sub cmd_greylist_remove { |
---|
97 | my ($nick) = $_[0]; |
---|
98 | if ($nick) { |
---|
99 | delete ($saved_greylist{$nick}); |
---|
100 | } else { |
---|
101 | Irssi::print('No nick given'); |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | sub cmd_greylist_show { |
---|
106 | Irssi::print("\nSaved greylist:"); |
---|
107 | foreach my $nick (keys %saved_greylist) { |
---|
108 | Irssi::print($nick); |
---|
109 | } |
---|
110 | Irssi::print("\nSession greylist:"); |
---|
111 | foreach my $nick (keys %session_greylist) { |
---|
112 | Irssi::print($nick); |
---|
113 | } |
---|
114 | } |
---|
115 | |
---|
116 | sub cmd_greylist { |
---|
117 | my ($data, $server, $witem) = @_; |
---|
118 | chomp($data); |
---|
119 | $data = $data || 'show'; |
---|
120 | Irssi::command_runsub('greylist', $data, $server, $witem); |
---|
121 | } |
---|
122 | |
---|
123 | load_greylist; |
---|
124 | |
---|
125 | Irssi::command_bind('greylist', 'cmd_greylist'); |
---|
126 | Irssi::command_bind('greylist load', 'cmd_greylist_load'); |
---|
127 | Irssi::command_bind('greylist save', 'cmd_greylist_save'); |
---|
128 | Irssi::command_bind('greylist add', 'cmd_greylist_add'); |
---|
129 | Irssi::command_bind('greylist remove', 'cmd_greylist_remove'); |
---|
130 | Irssi::command_bind('greylist show', 'cmd_greylist_show'); |
---|
131 | |
---|
132 | Irssi::signal_add('message public', 'sig_message_public'); |
---|
133 | Irssi::signal_add('message irc action', 'sig_message_irc_action'); |
---|
134 | Irssi::signal_add('event nick', 'sig_event_nick'); |
---|