html/kblamehost.pl
1 #!/usr/bin/perl
2
3 use Irssi;
4 use Irssi::Irc;
5
6 $VERSION = "0.0.1";
7 %IRSSI = (
8 authors => 'Filippo \'godog\' Giunchedi',
9 contact => 'filippo\@esaurito.net',
10 name => 'kblamehost',
11 description => 'Kicks (and bans) people with >= 4 dots in theirs hostname',
12 license => 'GNU GPLv2 or later',
13 url => 'http://esaurito.net',
14 );
15
16 # TODO
17 # add ban support
18
19 # all settings are space-separated
20 Irssi::settings_add_str('misc','kblamehost_channels',''); # channels with kicklamehost enabled
21 Irssi::settings_add_str('misc','kblamehost_exclude',''); # regexps with hostnames excluded
22 Irssi::settings_add_str('misc','kblamehost_dots','4'); # dots >= an host will be marked as lame
23 Irssi::settings_add_str('misc','kblamehost_kickmsg','Lame host detected, change it please!'); # on-kick message
24 Irssi::settings_add_str('misc','kblamehost_ban','0'); # should we ban that lame host?
25
26 sub event_join
27 {
28 my ($channel, $nicksList) = @_;
29 my @nicks = @{$nicksList};
30 my $server = $channel->{'server'};
31 my $channelName = $channel->{name};
32 my $channel_enabled = 0;
33 my @channels = split(/ /,Irssi::settings_get_str('kblamehost_channels'));
34 my @excludes = split(/ /,Irssi::settings_get_str('kblamehost_exclude'));
35
36 foreach (@channels)
37 {
38 $channel_enabled = 1 if($_ eq $channelName);
39 }
40
41 foreach (@nicks)
42 {
43 my $hostname = substr($_->{host},index($_->{host},'@')+1);
44 my @dots = split(/\./,$hostname); # yes i know, it's the number on fields in
45 # hostname, but array counts from 0 so element's count is number of dots
46 my $is_friend = 0;
47
48 foreach $exclude (@excludes)
49 {
50 $is_friend = 1 if ($hostname =~ $exclude);
51 }
52
53 if( $#dots >= Irssi::settings_get_str('kblamehost_dots') && $channel_enabled == 1 && $is_friend == 0)
54 {
55 # Irssi::print("lamehost ($hostname) by $_->{nick} detected on $channelName, kicking...");
56 $server->command("kick $channelName $_->{nick} Irssi::settings_get_str('kblamehost_kickmsg')");
57 $server->command("ban $channelName $_->{nick}") if ( Irssi::settings_get_str('kblamehost_ban') );
58 }
59 }
60 }
61
62 Irssi::signal_add_last("massjoin", "event_join");