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



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

def any &block
  set_respond_to :any, &block
end

#blockObject



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

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

#clear_current_messageObject



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

def clear_current_message
  @message = nil
end

#current_messageObject



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

def current_message
  @message
end

#current_message=(message) ⇒ Object



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

def current_message= message
  @message = message
end

#set_respond_to(type, &block) ⇒ Object

TEST match first not nil attribute



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

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