Module: Modes

Included in:
Instabot
Defined in:
lib/instabot/modes.rb

Overview

automatic module and helpers

Instance Method Summary collapse

Instance Method Details

#auto_commentObject



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
# File 'lib/instabot/modes.rb', line 131

def auto_comment
  all_medias  = medias
  # puts '[+] '.cyan + "#{all_medias.size} Media is ready".upcase
  id      = 0
  while @maximums[:comments_in_day] < @maximums[:max_comments_per_day]
    begin
      get_media_informations(all_medias[id])
      if @informations[:comments_disabled]
        puts '[-]'.red + 'comments are disable' + "\t[IGNORING]".yellow
        id += 1 
        next
      end
      generated_comment = generate_a_comment
      puts '[+] '.cyan + "Trying to send a comment[#{generated_comment}] to media[#{all_medias[id]}]"
      comment(@informations[:id], generated_comment)
      puts '[+] '.cyan + 'comment has been sent'.upcase.green.bold
      @maximums[:comments_in_day] += 1
      id                          += 1
      fall_in_asleep
    rescue Exception => e
      puts "An error occured ... #{e.class} #{e.message}\n#{e.backtrace.inspect}\n[ignored]"
      id += 1
      retry
    end
  end
end

#auto_followObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/instabot/modes.rb', line 63

def auto_follow
  all_users    = users
  id            = 0
  puts '[+] '.cyan + "#{all_users.size} user is ready to follow".upcase
  while @maximums[:follows_in_day] < @maximums[:max_follows_per_day]
    begin
      id += 1 if all_users[id].nil? || all_users[id] == []
      get_user_informations(all_users[id])
      puts '[+] '.cyan + "Trying to follow user [#{all_users[id]}]"
      follow(@informations[:id])
      puts '[+] '.cyan + 'User followed'.upcase.green.bold
      @maximums[:follows_in_day] += 1
      id                         += 1
      fall_in_asleep
    rescue Exception => e
      puts "An error occured ... #{e.class} #{e.message}\n#{e.backtrace.inspect}\n[ignored]"
      id += 1
      retry
    end
  end
end

#auto_likeObject



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/instabot/modes.rb', line 110

def auto_like
  all_medias  = medias
  puts '[+] '.cyan + "#{all_medias.size} Media is ready to like".upcase
  id      = 0
  while @maximums[:likes_in_day] < @maximums[:max_likes_per_day]
    begin
      get_media_informations(all_medias[id])
      puts '[+] '.cyan + "Trying to like media [#{all_medias[id]}]"
      like(@informations[:id])
      puts '[+] '.cyan + 'Media liked'.upcase.green.bold
      @maximums[:likes_in_day] += 1
      id                       += 1
      fall_in_asleep
    rescue Exception => e
      puts "An error occured ... #{e.class} #{e.message}\n#{e.backtrace.inspect}\n[ignored]"
      id += 1
      retry
    end
  end
end

#auto_unfollowObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/instabot/modes.rb', line 85

def auto_unfollow
  followed_users = @local_stroage[:followed_users]
  puts '[+] '.cyan + "#{followed_users.size} user is ready to unfollow".upcase
  id = 0
  while @maximums[:unfollows_in_day] < @maximums[:max_unfollows_per_day]
    if @local_stroage[:followed_users].size < @maximums[:max_unfollows_per_day]
      begin
        puts '[+] '.cyan + "Trying to unfollow user [#{followed_users[id]}]"
        unfollow(followed_users[id])
        puts '[+] '.cyan + 'User unfollowed'.upcase.bold.green
        @maximums[:unfollows_in_day] += 1
        id                           += 1
        fall_in_asleep
      rescue Exception => e
        puts "An error occured ... #{e.class} #{e.message}\n#{e.backtrace.inspect}\n[ignored]"
        id += 1
        retry
      end
    else
      puts '[+] '.cyan + '[unfollow per day] is much bigger than [follow per day]'
      exit
    end
  end
end

#check_dateObject



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/instabot/modes.rb', line 164

