]> git.donarmstrong.com Git - bin.git/blob - parse_banlist
added get_tweekn, parsebanlist and modified svnfix for gaim
[bin.git] / parse_banlist
1 #! /usr/bin/perl
2
3 use warnings;
4 use strict;
5
6
7 use IO::File;
8 use Getopt::Std;
9
10 my $conf = {bans           => 'bans.txt',
11             bans_to_remove => 'bans_to_remove.txt',
12             bans_to_keep   => 'bans_to_keep.txt',
13             minimum_age    => 1209600, # two weeks
14             max_ubans      => 4,
15            };
16
17 my $options = {};
18 getopt('b:k:r:a:',$options);
19
20 $conf->{bans} = $options->{b} || $conf->{bans};
21 $conf->{bans_to_remove} = $options->{r} || $conf->{bans_to_remove};
22 $conf->{bans_to_keep} = $options->{k} || $conf->{bans_to_keep};
23 $conf->{minimum_age} = $options->{a} || $conf->{minimum_age};
24
25 my $bans_fh = new IO::File $conf->{bans}, 'r' or die "Unable to open file $conf->{bans} for reading: $!";;
26
27 my $bans_r_fh = new IO::File $conf->{bans_to_remove}, 'w' or
28      die "Unable to open file $conf->{bans_to_remove} for writing: $!";
29
30 my $bans_k_fh = new IO::File $conf->{bans_to_keep}, 'w' or
31      die "Unable to open file $conf->{bans_to_keep} for writing: $!";
32
33 my @bans_to_remove;
34
35 while (<$bans_fh>) {
36      # pull the ban and the times.
37      print {$bans_k_fh} $_ and next unless my ($channel, $banmask, $time) = 
38           $_ =~ /(\#\w+)\:\s+ban\s+([\w\d\*\@\%\!\-\_\.]+)\s+\[by\s*.*?\,\s+(\d+)\s+secs/;
39      print {$bans_k_fh} $_ and next unless $time > $conf->{minimum_age};
40
41      # Ignore bans against specific users.
42      print {$bans_k_fh} $_ and next if $banmask =~ /^\%?\w/;
43
44      # Ignore wide bans
45      print {$bans_k_fh} $_ and next if $banmask =~ /\*\!.*?\@.*\*.*/;
46
47      push @bans_to_remove, $banmask;
48 }
49
50
51 while (my @unbans = splice(@bans_to_remove,0,$conf->{max_ubans})) {
52      print {$bans_r_fh} q(/mode -), q(b) x ($#unbans+1), q( ), join(' ',@unbans);
53      print {$bans_r_fh} qq(\n);
54 }