Skip to content

Instantly share code, notes, and snippets.

@cwage
Created February 5, 2014 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cwage/8833858 to your computer and use it in GitHub Desktop.
Save cwage/8833858 to your computer and use it in GitHub Desktop.
#!/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);
return 0 if ($ref->{'text'} =~ /jack.*white/i);
&defaulthandle($ref);
return 1;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment