Created
June 12, 2013 01:49
-
-
Save cwage/5762307 to your computer and use it in GitHub Desktop.
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 | |
$addaction = sub { | |
my $command = shift; | |
if ($command =~ s#^/ignore ## && length($command)) { | |
open(FILTERS, "</home/cwage/.ttytterfilters") or die $!; | |
my $filters = <FILTERS>; | |
close(FILTERS); | |
chomp($filters); | |
my @parts = split(/\|/, $filters); | |
if (grep(/$command/i, @parts)) | |
{ | |
print $stdout "User $command is already ignored.\n"; | |
return 0; | |
} | |
else | |
{ | |
print $stdout "Ignoring user $command.\n"; | |
push @parts, $command; | |
my $newstring = join '|', @parts; | |
open(FILTERS, ">/home/cwage/.ttytterfilters"); | |
print FILTERS $newstring; | |
close(FILTERS); | |
return 1; | |
} | |
} elsif ($command =~ s#^/unignore ## && length($command)) { | |
open(FILTERS, "</home/cwage/.ttytterfilters") or die $!; | |
my $filters = <FILTERS>; | |
close(FILTERS); | |
chomp($filters); | |
my @parts = split(/\|/, $filters); | |
if (grep(/$command/i, @parts)) | |
{ | |
print "Unignoring $command\n"; | |
@parts = grep !/$command/, @parts; | |
my $newstring = join '|', @parts; | |
open(FILTERS, ">/home/cwage/.ttytterfilters"); | |
print FILTERS $newstring; | |
close(FILTERS); | |
return 1; | |
} else | |
{ | |
print $stdout "User $command is not ignored.\n"; | |
} | |
} elsif ($command =~ /^\/listignore/) { | |
open(FILTERS, "</home/cwage/.ttytterfilters") or die $!; | |
my $filters = <FILTERS>; | |
close(FILTERS); | |
chomp($filters); | |
my @parts = split(/\|/, $filters); | |
print "Currently ignoring:\n"; | |
foreach (@parts) | |
{ | |
print; | |
print "\n"; | |
} | |
return 1; | |
} | |
return 0; | |
}; | |
$handle = sub { | |
open(FILTERS, "</home/cwage/.ttytterfilters") or die $!; | |
my $userfilter = <FILTERS>; | |
close(FILTERS); | |
chomp($userfilter); | |
my $ref = shift; | |
$ref->{'text'} =~ s/jesus/my penis/gi; | |
$ref->{'text'} =~ s/prayer/whiskey/gi; | |
my $text = &descape($ref->{'text'}); | |
return 0 if ($ref->{'user'}->{'screen_name'} =~ /$userfilter/i) || ($ref->{'text'} =~ /$userfilter/i); | |
return 0 if ($ref->{'user'}->{'screen_name'} =~ /TheCaitlinRose/) && ($ref->{'text'} =~ /cancer|astrology/i); | |
&defaulthandle($ref); | |
return 1; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment