#!/usr/bin/perl -w use strict; { package IRC::XChat::SpamIgnore; my @spam_ignore = (); my $nick = (); my $msg = (); my $remain = (); my $index = (); sub spam_handler { ($nick,$msg) = @_; foreach (@spam_ignore) { if ($msg =~ /^$_$/) { IRC::print "SPAM MATCHED FROM $nick"; return 1; } } } sub privmsg_handler { my $line = shift(@_); my ($nick, $ident, $domain, $msgtype, $channel, $msg) = $line =~ m{^ \:([^!]+) \!([^@]+) @(\S+)\s (\w+)\s (\S+)\s :(.*)$ }x; return spam_handler($nick, $msg); } sub load_si { open(FIN, (glob("~/spam-ignore.txt"))[0]) or return; @spam_ignore = (); while () { 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 #/si replace #/si list #/si del sub si_command { my $line = shift(@_); if ($line =~ /^\s*help/i) { load_si(); IRC::print "HELP:\n"; IRC::print "/si add to add a new blocker\n"; IRC::print "EG /si add girr\n"; IRC::print "/si save to save your current list and /si list to view it\n"; IRC::print "/si del n to delete an entry EG /si del 0 and /si clear to clear the lot\n"; return 1; } 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::print "/si help for help\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();