Class: Telegem::Types::Message
Instance Attribute Summary collapse
-
#chat ⇒ Object
readonly
Returns the value of attribute chat.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#entities ⇒ Object
readonly
Returns the value of attribute entities.
-
#forward_from ⇒ Object
readonly
Returns the value of attribute forward_from.
-
#forward_from_chat ⇒ Object
readonly
Returns the value of attribute forward_from_chat.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#message_id ⇒ Object
readonly
Returns the value of attribute message_id.
-
#reply_markup ⇒ Object
readonly
Returns the value of attribute reply_markup.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#via_bot ⇒ Object
readonly
Returns the value of attribute via_bot.
Attributes inherited from BaseType
Instance Method Summary collapse
-
#command? ⇒ Boolean
FIXED: Proper command detection.
- #command_args ⇒ Object
- #command_name ⇒ Object
-
#initialize(data) ⇒ Message
constructor
A new instance of Message.
Methods inherited from BaseType
#method_missing, #respond_to_missing?
Constructor Details
#initialize(data) ⇒ Message
Returns a new instance of Message.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/api/types.rb', line 107 def initialize(data) super(data) @message_id = data['message_id'] @from = User.new(data['from']) if data['from'] @chat = Chat.new(data['chat']) if data['chat'] @date = Time.at(data['date']) if data['date'] @text = data['text'] if data['entities'] @entities = data['entities'].map { |e| MessageEntity.new(e) } end @reply_markup = data['reply_markup'] @via_bot = User.new(data['via_bot']) if data['via_bot'] @forward_from = User.new(data['forward_from']) if data['forward_from'] @forward_from_chat = Chat.new(data['forward_from_chat']) if data['forward_from_chat'] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Telegem::Types::BaseType
Instance Attribute Details
#chat ⇒ Object (readonly)
Returns the value of attribute chat.
104 105 106 |
# File 'lib/api/types.rb', line 104 def chat @chat end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
104 105 106 |
# File 'lib/api/types.rb', line 104 def date @date end |
#entities ⇒ Object (readonly)
Returns the value of attribute entities.
104 105 106 |
# File 'lib/api/types.rb', line 104 def entities @entities end |
#forward_from ⇒ Object (readonly)
Returns the value of attribute forward_from.
104 105 106 |
# File 'lib/api/types.rb', line 104 def forward_from @forward_from end |
#forward_from_chat ⇒ Object (readonly)
Returns the value of attribute forward_from_chat.
104 105 106 |
# File 'lib/api/types.rb', line 104 def forward_from_chat @forward_from_chat end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
104 105 106 |
# File 'lib/api/types.rb', line 104 def from @from end |
#message_id ⇒ Object (readonly)
Returns the value of attribute message_id.
104 105 106 |
# File 'lib/api/types.rb', line 104 def @message_id end |
#reply_markup ⇒ Object (readonly)
Returns the value of attribute reply_markup.
104 105 106 |
# File 'lib/api/types.rb', line 104 def reply_markup @reply_markup end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
104 105 106 |
# File 'lib/api/types.rb', line 104 def text @text end |
#via_bot ⇒ Object (readonly)
Returns the value of attribute via_bot.
104 105 106 |
# File 'lib/api/types.rb', line 104 def via_bot @via_bot end |
Instance Method Details
#command? ⇒ Boolean
FIXED: Proper command detection
127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/api/types.rb', line 127 def command? return false unless text return false unless entities # Find a "bot_command" entity command_entity = entities.find { |e| e.type == 'bot_command' } return false unless command_entity # Extract the command text command_text = text[command_entity.offset, command_entity.length] command_text&.start_with?('/') end |
#command_args ⇒ Object
152 153 154 155 156 157 158 159 160 161 |
# File 'lib/api/types.rb', line 152 def command_args return nil unless command? command_entity = entities.find { |e| e.type == 'bot_command' } return nil unless command_entity # Text after the command entity args_start = command_entity.offset + command_entity.length text[args_start..-1]&.strip end |
#command_name ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/api/types.rb', line 140 def command_name return nil unless command? command_entity = entities.find { |e| e.type == 'bot_command' } return nil unless command_entity cmd = text[command_entity.offset, command_entity.length] cmd = cmd[1..-1] # Remove "/" cmd = cmd.split('@').first # Remove bot username cmd end |