Class: Tramway::Bots::Bot

Inherits:
ApplicationRecord show all
Defined in:
app/models/tramway/bots/bot.rb

Constant Summary collapse

TEAMS =
%i[rsm night purple_magic benchkiller].freeze

Instance Method Summary collapse

Instance Method Details

#finish_stepObject



28
29
30
31
32
# File 'app/models/tramway/bots/bot.rb', line 28

def finish_step
  return unless team.night?

  scenario_steps.finish_step
end

#finished_usersObject



34
35
36
37
38
# File 'app/models/tramway/bots/bot.rb', line 34

def finished_users
  return [] unless finish_step.present?

  progress_records.where(bot_telegram_scenario_step_id: finish_step.id).uniq(&:bot_telegram_user_id)
end

#new_users_between(begin_date, end_date) ⇒ Object



40
41
42
43
44
45
# File 'app/models/tramway/bots/bot.rb', line 40

def new_users_between(begin_date, end_date)
  users.uniq.map do |user|
    first_message_created_at = user.messages.order(created_at: :asc).first.created_at
    user if first_message_created_at.between?(begin_date, end_date)
  end.compact
end

#start_stepObject



23
24
25
26
# File 'app/models/tramway/bots/bot.rb', line 23

def start_step
  # scenario_steps.find_by name: :start did not work for some reason. Think it's about step word in Rails
  scenario_steps.select { |s| s.name == 'start' }.first
end

#uniq_users_between(begin_date, end_date) ⇒ Object



47
48
49
# File 'app/models/tramway/bots/bot.rb', line 47

def uniq_users_between(begin_date, end_date)
  messages.where('created_at >= ? AND created_at <= ?', begin_date, end_date).map(&:user).uniq
end