forked from rknell/instagrambot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
84 lines (73 loc) · 2.75 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
const InstagramBot = require('./lib')
const nodeSchedule = require('node-schedule')
let likeCount = 0
let followCount = 0
let maxLike = 100
let maxFollow = 60
const HASHTAGS = process.env.HASHTAG.split(',')
const unfollowNotFollowing = async () => {
const instagramBot = new InstagramBot(process.env.USERNAME, process.env.PASSWORD)
try {
await instagramBot.unfollowNotFollowing()
} catch (e) {
console.error(e)
} finally {
console.log('Unfollow finished, next run', unfollowJob.nextInvocation()._date.format('HH:mm DD/MM'))
}
}
const likeAndFollow = async () => {
const instagramBot = new InstagramBot(process.env.USERNAME, process.env.PASSWORD)
randomLikeAndFollowCounts()
shuffle(HASHTAGS)
try {
for (let hashtag of HASHTAGS) {
const results = await instagramBot.likeAndFollowHashtag(hashtag, maxLike - likeCount, maxFollow - followCount)
likeCount += results.likeCount
followCount += results.followCount
}
} catch (e) {
console.error(e)
} finally {
if (likeCount < maxLike && followCount < maxFollow) {
console.log('Sleeping', maxLike - likeCount, maxFollow - followCount)
await instagramBot.randomPause(60 * 3)
likeAndFollow()
} else {
console.log('Like and follow finished, next run', likeAndFollowJob.nextInvocation()._date.format('HH:mm DD/MM'))
}
}
}
function getRandomInt (min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min
}
function randomLikeAndFollowCounts () {
maxLike = getRandomInt(140,60)
maxFollow = getRandomInt(40, 80)
}
function shuffle(a) {
var j, x, i;
for (i = a.length - 1; i > 0; i--) {
j = Math.floor(Math.random() * (i + 1));
x = a[i];
a[i] = a[j];
a[j] = x;
}
return a;
}
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 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()
unfollowNotFollowing()