Class: VkCozy::UserEvent

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api, raw_event) ⇒ UserEvent

Returns a new instance of UserEvent.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/vk_cozy/dispatch/views/user/event.rb', line 8

def initialize(api, raw_event)
  @api = api
  @raw = raw_event

  @from_user = false
  @from_chat = false
  @from_group = false
  @from_me = false
  @to_me = false

  begin
    @type = UserEventType.parse(@raw[0])
    list_to_attr(@raw[1, @raw.length], EVENT_ATTRS_MAPPING[@type])
  rescue StandardError => e
    @type = @raw[0]
  end

  if VkCozy::PARSE_PEER_ID_EVENTS.include?(@type)
    parse_peer_id()
  end

  if VkCozy::PARSE_MESSAGE_FLAGS_EVENTS
    parse_message()
  end
end

Instance Attribute Details

#apiObject

Returns the value of attribute api.



3
4
5
# File 'lib/vk_cozy/dispatch/views/user/event.rb', line 3

def api
  @api
end

#attachmentsObject

Returns the value of attribute attachments.



3
4
5
# File 'lib/vk_cozy/dispatch/views/user/event.rb', line 3

def attachments
  @attachments
end

#extraObject

Returns the value of attribute extra.



3
4
5
# File 'lib/vk_cozy/dispatch/views/user/event.rb', line 3

def extra
  @extra
end

#extra_valuesObject

Returns the value of attribute extra_values.



3
4
5
# File 'lib/vk_cozy/dispatch/views/user/event.rb', line 3

def extra_values
  @extra_values
end

#flagsObject

Returns the value of attribute flags.



3
4
5
# File 'lib/vk_cozy/dispatch/views/user/event.rb', line 3

def flags
  @flags
end

#from_chatObject

Returns the value of attribute from_chat.



3
4
5
# File 'lib/vk_cozy/dispatch/views/user/event.rb', line 3

def from_chat
  @from_chat
end

#from_groupObject

Returns the value of attribute from_group.



3
4
5
# File 'lib/vk_cozy/dispatch/views/user/event.rb', line 3

def from_group
  @from_group
end

#from_meObject

Returns the value of attribute from_me.



3
4
5
# File 'lib/vk_cozy/dispatch/views/user/event.rb', line 3

def from_me
  @from_me
end

#from_userObject

Returns the value of attribute from_user.



3
4
5
# File 'lib/vk_cozy/dispatch/views/user/event.rb', line 3

def from_user
  @from_user
end

#message_dataObject

Returns the value of attribute message_data.



3
4
5
# File 'lib/vk_cozy/dispatch/views/user/event.rb', line 3

def message_data
  @message_data
end

#message_idObject

Returns the value of attribute message_id.



3
4
5
# File 'lib/vk_cozy/dispatch/views/user/event.rb', line 3

def message_id
  @message_id
end

#peer_idObject

Returns the value of attribute peer_id.



3
4
5
# File 'lib/vk_cozy/dispatch/views/user/event.rb', line 3

def peer_id
  @peer_id
end

#rawObject

Returns the value of attribute raw.



3
4
5
# File 'lib/vk_cozy/dispatch/views/user/event.rb', line 3

def raw
  @raw
end

#textObject

Returns the value of attribute text.



3
4
5
# File 'lib/vk_cozy/dispatch/views/user/event.rb', line 3

def text
  @text
end

#timestampObject

Returns the value of attribute timestamp.



3
4
5
# File 'lib/vk_cozy/dispatch/views/user/event.rb', line 3

def timestamp
  @timestamp
end

#to_meObject

Returns the value of attribute to_me.



3
4
5
# File 'lib/vk_cozy/dispatch/views/user/event.rb', line 3

def to_me
  @to_me
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/vk_cozy/dispatch/views/user/event.rb', line 3

def type
  @type
end

#type_idObject

Returns the value of attribute type_id.



3
4
5
# File 'lib/vk_cozy/dispatch/views/user/event.rb', line 3

def type_id
  @type_id
end

Instance Method Details

#answer(text) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/vk_cozy/dispatch/views/user/event.rb', line 40

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

#to_sObject



34
35
36
37
38
# File 'lib/vk_cozy/dispatch/views/user/event.rb', line 34

def to_s
  instance_variables.each_with_object({}) do |k, h|
    h[k] = instance_variable_get("#{k}")
  end.to_json
end