-
Notifications
You must be signed in to change notification settings - Fork 0
/
coreconfig.go
324 lines (214 loc) · 4.89 KB
/
coreconfig.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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
package coreconfig
import (
"sync"
"time"
"github.com/dekoch/gouniversal/shared/api/instaclient"
"github.com/dekoch/gouniversal/shared/hashstor"
)
type CoreConfig struct {
CoreUUID string
CheckInterv int // minutes (0=disabled)
FollowCnt int
UnfollowCnt int
UnfollowAfter int // hours
Tags []string
AddNewTags bool
FollowBusinessAccount bool
FollowVerified bool
FollowPrivate bool
MaxFollow int // (0=disabled)
MaxFollowedBy int // (0=disabled)
Cookies instaclient.Cookies
TagQueryHash hashstor.HashStor
MediaQueryHash hashstor.HashStor
FollowTime time.Time
UnfollowTime time.Time
}
var mut sync.RWMutex
func (hc *CoreConfig) LoadDefaults() {
hc.CheckInterv = 25
hc.FollowCnt = 15
hc.UnfollowCnt = 15
hc.UnfollowAfter = 2
hc.Tags = append(hc.Tags, "")
hc.AddNewTags = false
hc.FollowBusinessAccount = false
hc.FollowVerified = false
hc.FollowPrivate = false
hc.MaxFollow = 0
hc.MaxFollowedBy = 1000
hc.TagQueryHash.Add("")
hc.MediaQueryHash.Add("")
hc.FollowTime = time.Now().AddDate(-1, 0, 0)
hc.UnfollowTime = time.Now().AddDate(-1, 0, 0)
}
func (hc *CoreConfig) LoadConfig() error {
hc.TagQueryHash.Init()
hc.MediaQueryHash.Init()
return nil
}
func (hc *CoreConfig) SetCoreUUID(uid string) {
mut.Lock()
defer mut.Unlock()
hc.CoreUUID = uid
}
func (hc *CoreConfig) GetCoreUUID() string {
mut.RLock()
defer mut.RUnlock()
return hc.CoreUUID
}
func (hc *CoreConfig) SetCheckInterval(minutes int) {
mut.Lock()
defer mut.Unlock()
hc.CheckInterv = minutes
}
func (hc *CoreConfig) GetCheckInterval() time.Duration {
mut.RLock()
defer mut.RUnlock()
return time.Duration(hc.CheckInterv) * time.Minute
}
func (hc *CoreConfig) SetFollowCount(cnt int) {
mut.Lock()
defer mut.Unlock()
hc.FollowCnt = cnt
}
func (hc *CoreConfig) GetFollowCount() int {
mut.RLock()
defer mut.RUnlock()
return hc.FollowCnt
}
func (hc *CoreConfig) SetUnfollowCount(cnt int) {
mut.Lock()
defer mut.Unlock()
hc.UnfollowCnt = cnt
}
func (hc *CoreConfig) GetUnfollowCount() int {
mut.RLock()
defer mut.RUnlock()
return hc.UnfollowCnt
}
func (hc *CoreConfig) SetUnfollowAfter(hours int) {
mut.Lock()
defer mut.Unlock()
hc.UnfollowAfter = hours
}
func (hc *CoreConfig) GetUnfollowAfter() time.Duration {
mut.RLock()
defer mut.RUnlock()
return time.Duration(hc.UnfollowAfter) * time.Hour
}
func (hc *CoreConfig) SetTags(tags []string) {
mut.Lock()
defer mut.Unlock()
hc.Tags = tags
}
func (hc *CoreConfig) GetTags() []string {
mut.RLock()
defer mut.RUnlock()
return hc.Tags
}
func (hc *CoreConfig) SetAddNewTags(b bool) {
mut.Lock()
defer mut.Unlock()
hc.AddNewTags = b
}
func (hc *CoreConfig) GetAddNewTags() bool {
mut.RLock()
defer mut.RUnlock()
return hc.AddNewTags
}
func (hc *CoreConfig) AddTags(tags []string) {
mut.Lock()
defer mut.Unlock()
for i := range tags {
found := false
for ii := range hc.Tags {
if tags[i] == hc.Tags[ii] {
found = true
}
}
if found == false {
hc.Tags = append(hc.Tags, tags[i])
}
}
}
func (hc *CoreConfig) SetFollowBusinessAccount(b bool) {
mut.Lock()
defer mut.Unlock()
hc.FollowBusinessAccount = b
}
func (hc *CoreConfig) GetFollowBusinessAccount() bool {
mut.RLock()
defer mut.RUnlock()
return hc.FollowBusinessAccount
}
func (hc *CoreConfig) SetFollowVerified(b bool) {
mut.Lock()
defer mut.Unlock()
hc.FollowVerified = b
}
func (hc *CoreConfig) GetFollowVerified() bool {
mut.RLock()
defer mut.RUnlock()
return hc.FollowVerified
}
func (hc *CoreConfig) SetFollowPrivate(b bool) {
mut.Lock()
defer mut.Unlock()
hc.FollowPrivate = b
}
func (hc *CoreConfig) GetFollowPrivate() bool {
mut.RLock()
defer mut.RUnlock()
return hc.FollowPrivate
}
func (hc *CoreConfig) SetMaxFollow(n int) {
mut.Lock()
defer mut.Unlock()
hc.MaxFollow = n
}
func (hc *CoreConfig) GetMaxFollow() int {
mut.RLock()
defer mut.RUnlock()
return hc.MaxFollow
}
func (hc *CoreConfig) SetMaxFollowedBy(n int) {
mut.Lock()
defer mut.Unlock()
hc.MaxFollowedBy = n
}
func (hc *CoreConfig) GetMaxFollowedBy() int {
mut.RLock()
defer mut.RUnlock()
return hc.MaxFollowedBy
}
func (hc *CoreConfig) SetCookies(co instaclient.Cookies) {
mut.Lock()
defer mut.Unlock()
hc.Cookies = co
}
func (hc *CoreConfig) GetCookies() instaclient.Cookies {
mut.RLock()
defer mut.RUnlock()
return hc.Cookies
}
func (hc *CoreConfig) SetFollowTime(t time.Time) {
mut.Lock()
defer mut.Unlock()
hc.FollowTime = t
}
func (hc *CoreConfig) GetFollowTime() time.Time {
mut.RLock()
defer mut.RUnlock()
return hc.FollowTime
}
func (hc *CoreConfig) SetUnfollowTime(t time.Time) {
mut.Lock()
defer mut.Unlock()
hc.UnfollowTime = t
}
func (hc *CoreConfig) GetUnfollowTime() time.Time {
mut.RLock()
defer mut.RUnlock()
return hc.UnfollowTime
}