Class: Telegram::Utils::Responder

Inherits:
Object
  • Object
show all
Defined in:
lib/telegram/utils/responder.rb

Constant Summary collapse

RESPONSE_TYPES =
[
  :from,
  :date,
  :chat,
  :forward_from,
  :forward_from_chat,
  :forward_from_message_id,
  :forward_date,
  :reply_to_message,
  :edit_date,
  :text,
  :entities,
  :audio,
  :document,
  :game,
  :photo,
  :sticker,
  :video,
  :voice,
  :caption,
  :contact,
  :location,
  :venue,
  :new_chat_member,
  :left_chat_member,
  :new_chat_title,
  :new_chat_photo,
  :delete_chat_photo,
  :group_chat_created,
  :supergroup_chat_created,
  :channel_chat_created,
  :migrate_to_chat_id,
  :migrate_from_chat_id,
  :pinned_message,
  # Telegram::Bot::Types::ReplyKeyboardMarkup,
  # Telegram::Bot::Types::ReplyKeyboardRemove,
  # Telegram::Bot::Types::ForceReply,
  # Telegram::Bot::Types::InlineKeyboardMarkup
]

Instance Method Summary collapse

Instance Method Details

#any(&block) ⇒ Object



84
85
86
# File 'lib/telegram/utils/responder.rb', line 84

def any &block
  set_respond_to :any, &block
end

#blockObject



110
111
112
# File 'lib/telegram/utils/responder.rb', line 110

def block
  @block or raise Telegram::Errors::Controller::BlockNotGivenError
end

#clear_current_messageObject



79
80
81
# File 'lib/telegram/utils/responder.rb', line 79

def clear_current_message
  @message = nil
end

#current_messageObject



74
75
76
# File 'lib/telegram/utils/responder.rb', line 74

def current_message
  @message
end

#current_message=(message) ⇒ Object



69
70
71
# File 'lib/telegram/utils/responder.rb', line 69

def current_message= message
  @message = message
end

#set_respond_to(type, &block) ⇒ Object

TEST match first not nil attribute



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/telegram/utils/responder.rb', line 91

def set_respond_to type, &block
  @stack ||= []
  @stack.push type
  if block && @block.nil?
    # check if message matches stack
    has_attr = @stack.find do |format|
      format == :any || !current_message.send(format).nil?
    end

    if has_attr
      @block = block
    end

    @stack.clear
  end

end