ignoreoc.pl
Code Index:
1 #!/usr/bin/perl -w
2 use Irssi;
3 use vars qw($VERSION %IRSSI);
4 $VERSION = "0.6";
5 %IRSSI = (
6 authors => "Erkki Seppälä",
7 contact => "flux\@inside.org",
8 name => "Ignore-OC",
9 description => "Ignore messages from people not on your channels." .
10 "Now people you msg are added to bypass-list.",
11 license => "Public Domain",
12 url => "http://www.inside.org/~flux/software/irssi/",
13 changed => "Mon Jun 16 08:10:45 EEST 2008"
14 );
15
16 my %bypass = ();
17
18 my $ignoredMessages = 0;
19
20 sub cmd_message_private {
21 my ($server, $message, $nick, $address) = @_;
22 my $channel;
23
32
33 if ($message =~ m/oc:/i ||
34 exists $bypass{$nick}) {
35 return 1;
36 }
37
38 foreach $channel ($server->channels()) {
39 foreach my $other ($channel->nicks()) {
40 if ($other->{nick} eq $nick) {
41 return 1;
42 }
43 }
44 }
45
46 ++$ignoredMessages;
47 $server->command("^NOTICE $nick You're not on any channel I'm on, thus, due to spambots, your message was ignored. Prefix your message with 'OC:' to bypass the ignore.");
48 Irssi::signal_stop();
49 }
50
51 sub cmd_message_own_private {
52 my ($server, $message, $nick, $address) = @_;
53 $bypass{$nick} = 1;
54 }
55
56 sub cmd_ignoreoc {
57 Irssi::print("You've ignored $ignoredMessages messages since startup.");
58 }
59
60 Irssi::signal_add_first("message private", "cmd_message_private");
61 Irssi::signal_add("message own_private", "cmd_message_own_private");
62 Irssi::command_bind("ignoreoc", "cmd_ignoreoc");
63
64 Irssi::print "IgnoreOC version $VERSION by flux with patches from Exstatica. Try /ignoreoc"