Class: Telegruby::Message

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/telegruby.rb

Overview

Message structure generated by collect_msgs from an update hash. Has some convenience methods.

Instance Method Summary collapse

Constructor Details

#initialize(hash_msg) ⇒ Message

Returns a new instance of Message.



336
337
338
# File 'lib/telegruby.rb', line 336

def initialize(hash_msg)
  super(hash_msg)
end

Instance Method Details

#added?(username) ⇒ Boolean

Returns:

  • (Boolean)


352
353
354
355
356
357
358
# File 'lib/telegruby.rb', line 352

def added?(username)
  if self.message.new_chat_participant.nil?
    false
  else
    self.message.new_chat_participant.username == username
  end
end

#bodyObject



368
369
370
# File 'lib/telegruby.rb', line 368

def body
  self.message.text
end

#chat_idObject



348
349
350
# File 'lib/telegruby.rb', line 348

def chat_id
  self.message.chat.id
end

#left?(username) ⇒ Boolean

Returns:

  • (Boolean)


360
361
362
363
364
365
366
# File 'lib/telegruby.rb', line 360

def left?(username)
  if self.message.left_chat_participant.nil?
    false
  else
    self.message.left_chat_participant.username == username
  end
end

#message_idObject



372
373
374
# File 'lib/telegruby.rb', line 372

def message_id
  self.message.message_id
end

#older_than?(secs) ⇒ Boolean

Returns:

  • (Boolean)


344
345
346
# File 'lib/telegruby.rb', line 344

def older_than?(secs)
  ((Time.now.to_i - self.timestamp) > secs)
end

#timestampObject



340
341
342
# File 'lib/telegruby.rb', line 340

def timestamp
  self.message.date
end