Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Blunble Bot for Twitter
<?
//
// BLUNBLE BOT (by @levelsio)
//
// "Blunble" is Korean internet slang for [BL]ock [UNBL]ock
// If you block and unblock somebody on Twitter, they stop following you.
// It's a polite way of getting rid of trolls without permanently blocking
// because blocking usually results in more anger and more trolling.
//
// WHAT THIS SCRIPT DOES:
//
// 1) Gets your muted accounts list (max 200 users)
// 2) Checks if they follow you
// 2) Blocks and unblocks (or blunbles) each account (and then waits 2 minutes
// due to rate limiting)
// 4) Blunbling auto unfollows them from your account
//
// THIS LETS YOU:
// 1) Mute trolls on Twitter
// 2) And they'll then automatically stop following you when the script runs
//
// HOW TO INSTALL:
//
// 1) You need a server with PHP
// 2) You need the TwitterOAuth library from https://github.com/abraham/twitteroauth
// 3) Add your consumer key, consumer secret, user token and user secret from Twitter
// see how to here: https://themepacific.com/how-to-generate-api-key-consumer-token-access-key-for-twitter-oauth/994/
// 4) Set it up as a cron that runs daily (or more) like this: @daily blunble.php
//
// Note:
// * This will keep blocking/unblocking your entire mute list every day
//
// MIT licensed
$consumer_key='';
$consumer_secret='';
$user_token='';
$user_token_secret='';
error_reporting(E_ERROR);
require(__DIR__.'/twitteroauth/autoload.php');
use Abraham\TwitterOAuth\TwitterOAuth;
if($connection = new TwitterOAuth($consumer_key, $consumer_secret, $user_token, $user_token_secret)) {
}
else {
exit();
}
$self = $connection->get("account/verify_credentials");
$self=json_decode(json_encode($self),true);
$selfId=$self['id'];
if(!$response=$connection->get('mutes/users/list',array('count'=>200)) {
echo 'Error';
exit();
}
$mutedUsers=json_decode(json_encode($response),true)['users'];
if(empty($mutedUsers)) {
exit;
}
// <blunble users>
foreach($mutedUsers as $user) {
echo "\n\n";
echo "Checking if user @".$user['screen_name']." is following: ";
$response = $connection->get('friendships/show',array(
'source_id' => $user['id'],
'target_id' => $selfId
));
$response=json_decode(json_encode($response),true);
if(!$response['relationship']['target']['followed_by']) {
echo 'Nope!';
echo "\n\n";
}
else {
echo "Yes!";
echo "\n\n";
echo "Blocking user @".$user['screen_name'].": ";
$response = $connection->post('blocks/create',array(
'user_id' => $user['id']
));
// $response=json_decode(json_encode($response),true);
// echo json_encode($response);
echo "\n\n";
echo "Unblocking user @".$user['screen_name'].": ";
$response = $connection->post('blocks/destroy',array(
'user_id' => $user['id']
));
// $response=json_decode(json_encode($response),true);
// echo json_encode($response);
// sleep for 2 minutes
echo "Sleeping for 2 minutes";
echo "\n\n";
sleep(120);
}
// sleep for 10 seconds
echo "Sleeping for 10 seconds";
echo "\n\n";
sleep(10);
}
// </blunble users>
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment