[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: spam suppressor?



On Tue, 19 Mar 2002 19:11:13 +0100
Bruno Boettcher <bboett@bboett.dyndns.org> wrote:
> 
> lately i got really nooyed with spam on irc, the content is easily
> regexable: sex, teen etc...
> 
> so i was wondering if therewas allready a script out to completely
> ignore dcc or normal chat requests with lines matching those words....
> cause now i have tons tabs opening cause of those nuisances...
> 

Here's something that will probably do a large chunk of what
you want plus,

- Loading/Saving of a list of patterns to match spam on
- Add/Remove/Replace spam patterns without editing/reloading the script

A couple of cautions/things that are missing:

- The script does not filter DCCs, but that probably shouldn't be hard
  to adapt the existing code for.
- The script as presented will filter all messages; you may want to only
  filter private messages specifically sent to your nick (match against
  $to in privmsg_handler)

The code presented below is heavily modified from a script I use to
deal with IRC spams forwarded to a special channel by known reporters
on DALNet, so I'm not filtering all my PRIVMSGs, but rather only ones
directed at the specific channel I monitor.

You're probably aware of the following, but I figured I'd throw it out anyway as
other options with less of an impact on the IRC client:

I believe most IRC nets support usermode +i, which renders your client
invisible to anyone not sharing a channel with you. Some IRC spam scripts/bots
attempt to spam all nicks that it can see globally on the IRC net. Usermode
+i will prevent you from getting spam from spam bots not any channels in
common with you.

Unfortunately, IRC spam bots have known about that for a long time, so spam
bots will rapidly join/part through all channels it can find on the IRC net
and PRIVMSG all of the nicks it finds in each channel it joins. However
most of those spam bot operators won't bother registering a nick (on nets
that support nick registration -- like DALnet). DALnet has an additional
usermode that some people use - +R. This mode will prevent anyone/anything
on a non-registered nick from messaging you.


------ Begin Script ------
#!/usr/bin/perl -w

{
package IRC::XChat::SpamIgnore;

@spam_ignore = ();

sub spam_handler
{
    ($nick,$msg) = @_;

    foreach (@webspam_ignore) {
	if ($msg =~ /$_/i) {
	    return 1;
	}
    }
}

sub privmsg_handler
{
    my $line = shift(@_);
    $line =~ /:(\S+)!(\S+)@(\S+) (\S+) (\S+) :(.*)/;
    ($nick,$ident,$host,$cmd,$to,$msg) = ($1,$2,$3,$4,$5,$6);
    return spam_handler($nick, $msg);
}

sub load_si {
    open(FIN, (glob("~/spam-ignore.txt"))[0])
	or return;
    @spam_ignore = ();
    while (<FIN>) {
	chomp;
	push @spam_ignore, $_;
    }
    close FIN;
}

sub save_si {
    open(FOUT, ">", (glob("~/spam-ignore.txt"))[0])
	or return;
    foreach (@spam_ignore) {
      print FOUT "$_\n";
    }
    close FOUT;
}

#/si load
#/si clear
#/si save
#/si add <pattern>
#/si replace <pattern-num> <pattern>
#/si list
#/si del <pattern-num>
sub si_command {
    my $line = shift(@_);

    if ($line =~ /^\s*load/i) {
	load_si();
      IRC::print "--spam ignore list loaded--\n";
	return 1;
    }
    elsif ($line =~ /^\s*clear/i) {
	@spam_ignore = ();
    }
    elsif ($line =~ /^\s*save/i) {
	save_si();
      IRC::print "--spam ignore list saved--\n";
	return 1;
    }
    elsif ($line =~ /^\s*add\s+(.*)$/i) {
	$remain = $1;
	push @spam_ignore, $remain;
    }
    elsif ($line =~ /^\s*replace\s+(\d+)\s+(.*)$/i) {
	($index, $remain) = ($1, $2);
	if ($index && ($index >= 0 && $index <= $#spam_ignore)) {
	    $spam_ignore[$index] = $remain;
	}
    }
    elsif ($line =~ /^\s*list/i) {
	my $count;
	foreach (@spam_ignore) {
	  IRC::print $count+0 . " - $_\n";
	    $count++;
	}
      IRC::print "--End of Spam Ignore List--\n";
    }
    elsif ($line =~ /^\s*del\s+(\d+)/i) {
	$index = $1;
	if (length($index) && ($index >= 0 && $index <= $#spam_ignore)) {
	    splice @spam_ignore, $index+0, 1;
	}
    }
    else {
	#no valid command detected
    }
    return 1;
}

}

IRC::print "Loading spamignore.pl\n";
IRC::print "Registering Handlers...\n";
IRC::add_command_handler("si", "IRC::XChat::SpamIgnore::si_command");

IRC::add_message_handler("PRIVMSG", "IRC::XChat::SpamIgnore::privmsg_handler");
IRC::XChat::SpamIgnore::load_si();

------ End Script ------


--
XChat-discuss: mailing list for XChat users
Archive:       http://mail.nl.linux.org/xchat-discuss/