instabot 0.1.81 → 0.1.90

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,62 +1,62 @@
1
- module Login
2
- def login(username = '', password = '')
3
- if @login_mode == :manual
4
- username = username.to_s
5
- password = password.to_s
6
- else
7
- username = options[:username]
8
- password = options[:password]
9
- end
10
-
11
- log('trying to login', 'LOGIN')
12
- puts '[+] '.cyan + "Trying to login into [#{username}] account"
13
- login_page = @agent.get('https://www.instagram.com/accounts/login/?force_classic_login')
14
- page_form = login_page.forms.last
15
- page_form.username = username
16
- page_form.password = password
17
- page = page_form.submit
18
-
19
- if page.code == '200' && page.uri.to_s != 'https://www.instagram.com/accounts/login/?force_classic_login' && !page.uri.to_s.include?('challenge')
20
- @login_status = true
21
- log('successfully logged in', 'LOGIN')
22
- puts '[+] '.cyan + 'Successfully logged in'.green.bold
23
- else
24
- @login_status = false
25
- if page.uri.to_s.include?('challenge')
26
- puts '[-] '.cyan + 'Your account needs veryfication or it has been banned from instagram'.red.bold
27
- else
28
- puts '[-] '.cyan + 'Invalid username or password'.red.bold
29
- end
30
- check_login_status
31
- end
32
-
33
- rescue Exception => e
34
- log("an error detected: #{e.class} #{e} #{e.backtrace}", 'LOGIN')
35
- @login_status = false
36
- puts '[-] '.cyan + "#{e.class} #{e.message}\n check out the log file for full trace ".red
37
- exit
38
- end
39
-
40
- def logout
41
- log('trying to logout', 'LOGIN')
42
- puts '[+] '.cyan + 'Trying to logging out'
43
- set_mechanic_data
44
- @agent.get('https://www.instagram.com/accounts/logout/')
45
- @logout_status = true
46
- log('successfully logged out', 'LOGIN')
47
- puts '[+] '.cyan + 'Successfully logged out'
48
- end
49
-
50
- def check_login_status(_mode = :default)
51
- puts '[+] '.cyan + 'Checking login status' if @login_mode != :manual
52
- log('checking loging status', 'LOGIN')
53
- if @login_status
54
- return true
55
- else
56
- puts "[-] [##{@login_counter}] ".cyan + "You're not logged in (or it is an error with the request)\t[TRYING AGAIN]".red.bold
57
- exit! if @login_counter == 3
58
- @login_counter += 1
59
- login
60
- end
61
- end
62
- end
1
+ module Login
2
+ def login(username = '', password = '')
3
+ if @login_mode == :manual
4
+ username = username.to_s
5
+ password = password.to_s
6
+ else
7
+ username = options[:username]
8
+ password = options[:password]
9
+ end
10
+
11
+ log('trying to login', 'LOGIN')
12
+ puts '[+] '.cyan + "Trying to login as [#{username}]"
13
+ login_page = @agent.get('https://www.instagram.com/accounts/login/?force_classic_login')
14
+ page_form = login_page.forms.last
15
+ page_form.username = username
16
+ page_form.password = password
17
+ page = page_form.submit
18
+
19
+ if page.code == '200' && page.uri.to_s != 'https://www.instagram.com/accounts/login/?force_classic_login' && !page.uri.to_s.include?('challenge')
20
+ @login_status = true
21
+ log('successfully logged in', 'LOGIN')
22
+ puts '[+] '.cyan + 'Successfully logged in'.green.bold
23
+ else
24
+ @login_status = false
25
+ if page.uri.to_s.include?('challenge')
26
+ puts '[-] '.cyan + 'Your account needs veryfication or it has been banned from instagram'.red.bold
27
+ else
28
+ puts '[-] '.cyan + 'Invalid username or password'.red.bold
29
+ end
30
+ check_login_status
31
+ end
32
+
33
+ rescue Exception => e
34
+ log("an error detected: #{e.class} #{e} #{e.backtrace}", 'LOGIN')
35
+ @login_status = false
36
+ puts '[-] '.cyan + "#{e.class} #{e.message}\n check out the log file for full trace ".red
37
+ exit
38
+ end
39
+
40
+ def logout
41
+ log('trying to logout', 'LOGIN')
42
+ puts '[+] '.cyan + 'Trying to logging out'
43
+ set_mechanic_data
44
+ @agent.get('https://www.instagram.com/accounts/logout/')
45
+ @logout_status = true
46
+ log('successfully logged out', 'LOGIN')
47
+ puts '[+] '.cyan + 'Successfully logged out'
48
+ end
49
+
50
+ def check_login_status(_mode = :default)
51
+ puts '[+] '.cyan + 'Checking login status' if @login_mode != :manual
52
+ log('checking loging status', 'LOGIN')
53
+ if @login_status
54
+ return true
55
+ else
56
+ puts "[-] [##{@login_counter}] ".cyan + "You're not logged in (or it is an error with the request)\t[TRYING AGAIN]".red.bold
57
+ exit! if @login_counter == 3
58
+ @login_counter += 1
59
+ login
60
+ end
61
+ end
62
+ end
@@ -1,239 +1,228 @@
1
- # modes module and helpers
2
- module Modes
3
- # main def and mode selector
4
- def mode(mode = :default)
5
- case mode
6
- when :infinite
7
- puts '[+] '.cyan + '[Auto] mode is turned on'.yellow
8
- log('[Auto] mode is turned on', 'MODES')
9
- search(options[:tags])
10
- @tomorrow = Time.new + 1.days
11
- actions = %w[follow unfollow like comment]
12
- loop do
13
- if !maximums_are_full?
14
- action = actions.sample
15
- case action
16
- when 'follow'
17
- if !follows_in_day_are_full?
18
- auto_follow
19
- end
20
- when 'unfollow'
21
- if !unfollows_in_day_are_full?
22
- auto_unfollow
23
- end
24
- when 'like'
25
- if !likes_in_day_are_full?
26
- auto_like
27
- end
28
- when 'comment'
29
- if !comments_in_day_are_full?
30
- auto_comment
31
- end
32
- end
33
- else
34
- check_date
35
- sleep 1
36
- end
37
- end
38
- when :clean_up
39
- puts '[+] '.cyan + '[Clean up] mode is turned on'.upcase.yellow
40
- log('[Clean up] mode is turned on', 'MODES')
41
- @local_stroage[:followed_users].each do |user|
42
- unfollow(user)
43
- fall_in_asleep
44
- end
45
- when :default
46
- puts '[-] '.cyan + 'Please choose a mode'.upcase.red
47
- else
48
- puts '[-] '.cyan + 'Please choose a mode'.upcase.red
49
- end
50
- end
51
-
52
- def auto_follow
53
- all_users = @users
54
- id = 0
55
- puts '[+] '.cyan + "[follow] ".upcase.yellow.bold + "#{all_users.size} user is ready".upcase
56
- while @maximums[:follows_in_day] < @maximums[:max_follows_per_day]
57
- begin
58
- id += 1 if all_users[id].nil? || all_users[id] == []
59
- handle_user_information_data_by_user_id(all_users[id])
60
- if !is_user_valid?(@user_information[:full_name])
61
- puts '[+] '.cyan + "Trying to follow user [#{all_users[id]}]"
62
- follow(@user_information[:id])
63
- @users -= [all_users[id]]
64
- puts '[+] '.cyan + 'User followed'.upcase.green.bold
65
- @maximums[:follows_in_day] += 1
66
- id += 1
67
- fall_in_asleep
68
- else
69
- puts "unwanted user(#{@user_information[:full_name]}) [ignored]".yellow
70
- id += 1
71
- end
72
- break
73
- rescue Exception => e
74
- puts "An error occured ... #{e.class} #{e.message}\n#{e.backtrace.inspect}\n[ignored]"
75
- # exit! if @errors_iteration > 3
76
- # id += 1
77
- # @errors_iteration += 1
78
- # retry
79
- break
80
- retry
81
- end
82
- end
83
- end
84
-
85
- def auto_unfollow
86
- followed_users = @local_stroage[:followed_users]
87
- puts '[+] '.cyan + "[unfollow] ".upcase.yellow.bold + "#{followed_users.size} user is ready".upcase
88
- id = 0
89
- while @maximums[:unfollows_in_day] < @maximums[:max_unfollows_per_day]
90
- if @local_stroage[:followed_users].size < @maximums[:max_unfollows_per_day]
91
- if !followed_users.empty?
92
- begin
93
- puts '[+] '.cyan + "Trying to unfollow user [#{followed_users[id]}]"
94
- unfollow(followed_users[id])
95
- @local_stroage[:followed_users] -= [followed_users[id]]
96
- puts '[+] '.cyan + 'User unfollowed'.upcase.bold.green
97
- @maximums[:unfollows_in_day] += 1
98
- id += 1
99
- fall_in_asleep
100
- break
101
- rescue Exception => e
102
- puts "An error occured ... #{e.class} #{e.message}\n#{e.backtrace.inspect}\n[ignored]"
103
- # exit! if @errors_iteration > 3
104
- # id += 1
105
- # @errors_iteration += 1
106
- # retry
107
- break
108
- end
109
- else
110
- break
111
- end
112
- else
113
- puts '[-] '.red + '[unfollow per day] is much bigger than [follow per day]'.upcase.red.bold
114
- exit!
115
- end
116
- end
117
- end
118
-
119
- def auto_like
120
- all_medias = @medias
121
- puts '[+] '.cyan + "[like] ".upcase.yellow.bold + "#{all_medias.size} Media is ready".upcase
122
- id = 0
123
- while @maximums[:likes_in_day] < @maximums[:max_likes_per_day]
124
- begin
125
- handle_media_information_data(all_medias[id])
126
- puts '[+] '.cyan + "Trying to like media [#{all_medias[id]}]"
127
- like(@media_information[:id])
128
- @medias -= [all_medias[id]]
129
- puts '[+] '.cyan + 'Media liked'.upcase.green.bold
130
- @maximums[:likes_in_day] += 1
131
- id += 1
132
- fall_in_asleep
133
- break
134
- rescue Exception => e
135
- puts "An error occured ... #{e.class} #{e.message}\n#{e.backtrace.inspect}\n[ignored]"
136
- # exit! if @errors_iteration > 3
137
- # id += 1
138
- # @errors_iteration += 1
139
- # retry
140
- break
141
- end
142
- end
143
- end
144
-
145
- def auto_comment
146
- all_medias = @medias
147
- puts '[+] '.cyan + "[comment] ".upcase.yellow.bold + "#{all_medias.size} Media is ready".upcase
148
- id = 0
149
- while @maximums[:comments_in_day] < @maximums[:max_comments_per_day]
150
- begin
151
- handle_media_information_data(all_medias[id])
152
- if @media_information[:comments_disabled]
153
- puts '[-]'.cyan + 'comments are disable' + "\t[ignored]".yellow
154
- id += 1
155
- # next
156
- end
157
- generated_comment = generate_a_comment
158
- puts '[+] '.cyan + "Trying to send a comment[#{generated_comment}] to media[#{all_medias[id]}]"
159
- comment(@media_information[:id], generated_comment)
160
- @medias -= [all_medias[id]]
161
- puts '[+] '.cyan + 'comment has been sent'.upcase.green.bold
162
- @maximums[:comments_in_day] += 1
163
- id += 1
164
- fall_in_asleep
165
- break
166
- rescue Exception => e
167
- puts "An error occured ... #{e.class} #{e.message}\n#{e.backtrace.inspect}\n[ignored]"
168
- # exit! if @errors_iteration > 3
169
- # id += 1
170
- # @errors_iteration += 1
171
- # retry
172
- break
173
- end
174
- end
175
- end
176
-
177
- # genrating random comment
178
- def generate_a_comment
179
- comment = ""
180
- options[:comments].each { |c| comment << " #{c.sample}" }
181
- comment
182
- end
183
-
184
- def is_user_valid?(user)
185
- if options[:white_list_users].include?(user)
186
- options[:unwanted_list].find { |unwanted| unwanted =~ /#{user}/ } != nil
187
- else
188
- return false
189
- end
190
- end
191
-
192
-
193
- def check_date
194
- time = (@tomorrow - Time.new).to_i # => remained time ...
195
- if time.zero?
196
- puts '[+] '.cyan + "[new day]".upcase
197
- @local_stroage[:followed_users] = []
198
- @local_stroage[:unfollowed_users] = []
199
- @local_stroage[:liked_medias] = []
200
- @local_stroage[:commented_medias] = []
201
- @maximums[:follows_in_day] = 0
202
- @maximums[:unfollows_in_day] = 0
203
- @maximums[:likes_in_day] = 0
204
- @maximums[:comments_in_day] = 0
205
- @tomorrow = Time.new + 1.days
206
- search(options[:tags]) unless @infinite_tags == true
207
- else
208
- time = Time.at(time).utc.strftime("%H:%M:%S")
209
- print "\r[+] ".cyan + "#{time} remained".upcase + ' '*10 # the empty space
210
- $stdout.flush
211
- end
212
- end
213
-
214
- def fall_in_asleep(time=options[:wait_per_action])
215
- puts '[+] '.cyan + "Waiting for #{time} seconds".upcase
216
- sleep time
217
- end
218
-
219
- def likes_in_day_are_full?
220
- @maximums[:likes_in_day] == @maximums[:max_likes_per_day]
221
- end
222
-
223
- def follows_in_day_are_full?
224
- @maximums[:follows_in_day] == @maximums[:max_follows_per_day]
225
- end
226
-
227
- def unfollows_in_day_are_full?
228
- @maximums[:unfollows_in_day] == @maximums[:max_unfollows_per_day]
229
- end
230
-
231
- def comments_in_day_are_full?
232
- @maximums[:comments_in_day] == @maximums[:max_comments_per_day]
233
- end
234
-
235
- def maximums_are_full?
236
- likes_in_day_are_full? && follows_in_day_are_full? &&
237
- unfollows_in_day_are_full? && comments_in_day_are_full?
238
- end
239
- end
1
+ # modes module and helpers
2
+ module Modes
3
+ # main def and mode selector
4
+ def mode(mode = :default)
5
+ case mode
6
+ when :infinite
7
+ puts '[+] '.cyan + '[Auto] mode is turned on'.yellow
8
+ log('[Auto] mode is turned on', 'MODES')
9
+ search(options[:tags])
10
+ @tomorrow = Time.new + 1.days
11
+ actions = %w[follow unfollow like comment]
12
+ loop do
13
+ if !maximums_are_full?
14
+ action = actions.sample
15
+ case action
16
+ when 'follow'
17
+ if !follows_in_day_are_full?
18
+ auto_follow
19
+ end
20
+ when 'unfollow'
21
+ if !unfollows_in_day_are_full?
22
+ auto_unfollow
23
+ end
24
+ when 'like'
25
+ if !likes_in_day_are_full?
26
+ auto_like
27
+ end
28
+ when 'comment'
29
+ if !comments_in_day_are_full?
30
+ auto_comment
31
+ end
32
+ end
33
+ else
34
+ check_date
35
+ sleep 1
36
+ end
37
+ end
38
+ when :clean_up
39
+ puts '[+] '.cyan + '[Clean up] mode is turned on'.upcase.yellow
40
+ log('[Clean up] mode is turned on', 'MODES')
41
+ @local_stroage[:followed_users].each do |user|
42
+ unfollow(user)
43
+ fall_in_asleep
44
+ end
45
+ when :default
46
+ puts '[-] '.cyan + 'Please choose a mode'.upcase.red
47
+ else
48
+ puts '[-] '.cyan + 'Please choose a mode'.upcase.red
49
+ end
50
+ end
51
+
52
+ def auto_follow
53
+ all_users = @users
54
+ search(options[:tags]) if all_users == [] || all_users.nil?
55
+ @follows_auto_increment = 0
56
+ puts '[+] '.cyan + "[follow] ".upcase.yellow.bold + "#{all_users.size} user is ready".upcase
57
+ while @maximums[:follows_in_day] < @maximums[:max_follows_per_day]
58
+ begin
59
+ @users -= all_users[@follows_auto_increment] if all_users[@follows_auto_increment].nil? || all_users[@follows_auto_increment] == []
60
+ handle_user_information_data_by_user_id(all_users[@follows_auto_increment])
61
+ if !is_user_valid?(@user_information[:full_name])
62
+ puts '[+] '.cyan + "Trying to follow user [#{all_users[@follows_auto_increment]}]"
63
+ follow(@user_information[:id])
64
+ @users -= [all_users[@follows_auto_increment]]
65
+ puts '[+] '.cyan + 'User followed'.upcase.green.bold
66
+ @maximums[:follows_in_day] += 1
67
+ @follows_auto_increment += 1
68
+ fall_in_asleep
69
+ else
70
+ puts "unwanted user(#{@user_information[:full_name]}) [ignored]".yellow
71
+ @follows_auto_increment += 1
72
+ end
73
+ break
74
+ rescue Exception => e
75
+ puts "An error occured ... #{e.class} #{e.message}\n#{e.backtrace.inspect}\n[ignored]"
76
+ @follows_auto_increment += 1
77
+ break
78
+ retry
79
+ end
80
+ end
81
+ end
82
+
83
+ def auto_unfollow
84
+ followed_users = @local_stroage[:followed_users]
85
+ puts '[+] '.cyan + "[unfollow] ".upcase.yellow.bold + "#{followed_users.size} user is ready".upcase
86
+ @unfollows_auto_increment = 0
87
+ while @maximums[:unfollows_in_day] < @maximums[:max_unfollows_per_day]
88
+ if @local_stroage[:followed_users].size < @maximums[:max_unfollows_per_day]
89
+ if !followed_users.empty?
90
+ begin
91
+ puts '[+] '.cyan + "Trying to unfollow user [#{followed_users[@unfollows_auto_increment]}]"
92
+ unfollow(followed_users[@unfollows_auto_increment])
93
+ @local_stroage[:followed_users] -= [followed_users[@unfollows_auto_increment]]
94
+ puts '[+] '.cyan + 'User unfollowed'.upcase.bold.green
95
+ @maximums[:unfollows_in_day] += 1
96
+ @unfollows_auto_increment += 1
97
+ fall_in_asleep
98
+ break
99
+ rescue Exception => e
100
+ puts "An error occured ... #{e.class} #{e.message}\n#{e.backtrace.inspect}\n[ignored]"
101
+ @unfollows_auto_increment += 1
102
+ break
103
+ end
104
+ else
105
+ break
106
+ end
107
+ else
108
+ puts '[-] '.red + '[unfollow per day] is much bigger than [follow per day]'.upcase.red.bold
109
+ exit!
110
+ end
111
+ end
112
+ end
113
+
114
+ def auto_like
115
+ all_medias = @medias
116
+ search(options[:tags]) if all_medias == [] || all_medias.nil?
117
+ puts '[+] '.cyan + "[like] ".upcase.yellow.bold + "#{all_medias.size} Media is ready".upcase
118
+ while @maximums[:likes_in_day] < @maximums[:max_likes_per_day]
119
+ begin
120
+ @medias -= [all_medias[@likes_auto_increment]] if all_medias[@likes_auto_increment].nil? || all_medias[@likes_auto_increment] == []
121
+ handle_media_information_data(all_medias[@likes_auto_increment])
122
+ puts '[+] '.cyan + "Trying to like media [#{all_medias[@likes_auto_increment]}]"
123
+ like(@media_information[:id])
124
+ @medias -= [all_medias[@likes_auto_increment]]
125
+ puts '[+] '.cyan + 'Media liked'.upcase.green.bold
126
+ @maximums[:likes_in_day] += 1
127
+ fall_in_asleep
128
+ break
129
+ rescue Exception => e
130
+ puts "An error occured ... #{e.class} #{e.message}\n#{e.backtrace.inspect}\n[ignored]"
131
+ @medias -= [all_medias[@likes_auto_increment]]
132
+ break
133
+ end
134
+ end
135
+ end
136
+
137
+ def auto_comment
138
+ all_medias = @medias
139
+ search(options[:tags]) if all_medias == [] || all_medias.nil?
140
+ puts '[+] '.cyan + "[comment] ".upcase.yellow.bold + "#{all_medias.size} Media is ready".upcase
141
+ @comments_auto_increment = 0
142
+ while @maximums[:comments_in_day] < @maximums[:max_comments_per_day]
143
+ begin
144
+ @medias -= [all_medias[@comments_auto_increment]] if all_medias[@comments_auto_increment].nil? || all_medias[@comments_auto_increment] == []
145
+ handle_media_information_data(all_medias[@comments_auto_increment])
146
+ if @media_information[:comments_disabled]
147
+ puts '[-]'.cyan + 'comments are disable' + "\t[ignored]".yellow
148
+ @comments_auto_increment += 1
149
+ end
150
+ generated_comment = generate_a_comment
151
+ puts '[+] '.cyan + "Trying to send a comment[#{generated_comment}] to media[#{all_medias[@comments_auto_increment]}]"
152
+ comment(@media_information[:id], generated_comment)
153
+ @medias -= [all_medias[@comments_auto_increment]]
154
+ puts '[+] '.cyan + 'comment has been sent'.upcase.green.bold
155
+ @maximums[:comments_in_day] += 1
156
+ fall_in_asleep
157
+ break
158
+ rescue Exception => e
159
+ puts "An error occured ... #{e.class} #{e.message}\n#{e.backtrace.inspect}\n[ignored]"
160
+ @comments_auto_increment += 1
161
+ break
162
+ end
163
+ end
164
+ end
165
+
166
+ # genrating random comment
167
+ def generate_a_comment
168
+ comment = ""
169
+ options[:comments].each { |c| comment << " #{c.sample}" }
170
+ comment
171
+ end
172
+
173
+ def is_user_valid?(user)
174
+ if options[:white_list_users].include?(user)
175
+ options[:unwanted_list].find { |unwanted| unwanted =~ /#{user}/ } != nil
176
+ else
177
+ return false
178
+ end
179
+ end
180
+
181
+
182
+ def check_date
183
+ time = (@tomorrow - Time.new).to_i # => remained time ...
184
+ if time.zero?
185
+ puts '[+] '.cyan + "[new day]".upcase
186
+ @local_stroage[:followed_users] = []
187
+ @local_stroage[:unfollowed_users] = []
188
+ @local_stroage[:liked_medias] = []
189
+ @local_stroage[:commented_medias] = []
190
+ @maximums[:follows_in_day] = 0
191
+ @maximums[:unfollows_in_day] = 0
192
+ @maximums[:likes_in_day] = 0
193
+ @maximums[:comments_in_day] = 0
194
+ @tomorrow = Time.new + 1.days
195
+ search(options[:tags]) unless @infinite_tags == true
196
+ else
197
+ time = Time.at(time).utc.strftime("%H:%M:%S")
198
+ print "\r[+] ".cyan + "#{time} remained".upcase + ' '*10 # the empty space
199
+ $stdout.flush
200
+ end
201
+ end
202
+
203
+ def fall_in_asleep(time=options[:wait_per_action])
204
+ puts '[+] '.cyan + "Waiting for #{time} seconds".upcase
205
+ sleep time
206
+ end
207
+
208
+ def likes_in_day_are_full?
209
+ @maximums[:likes_in_day] == @maximums[:max_likes_per_day]
210
+ end
211
+
212
+ def follows_in_day_are_full?
213
+ @maximums[:follows_in_day] == @maximums[:max_follows_per_day]
214
+ end
215
+
216
+ def unfollows_in_day_are_full?
217
+ @maximums[:unfollows_in_day] == @maximums[:max_unfollows_per_day]
218
+ end
219
+
220
+ def comments_in_day_are_full?
221
+ @maximums[:comments_in_day] == @maximums[:max_comments_per_day]
222
+ end
223
+
224
+ def maximums_are_full?
225
+ likes_in_day_are_full? && follows_in_day_are_full? &&
226
+ unfollows_in_day_are_full? && comments_in_day_are_full?
227
+ end
228
+ end