Class: VkCozy::BotMessageEvent

Inherits:
BotEvent
  • Object
show all
Defined in:
lib/vk_cozy/dispatch/views/bot/event.rb

Instance Attribute Summary collapse

Attributes inherited from BotEvent

#api, #client_info, #group_id, #message, #obj, #object, #raw, #t, #type

Instance Method Summary collapse

Methods inherited from BotEvent

#[]

Constructor Details

#initialize(api, event_raw) ⇒ BotMessageEvent

Returns a new instance of BotMessageEvent.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/vk_cozy/dispatch/views/bot/event.rb', line 41

def initialize(api, event_raw)
  super(api, event_raw)
  @from_user = false
  @from_chat = false
  @from_group = false


  peer_id = @raw['object']['peer_id']
  if peer_id.nil?
    peer_id = @raw['object']['message']['peer_id']
  end

  if peer_id < 0
    @from_group = true
  elsif peer_id < 2e9
    @from_user = true
  else
    from_user = true
    @chat_id = peer_id - 2e9
  end
end

Instance Attribute Details

#chat_idObject (readonly)

Returns the value of attribute chat_id.



40
41
42
# File 'lib/vk_cozy/dispatch/views/bot/event.rb', line 40

def chat_id
  @chat_id
end

#from_chatObject (readonly)

Returns the value of attribute from_chat.



40
41
42
# File 'lib/vk_cozy/dispatch/views/bot/event.rb', line 40

def from_chat
  @from_chat
end

#from_groupObject (readonly)

Returns the value of attribute from_group.



40
41
42
# File 'lib/vk_cozy/dispatch/views/bot/event.rb', line 40

def from_group
  @from_group
end

#from_userObject (readonly)

Returns the value of attribute from_user.



40
41
42
# File 'lib/vk_cozy/dispatch/views/bot/event.rb', line 40

def from_user
  @from_user
end

Instance Method Details

#answer(text) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/vk_cozy/dispatch/views/bot/event.rb', line 63

def answer(text)
  return @api.messages_send(
    peer_id: @message.peer_id,
    message: text,
    random_id: 0
  )
end

#to_sObject



71
72
73
# File 'lib/vk_cozy/dispatch/views/bot/event.rb', line 71

def to_s
  "BotMessageEvent(#{@raw.to_s})"
end