Created
October 21, 2009 01:03
-
-
Save rupa/214760 to your computer and use it in GitHub Desktop.
ENFORCEMENT BOT FOR CAPSLOCKDAY 10/22
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use POSIX; | |
use IO::Socket; | |
#fork && exit; | |
setsid; | |
$nick = "CAPSLOCKENFORCEMENTBOT"; | |
if( $ARGV[0] ) { $channel = $ARGV[0] } | |
if( $ARGV[1] ) { $server = $ARGV[1] } | |
if( !$ARGV[0] || !$ARGV[1] ) { | |
print "need channel and server\n"; | |
exit; | |
} | |
$pass = time(); | |
$user = "$nick $nick.org * :$nick"; | |
# open connection | |
$sock = new IO::Socket::INET( | |
PeerAddr => $server, | |
PeerPort => 6667, | |
Proto => 'tcp' | |
) or die "Can't connect\n"; | |
print $sock "PASS $pass\r\n"; | |
print $sock "USER $user\r\n"; | |
print $sock "NICK $nick\r\n"; | |
while( $input = <$sock> ) { | |
if( $input =~ /^PING(.*)$/i ) { | |
print $sock "PONG $1\r\n"; | |
} elsif ($input =~ /004/) { | |
last; | |
} elsif ($input =~ /433/) { | |
die "nick is already in use."; | |
} | |
} | |
print $sock "JOIN $channel\r\n"; | |
# monitor input | |
while( $input = <$sock> ) { | |
chop $input; | |
if( $input =~ /^PING(.*)$/i ) { | |
print $sock "PONG $1\r\n"; | |
} | |
@in = split(" ", $input); | |
$host = shift(@in); | |
@them = split("!", $host); | |
$theirnick = $them[0]; | |
$theirnick =~ s/^://; | |
$type = shift(@in); | |
$chan = shift(@in); | |
$data = join(" ", @in); | |
$data =~ s/^://; | |
if( $type eq "KICK" ) { | |
print $sock "JOIN $channel\r\n"; | |
} elsif( ($type eq "PRIVMSG") && ($chan ne $nick) ) { | |
enforce(); | |
} | |
print "$input\n"; | |
} | |
sub enforce { | |
# allow links | |
return if $data =~ /https?:/; | |
return if $data =~ /ftp:/; | |
# exceptions for bots and commands and lulz and stuff | |
return if $data =~ /^!/; | |
return if $data =~ /^quote /; | |
return if $data =~ /^twit /; | |
return if $theirnick =~ /^LRRR$/i; | |
return if $theirnick =~ /^GIR$/i; | |
return if $theirnick =~ /^TUMBLR$/i; | |
return if $data =~ /newfags can't/; | |
return if $data =~ /e\.e\. cummings/; | |
if( $yrnick =~ /[a-z]/ ) { | |
print $sock "KICK $channel $theirnick NICK IS NOT UPPERCASE!\r\n"; | |
return; | |
} | |
if( $data =~ /[a-z]/ ) { | |
print $sock "KICK $channel $theirnick CAPSLOCK VIOLATION!\r\n"; | |
return; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment