-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
executable file
·90 lines (72 loc) · 2.25 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env node
const lodash = require('lodash')
const Promise = require('bluebird')
const IgApiClient = require('instagram-private-api').IgApiClient
const ig = new IgApiClient()
var program = require('commander')
let session = null
const everyMinutes = 10
let intervalFunc = null
program
.version('0.1.0')
.option('-u, --username [username]', 'Username', '')
.option('-p, --password [password]', 'Password', '')
.parse( process.argv )
if( lodash.isEmpty( program.username ) || lodash.isEmpty( program.password ) ){
throw(new Error('Must supply -u {username} and -p {password}'))
}
ig.state.generateDevice(program.username)
let pendingCount = 0
async function DoApprovals(){
const pendFriend = ig.feed.pendingFriendships(session.pk)
const pendFriendItems = await pendFriend.items()
console.log('Awaiting Approval: ', pendFriendItems.length)
return Promise.mapSeries(pendFriendItems, async ( friend ) => {
console.log('Approving: ', friend.username)
const body = await ig.friendship.approve(friend.pk)
return Promise.delay( randomIntFromInterval(350, 1450) )
}).then(() => {
if( pendFriendItems.length != 0 ){
return DoApprovals()
}
setTimeoutContinue()
}).catch(( err ) => {
console.log('Do approvals error:', err)
console.log('Waiting 11sec before starting again...')
return Promise.delay(11500).then(() => {
console.log('Starting again...')
DoApprovals()
})
})
}
function randomIntFromInterval(min, max) { // min and max included
return Math.floor(Math.random() * (max - min + 1) + min);
}
function setTimeoutContinue(){
clearTimeout( intervalFunc )
intervalFunc = setTimeout(() => {
console.log('interval')
DoApprovals().catch(( err ) => {
console.log('Set timeouts error:', err)
setTimeoutContinue()
})
}, 1000 * 60 * everyMinutes )
}
// Login and go
async function main(){
await ig.simulate.preLoginFlow()
ig.account.login(program.username, program.password)
.then(( ses ) => {
console.log(`Logged In! ${ses.username} - ${ses.full_name}`)
process.nextTick(async () => await ig.simulate.postLoginFlow())
session = ses
DoApprovals().catch(( err ) => {
console.log('Create sessions error:', err)
setTimeoutContinue()
})
})
.catch(( err ) => {
console.log('err:', err)
})
}
main()