1#!/usr/local/bin/perl -w
2use strict;
3use Irssi;
4use vars qw($VERSION %IRSSI);
5$VERSION = "0.6";
6%IRSSI = (
7    authors     => "Erkki Sepp�l�",
8    contact     => "flux\@inside.org",
9    name        => "Ignore-OC",
10    description => "Ignore messages from people not on your channels." .
11		   "Now people you msg are added to bypass-list.",
12    license     => "Public Domain",
13    url         => "http://www.inside.org/~flux/software/irssi/",
14    changed     => "Mon Jun 16 08:10:45 EEST 2008"
15);
16
17my %bypass = ();
18
19my $ignoredMessages = 0;
20
21sub cmd_message_private {
22  my ($server, $message, $nick, $address) = @_;
23  my $channel;
24
25=cut
26  my ($addressNick) = $address =~ /^([^@]*)/;
27
28  if ($addressNick ne $server->{nick}) {
29    Irssi::print "Irssi bug? Received a message sent to $address";
30    return 1;
31  }
32=cut
33
34  if ($message =~ m/oc:/i ||
35      exists $bypass{$nick}) {
36    return 1;
37  }
38
39  foreach $channel ($server->channels()) {
40    foreach my $other ($channel->nicks()) {
41      if ($other->{nick} eq $nick) {
42        return 1;
43      }
44    }
45  }
46
47  ++$ignoredMessages;
48  $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.");
49  Irssi::signal_stop();
50}
51
52sub cmd_message_own_private {
53  my ($server, $message, $nick, $address) = @_;
54  $bypass{$nick} = 1;
55}
56
57sub cmd_ignoreoc {
58  Irssi::print("You've ignored $ignoredMessages messages since startup.");
59}
60
61Irssi::signal_add_first("message private", "cmd_message_private");
62Irssi::signal_add("message own_private", "cmd_message_own_private");
63Irssi::command_bind("ignoreoc", "cmd_ignoreoc");
64
65Irssi::print "IgnoreOC version $VERSION by flux with patches from Exstatica. Try /ignoreoc"
66