def check_date
  time = (@tomorrow - Time.new).to_i # => remained time ...
  if time.zero?
    puts '[+] '.cyan + "It's a new day"
    @local_stroage[:followed_users]   = []
    @local_stroage[:unfollowed_users] = []
    @local_stroage[:liked_medias]     = []
    @local_stroage[:commented_medias] = []
    @maximums[:follows_in_day]        = 0
    @maximums[:unfollows_in_day]      = 0
    @maximums[:likes_in_day]          = 0
    @maximums[:comments_in_day]       = 0
    @tomorrow                         = Time.new + 1.days
    search(options[:tags]) unless @infinite_tags == true
  else
    time = Time.at(time).utc.strftime("%H:%M:%S")
    print "\r[+] ".cyan + "#{time} remained".upcase + ' '*10 # the empty space
    $stdout.flush
  end
end

#comments_in_day_are_full?Boolean

Returns:

  • (Boolean)


203
204
205
# File 'lib/instabot/modes.rb', line 203

def comments_in_day_are_full?
  @maximums[:comments_in_day] == @maximums[:max_comments_per_day]
end

#fall_in_asleepObject



185
186
187
188
189
# File 'lib/instabot/modes.rb', line 185

def fall_in_asleep
  time = options[:wait_per_action]
  puts '[+] '.cyan + "Waiting for #{time} seconds".upcase
  sleep time
end

#follows_in_day_are_full?Boolean

Returns:

  • (Boolean)


195
196
197
# File 'lib/instabot/modes.rb', line 195

def follows_in_day_are_full?
  @maximums[:follows_in_day] == @maximums[:max_follows_per_day]
end

#generate_a_commentObject

genrating random comment



158
159
160
161
162
# File 'lib/instabot/modes.rb', line 158

def generate_a_comment
  comment = ""
  options[:comments].each { |c| comment << " #{c.sample}" }
  comment
end

#likes_in_day_are_full?Boolean

Returns:

  • (Boolean)


191
192
193
# File 'lib/instabot/modes.rb', line 191

def likes_in_day_are_full?
  @maximums[:likes_in_day] == @maximums[:max_likes_per_day]
end

#maximums_are_full?Boolean

Returns:

  • (Boolean)


207
208
209
210
# File 'lib/instabot/modes.rb', line 207

def maximums_are_full?
    likes_in_day_are_full? && follows_in_day_are_full? &&
    unfollows_in_day_are_full? && comments_in_day_are_full?
end

#mode(mode = :default) ⇒ Object

main def and mode selector



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
# File 'lib/instabot/modes.rb', line 5

def mode(mode = :default)
  case mode
  when :infinite
    puts '[+] '.cyan + '[Auto] mode is turned on'.yellow
    log('[Auto] mode is turned on', 'MODES')
    search(options[:tags])
    @tomorrow = Time.new + 1.days
    loop do
      if !maximums_are_full?
        if !follows_in_day_are_full?
          @maximums[:follows_in_day] += 1
          auto_follow
        else
          puts '[+] '.cyan + 'Maximum follows per day'.upcase
          log('Maximum follows per day', 'MODES')
        end

        if !unfollows_in_day_are_full?
          @maximums[:unfollows_in_day] += 1
          auto_unfollow
        else
          puts '[+] '.cyan + 'Maximum unfollows per day'.upcase
          log('Maximum unfollows per day', 'MODES')
        end

        if !likes_in_day_are_full?
          @maximums[:likes_in_day] += 1
          auto_like
        else
          puts '[+] '.cyan + 'Maximum likes per day'.upcase
          log('Maximum likes per day', 'MODES')
        end

        if !comments_in_day_are_full?
          @maximums[:comments_in_day] += 1
          auto_comment
        else
          puts '[+] '.cyan + 'Maximum comments per day'.upcase
          log('Maximum comments per day', 'MODES')
        end
      else
        check_date
        sleep 1
      end
    end
  when :clean_up
    puts '[+] '.cyan + '[Clean up] mode is turned on'.upcase.yellow
    log('[Clean up] mode is turned on', 'MODES')
    @local_stroage[:followed_users].each do |user|
      unfollow(user)
    end
  when :default
    puts '[-] '.cyan + 'Please choose a mode'.upcase.red
  else
    puts '[-] '.cyan + 'Please choose a mode'.upcase.red
  end
end

#unfollows_in_day_are_full?Boolean

Returns:

  • (Boolean)


199
200
201
# File 'lib/instabot/modes.rb', line 199

def unfollows_in_day_are_full?
  @maximums[:unfollows_in_day] == @maximums[:max_unfollows_per_day]
end