Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ To use:
- Change to project directory and run `npm install`
- Install PM2 to keep it alive:
`npm install -g pm2`
- Create a /cookies directory
- Create a /logs directory
- Create an ecosystem.config.js file in the root of the project:

*ecosystem.config.js*
Expand All @@ -25,6 +27,7 @@ module.exports = {
{
name : 'InstagramBot',
script : 'app.js',
cron_restart: "0 0 * * *",
env: {
USERNAME: 'instagram_username',
PASSWORD: 'instagram_password',
Expand Down
21 changes: 15 additions & 6 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,24 @@ function shuffle(a) {
return a;
}

const likeAndFollowJob = nodeSchedule.scheduleJob('Like and follow', '0 0 7,13,18 * * * *', () => {
followCount = 0
likeCount = 0
setTimeout(likeAndFollow, 1000 * getRandomInt(60*60, 0))
const followMins = Math.floor(Math.random() * 59);
const followHour1 = Math.floor(Math.random() * ((11) - 6 + 1)) + 6;
const followHour2 = Math.floor(Math.random() * ((18) - 12 + 1)) + 12;
const followHour3 = Math.floor(Math.random() * ((23) - 19 + 1)) + 19;

let followTimes = '0 ' + followMins + ' ' + followHour1 + ',' + followHour2 + ',' + followHour3 + ' * * * *';
const likeAndFollowJob = nodeSchedule.scheduleJob('Like and follow', followTimes, () => {
followCount = 0
likeCount = 0
setTimeout(likeAndFollow, 1000 * getRandomInt(60 * 60, 0))
})

const unfollowJob = nodeSchedule.scheduleJob('Unfollow', '0 0 5 * * * *', unfollowNotFollowing)
const unfollowHours = Math.floor(Math.random() * (5 - 3 + 1)) + 3;
const unfollowMins = '0 ' + Math.floor(Math.random() * 59) + ' ' + unfollowHours + ' * * * *';
const unfollowJob = nodeSchedule.scheduleJob('Unfollow', unfollowMins, unfollowNotFollowing);

console.log('Like and follow next run', likeAndFollowJob.nextInvocation()._date.format('HH:mm DD/MM'))
console.log('Unfollow next run', unfollowJob.nextInvocation()._date.format('HH:mm DD/MM'))

likeAndFollow()
// likeAndFollow()
unfollowNotFollowing()
24 changes: 15 additions & 9 deletions lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ class InstagramBot {
this.storage = new Client.CookieFileStorage(__dirname + `/cookies/${username}.json`)
this.username = username
this.password = password
this.proxy = "http://username:password@your_proxy.com"
this.randomPause = randomPause
}

async _getSession () {
if (!this._session) {
this._session = await Client.Session.create(this.device, this.storage, this.username, this.password)
this._session = await Client.Session.create(this.device, this.storage, this.username, this.password, this.proxy)
}
return this._session
}
Expand Down Expand Up @@ -65,8 +66,9 @@ class InstagramBot {
})
if (notFollowingBack.length) {
const unfollowNumber = Math.ceil(notFollowingBack.length)
console.log('Numbers', followers.length, following.length,notFollowingBack.length, unfollowNumber)
for (let i = 0; i < unfollowNumber; i++) {

console.log('Numbers', 'Followers:', followers.length, 'Following:', following.length, 'About to Unfollow:', notFollowingBack.length, 'New Follow Total:', (following.length - unfollowNumber))
for (let i = 0; i < unfollowNumber; i++) {
const user = notFollowingBack[notFollowingBack.length - 1 - i]
if (user) {
try {
Expand All @@ -79,12 +81,16 @@ class InstagramBot {
}
}
}
// const nextUnfollow = getRandomInt(1000 * 60 * 3, 1000 * 60 * 7)
// const nextUnfollowMinutes = Math.floor(nextUnfollow / (1000 * 60))
// console.log(`Next unfollow in ${nextUnfollowMinutes} minutes (${moment().add(nextUnfollowMinutes, 'minutes').format('HH:mm')})`)
// await pausePromise(nextUnfollow) //Unfollow 1 every 30 minutes
// return this.unfollowNotFollowing() //loop back around and get a fresh list
}
const newfollows = following.length - notFollowingBack.length;
const numbers = moment().unix() + ' ' + followers.length + ' ' + newfollows;
const fs = require('fs');
fs.appendFile("logs/" + process.env.USERNAME + '.txt', numbers + '\n', (err) => {

if (err) throw err;

console.log('Info saved!');
});
}

async hashtag (hashtag) {
Expand Down Expand Up @@ -151,4 +157,4 @@ const pausePromise = (milliseconds) => new Promise((resolve, reject) => {
setTimeout(resolve, milliseconds)
})

module.exports = InstagramBot
module.exports = InstagramBot