Class: TelegramMeetupBot::HandlerHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/telegram_meetup_bot/handler_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ HandlerHelper



5
6
7
8
9
# File 'lib/telegram_meetup_bot/handler_helper.rb', line 5

def initialize(args)
  @command = args.fetch(:command)
  @author = args.fetch(:author)
  @messenger = args.fetch(:messenger)
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



3
4
5
# File 'lib/telegram_meetup_bot/handler_helper.rb', line 3

def author
  @author
end

#commandObject (readonly)

Returns the value of attribute command.



3
4
5
# File 'lib/telegram_meetup_bot/handler_helper.rb', line 3

def command
  @command
end

#errorObject (readonly)

Returns the value of attribute error.



3
4
5
# File 'lib/telegram_meetup_bot/handler_helper.rb', line 3

def error
  @error
end

#messengerObject (readonly)

Returns the value of attribute messenger.



3
4
5
# File 'lib/telegram_meetup_bot/handler_helper.rb', line 3

def messenger
  @messenger
end

Instance Method Details

#author_has_username?Boolean



42
43
44
# File 'lib/telegram_meetup_bot/handler_helper.rb', line 42

def author_has_username?
  author.username
end

#handle_cal(month) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/telegram_meetup_bot/handler_helper.rb', line 46

def handle_cal(month)
  dates = Calendar.submited_days_of_month(month)
  today = Date.today
  year = month < today.month ? today.next_year.year : today.year
  month = Date.new(year, month)
  messenger.send_text list_response(list: dates, month: month)
end

#handle_date(date, time) ⇒ Object



11
12
13
14
15
16
# File 'lib/telegram_meetup_bot/handler_helper.rb', line 11

def handle_date(date, time)
  handle(date) do
    Calendar.new(date: date, user: author, time: time).add_user_to_date
    messenger.send_text build_response(date: date)
  end
end

#handle_date_cancel(date) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/telegram_meetup_bot/handler_helper.rb', line 25

def handle_date_cancel(date)
  handle(date) do
    calendar = Calendar.new(date: date, user: author)
    deleted_user = calendar.delete_user_from_date
    args = deleted_user ? {} : {key: 'not_subscribed', date: date}
    messenger.send_text build_response(args)
  end
end

#handle_date_list(date) ⇒ Object



18
19
20
21
22
23
# File 'lib/telegram_meetup_bot/handler_helper.rb', line 18

def handle_date_list(date)
  handle(date) do
    users = Calendar.formated_users_for_date(date)
    messenger.send_text list_response(list: users, date: date)
  end
end

#handle_default_commandObject



34
35
36
# File 'lib/telegram_meetup_bot/handler_helper.rb', line 34

def handle_default_command
  messenger.send_text build_response
end

#send_empty_username_notificationObject



38
39
40
# File 'lib/telegram_meetup_bot/handler_helper.rb', line 38

def send_empty_username_notification
  messenger.send_text build_response(key: 'no_username')
end