-
Notifications
You must be signed in to change notification settings - Fork 1
/
unfollower.go
307 lines (235 loc) · 6.27 KB
/
unfollower.go
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
/* unfollower
Instagram Bot - autofollow, like, comment dan unfollow not followback (c) Free Angel - [email protected]
please subscribe to my channel :
https://www.youtube.com/channel/UC15iFd0nlfG_tEBrt6Qz1NQ
*/
package main
import (
"fmt"
"io/ioutil"
"os"
"strings"
"time"
"github.com/jimlawless/whereami"
)
func unfollower_main() {
fmt.Println("Hello World!")
}
type _UNFOLLOWER struct {
prev, next *_UNFOLLOWER
id int64
date int64
}
type cUnfollower struct {
enable bool
chance int
min_node int
max_node int
search_interval int64
follow_back_expired int64 // 0 = disable
post_activity_expired int64 // 0 = disable
max_unfollow_in_session int
max_unfollow_in_day int
unfollow_interval int64
debug bool
exception_usernames []string
// counter
last_search int64
last_unfollow int64
count int
unfollow_count_in_session int
unfollow_count_in_day int
last_max_id string
// classes
Followings *cInvData
following_max_id_fname string
}
func (U *cUnfollower) Initialize() {
U.following_max_id_fname = "./following_last_max_id.txt"
section, err := conf.Section("unfollower")
if err != nil {
mylog(whereami.WhereAmI(), err)
halt()
}
U.enable = section.ValueOf("enable") == "1"
if !U.enable {
mylog(whereami.WhereAmI(), "Unfollower is OFF")
return
}
U.min_node = strToInt(section.ValueOf("min_node"))
U.max_node = strToInt(section.ValueOf("max_node"))
U.chance = strToInt(section.ValueOf("chance"))
if (U.chance < 1) || (U.chance > 100) {
U.chance = 75
mylog(whereami.WhereAmI(), "invalid chance value, set to default 75 %")
}
U.search_interval = strToInt64(section.ValueOf("search_interval"))
if U.search_interval < 30 {
mylog(whereami.WhereAmI(), "search_interval too fast, set to default 30 minutes")
U.search_interval = 30
}
U.search_interval = U.search_interval * 60
U.follow_back_expired = strToInt64(section.ValueOf("follow_back_expired"))
U.follow_back_expired = U.follow_back_expired * 3600 * 24
U.post_activity_expired = strToInt64(section.ValueOf("post_activity_expired"))
U.post_activity_expired = U.post_activity_expired * 3600 * 24
U.max_unfollow_in_session = strToInt(section.ValueOf("max_unfollow_in_session"))
U.max_unfollow_in_day = strToInt(section.ValueOf("max_unfollow_in_day"))
U.unfollow_interval = strToInt64(section.ValueOf("unfollow_interval"))
U.unfollow_interval = U.unfollow_interval * 60
U.debug = section.ValueOf("debug") == "1"
U.count = 0
U.unfollow_count_in_session = 0
U.unfollow_count_in_day = 0
ts := strings.Split(section.ValueOf("exception_usernames"), ",")
for _, s := range ts {
if s != "" {
U.exception_usernames = append(U.exception_usernames, s)
}
}
if section.ValueOf("run_on_start") != "1" {
U.last_search = time.Now().Unix()
}
// classes
U.Followings = new(cInvData)
U.Followings.Initialize()
U.Followings.fname = "./followings.txt"
U.Followings.load()
U.Followings.ExpiredSecs = U.follow_back_expired
U.Followings.autosave = true
U._load_last_max_id()
}
func (U *cUnfollower) _load_last_max_id() {
if !IsFileExists(U.following_max_id_fname) {
U.last_max_id = ""
return
}
f, err := os.Open(U.following_max_id_fname)
if err != nil {
mylog(whereami.WhereAmI(), err)
return
}
defer f.Close()
b, err := ioutil.ReadAll(f)
U.last_max_id = string(b)
}
func (U *cUnfollower) _save_last_max_id() {
f, err := os.Create(U.following_max_id_fname)
if err != nil {
mylog(whereami.WhereAmI(), err)
return
}
f.WriteString(U.last_max_id)
f.Close()
}
func (U *cUnfollower) _is_exception_names(username string) bool {
for _, s := range U.exception_usernames {
if s == username {
return true
}
}
return false
}
func (U *cUnfollower) new_session() {
U.unfollow_count_in_session = 0
}
func (U *cUnfollower) new_day() {
U.unfollow_count_in_day = 0
}
func (U *cUnfollower) _unfollow_not_follow_back(CurTime int64) bool {
if U.follow_back_expired == 0 {
return false
}
if U.unfollow_count_in_session >= U.max_unfollow_in_session {
return false
}
if U.unfollow_count_in_day >= U.max_unfollow_in_day {
return false
}
if CurTime-U.last_unfollow < U.unfollow_interval {
return false
}
res := U.Followings.GetOneExpired(CurTime)
if res == nil {
return false
}
U.last_unfollow = CurTime
// get friendship status
fr, err := Instagram.UserFriendShip(res.id)
if err != nil {
mylog(whereami.WhereAmI(), err)
U.Followings.del(res.id)
// hanya utk menandai, jangan lakukan process lain
return true
}
if (fr.Following) && (!fr.FollowedBy) {
U.unfollow_count_in_session++
U.unfollow_count_in_day++
_, err = Instagram.UnFollow(res.id)
if err != nil {
mylog(whereami.WhereAmI(), err)
} else {
s := intToStr(U.unfollow_count_in_session) + ":" + intToStr(U.max_unfollow_in_session) +
" - " + intToStr(U.unfollow_count_in_day) + ":" + intToStr(U.max_unfollow_in_day)
mylog(whereami.WhereAmI(), "Unfollowed (Not Followback):", res.id, s)
}
}
// delete node
U.Followings.del(res.id)
return true
}
func (U *cUnfollower) _search(CurTime int64) bool {
if U.count > U.min_node {
// there're still node waiting for process, just dont search
return false
}
if CurTime-U.last_search < U.search_interval {
return false
}
if !getChance(U.chance) {
return false
}
U.last_search = CurTime
// searching unfollower
user, err := Instagram.SelfUserFollowing(U.last_max_id)
if err != nil {
mylog(whereami.WhereAmI(), err)
return true
}
if len(user.Users) < 1 {
mylog(whereami.WhereAmI(), "No Following Last")
U.last_max_id = ""
return true
}
U.last_max_id = user.NextMaxID
i := 0
for _, u := range user.Users {
if U._is_exception_names(u.Username) {
continue
}
// check for auto follow
b := false
if AutoFollow != nil {
b = AutoFollow.Followings.find(u.ID) != nil
}
if !b {
if U.Followings.add(u.ID, CurTime, true) {
i++
}
}
}
if U.Followings.modified {
U.Followings.save()
}
U._save_last_max_id()
if i > 0 {
mylog(whereami.WhereAmI(), "Added Following :", i)
}
return true
}
func (U *cUnfollower) execute(CurTime int64) bool {
if U._unfollow_not_follow_back(CurTime) {
return true
}
return U._search(CurTime)
}