summaryrefslogtreecommitdiffstats
path: root/modules/classes.pl
blob: 74b28990097ee7c5091bb9114a5b64246b9e22f2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
use strict;
use warnings;
use Data::Dumper;
#package Classes;

sub Classes::dnsbl {
  our (%aonx, $id, %dct, $event, $chan, $rev);
    if (defined $rev) {
      my $iaddr = hostip( "$rev$aonx{$id}{content}" );
      my @dnsbl = unpack( 'C4', $iaddr ) if defined $iaddr;
      $dct{$id} = $aonx{$id} if (@dnsbl);
    }
}

sub Classes::floodqueue {
  our (%aonx, $id, %dct, $event, $chan);
  my @cut=split(/:/, $aonx{$id}{content});
  $dct{$id} = $aonx{$id} if ( flood_add( $chan, $id, $event->{host}, int($cut[1]) ) == int($cut[0]) );
}

sub Classes::nickspam {
  our (%aonx, $id, %dct, $event, $chan);
     my @cut = split(/:/, $aonx{$id}{content});
     if ( length $event->{args}->[0] >= int($cut[0]) ) {
       %_ = map { $_=>$_ } lc keys %{$::sc{lc $chan}{users}};
       my @uniq = grep( $_{$_}, split( / /, lc $event->{args}->[0]) );
       $dct{$id} = $aonx{$id} if ( $#{ @uniq } >= int($cut[1]) );
     }
}

my %cf=();
my %bs=();

sub Classes::splitflood {
  our (%aonx, $id, %dct, $event, $chan);
  my $text;
  my @cut = split(/:/, $aonx{$id}{content});
  $cf{$id}{timeout}=int($cut[1]);
  if ($event->{type} =~ /^(public|notice|part|caction)$/) {
    $text=$event->{args}->[0];
  }
  return unless defined($text);
  return unless length($text) >= 10;
  if (defined($bs{$id}{$text}) && (time <= $bs{$id}{$text} + 600)) {
    $dct{$id}=$aonx{$id};
    return;
  }
  push( @{$cf{$id}{$chan}{$text}}, time );
  foreach my $nid ( keys %cf ) {
    foreach my $xchan ( keys %{$cf{$nid}} ) {
      next if $xchan eq 'timeout';
      foreach my $host ( keys %{$cf{$nid}{$xchan}} ) {
        next unless defined $cf{$nid}{$xchan}{$host}[0];
        while ( time >= $cf{$nid}{$xchan}{$host}[0] + $cf{$nid}{'timeout'} ) {
          last if ( $#{ $cf{$nid}{$xchan}{$host} } == 0 );
          shift ( @{$cf{$nid}{$xchan}{$host}} );
        }
      }
    }
  }
  if ( $#{ @{$cf{$id}{$chan}{$text}}}+1 == int($cut[0]) ) {
    $dct{$id}=$aonx{$id};
    $bs{$id}{$text} = time;
  }
} 

sub Classes::re {
  our (%aonx, $id, %dct, $event, $chan);
     my $match = $event->{args}->[0];
     $match = $event->{nick} if ($event->{type} eq 'join');
     if ( (defined $aonx{$id}{nocase}) && ($aonx{$id}{nocase}) ) {
       $dct{$id}=$aonx{$id} if ($match =~ /$aonx{$id}{content}/i);
     }
     else {
       $dct{$id}=$aonx{$id} if ($match =~ /$aonx{$id}{content}/);
     }
}

sub Classes::nick {
  our (%aonx, $id, %dct, $event, $chan);
  if ( lc $event->{nick} eq lc $aonx{$id}{content} ) {
    $dct{$id} = $aonx{$id};
  }
}

sub Classes::ident {
  our (%aonx, $id, %dct, $event, $chan);
  if ( lc $event->{user} eq lc $aonx{$id}{content} ) {
    $dct{$id} = $aonx{$id};
  }
}

sub Classes::host {
  our (%aonx, $id, %dct, $event, $chan);
  if ( lc $event->{host} eq lc $aonx{$id}{content} ) {
    $dct{$id} = $aonx{$id};
  }
}

sub Classes::killsub {
  undef &Classes::dnsbl;
  undef &Classes::floodqueue;
  undef &Classes::nickspam;
  undef &Classes::re;
}
#$VAR1 = bless( {
#                 'to' => [
#                           '##asb-testing'
#                         ],
#                 'format' => 'mode',
#                 'from' => 'ChanServ!ChanServ@services.',
#                 'user' => 'ChanServ',
#                 'args' => [
#                             '+o',
#                             'AntiSpamMetaBeta',
#                             ''
#                           ],
#                 'nick' => 'ChanServ',
#                 'type' => 'mode',
#                 'userhost' => 'ChanServ@services.',
#                 'host' => 'services.'
#               }, 'Net::IRC::Event' );

return 1;