Skip to content

Instantly share code, notes, and snippets.

@jadiunr
Last active Jun 10, 2019
Embed
What would you like to do?
FF外から失礼する奴を粛清するやつ APIが一瞬で枯渇するので使えません
use strict;
use warnings;
use utf8;
use feature 'say';
use Net::Twitter;
my $api = Net::Twitter->new(
traits => [qw/API::RESTv1_1/],
consumer_key => $ENV{PURGER_TWITTER_CK},
consumer_secret => $ENV{PURGER_TWITTER_CS},
access_token => $ENV{PURGER_TWITTER_AT},
access_token_secret => $ENV{PURGER_TWITTER_ATS}
);
while(1) {
my $home = $api->home_timeline({count => 200});
for my $tweet (@$home) {
if ($tweet->{retweeted_status}) {
my $retweet = $tweet->{retweeted_status};
execute($retweet) if $retweet->{retweet_count} > 100;
} else {
execute($tweet) if $tweet->{retweet_count} > 100;
}
}
sleep(120);
}
sub execute {
my $tweet = shift;
my $search_tweets = $api->search({
q => 'to:'.$tweet->{user}{screen_name},
count => 200,
since_id => $tweet->{id}
})->{statuses};
return unless $search_tweets->[0];
my $replies = [grep { $_->{in_reply_to_status_id} eq $tweet->{id} } @$search_tweets];
return unless $replies->[0];
for my $reply (@$replies) {
next if check($tweet, $reply);
block($reply);
}
}
sub check {
my ($tweet, $reply) = @_;
my $rel_with_me = $api->show_relationship({
source_screen_name => $ENV{PURGER_TWITTER_SCREEN_NAME},
target_screen_name => $reply->{user}{screen_name}
})->{relationship}{source};
return 1 if $rel_with_me->{following} || $rel_with_me->{followed_by};
my $rel = $api->show_relationship({
source_screen_name => $tweet->{user}{screen_name},
target_screen_name => $reply->{user}{screen_name}
})->{relationship}{source};
return 1 if $rel->{following} || $rel->{followed_by};
return 0;
}
sub block {
my $reply = shift;
$api->create_block($reply->{user}{id});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment