Class: ICQ::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/icqbot/event.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event_h) ⇒ Event

Returns a new instance of Event.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/icqbot/event.rb', line 18

def initialize event_h
  # TODO: больше информации

  @event_h = event_h
  @type = event_h['type']
  @from = event_h['payload']['from']
  if @type != ICQ::TypeEvent::CALLBACK
    @text = event_h['payload']['text']
    @msg_id = event_h['payload']['msgId']
    @chat_id = event_h['payload']['chat']['chatId']
  else
    @data = event_h['payload']['callbackData']
    @query_id = event_h['payload']['queryId']
    @chat_id = event_h['message']['chat']['chatId']
  end
end

Instance Attribute Details

#chat_idObject (readonly)

Returns the value of attribute chat_id.



15
16
17
# File 'lib/icqbot/event.rb', line 15

def chat_id
  @chat_id
end

#dataObject (readonly)

Returns the value of attribute data.



15
16
17
# File 'lib/icqbot/event.rb', line 15

def data
  @data
end

#fromObject (readonly)

Returns the value of attribute from.



15
16
17
# File 'lib/icqbot/event.rb', line 15

def from
  @from
end

#msg_idObject (readonly)

Returns the value of attribute msg_id.



15
16
17
# File 'lib/icqbot/event.rb', line 15

def msg_id
  @msg_id
end

#query_idObject (readonly)

Returns the value of attribute query_id.



15
16
17
# File 'lib/icqbot/event.rb', line 15

def query_id
  @query_id
end

#textObject (readonly)

Returns the value of attribute text.



15
16
17
# File 'lib/icqbot/event.rb', line 15

def text
  @text
end

#typeObject (readonly)

Returns the value of attribute type.



15
16
17
# File 'lib/icqbot/event.rb', line 15

def type
  @type
end

Instance Method Details

#prefix?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/icqbot/event.rb', line 34

def prefix?
  @text[0] == ICQ::BOT_PREFIX if @text
end

#to_hObject



38
# File 'lib/icqbot/event.rb', line 38

def to_h; @event_h end

#to_sObject



39
# File 'lib/icqbot/event.rb', line 39

def to_s; "Event(#{@type}" + (@text ? ", #{@text}" : '') + ')' end