Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto follower functionality #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion src/tweet.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,56 @@ function tweetNow(status){
});
}

/**
*
* @description it checks the list of followers and follows them if we have not already followed them
*/
function followBack(){
// Get the list of friends (accounts which we follow)
client.get('friends/list', function(error, friendsResult) {
if (friendsResult) {
const friendIdList = [];
friendsResult.users.forEach((friend) => {
friendIdList.push(friend.screen_name);
});

// Get the list of followers
client.get('followers/list', function(error, followerResult) {
if (followerResult) {
followerResult.users.forEach((follower) => {
// If we are not already following the account
if (!friendIdList.includes(follower.id)) {
client.post('friendships/create', {
screen_name: follower.screen_name
}, function(error, createResult) {
if (createResult) {
console.log(`Follow back success for ${follower.id} - ${follower.screen_name}`);
}
if (error) {
console.log(`Follow back failed for ${follower.id} - ${follower.screen_name}`);
}
});
}
});
}
if (error) {
console.log(`Error occured while getting followers!`);
}
});
}
if (error) {
console.log(`Error occured while getting friends!`);
}
});

}

/**
* @description API to fetch random images
*/
var imageURL = 'https://source.unsplash.com/featured/?motivation';

// encode the image to base64
encodeImage(imageURL);
encodeImage(imageURL);

// followBack();