Class: VkCozy::BotEvent

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

Direct Known Subclasses

BotMessageEvent

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api, event_raw) ⇒ BotEvent

Returns a new instance of BotEvent.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/vk_cozy/dispatch/views/bot/event.rb', line 4

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

  @type = event_raw['type']
  @t = @type 

  @object = event_raw['object'].to_dot
  @obj = @object

  @message = @obj['message']

  @client_info = @obj['client_info']

  @group_id = @raw['group_id']
  
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



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

def api
  @api
end

#client_infoObject (readonly)

Returns the value of attribute client_info.



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

def client_info
  @client_info
end

#group_idObject (readonly)

Returns the value of attribute group_id.



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

def group_id
  @group_id
end

#messageObject (readonly)

Returns the value of attribute message.



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

def message
  @message
end

#objObject (readonly)

Returns the value of attribute obj.



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

def obj
  @obj
end

#objectObject (readonly)

Returns the value of attribute object.



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

def object
  @object
end

#rawObject (readonly)

Returns the value of attribute raw.



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

def raw
  @raw
end

#tObject (readonly)

Returns the value of attribute t.



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

def t
  @t
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#[](key) ⇒ Object



30
31
32
# File 'lib/vk_cozy/dispatch/views/bot/event.rb', line 30

def [] key
  instance_variable_get("@#{key}")
end

#answer(text) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/vk_cozy/dispatch/views/bot/event.rb', line 22

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

#to_sObject



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

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