Class: Sinbotra::Bot::User

Inherits:
Object
  • Object
show all
Defined in:
lib/sinbotra/bot/user.rb

Direct Known Subclasses

Messenger::User

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, history = Sinbotra::Bot::DefaultMessageHistory.new) ⇒ User

Returns a new instance of User.



12
13
14
15
16
17
18
# File 'lib/sinbotra/bot/user.rb', line 12

def initialize(id, history=Sinbotra::Bot::DefaultMessageHistory.new)
  @id            = id
  @history       = history
  @session_id    = nil
  @conversations = []
  start_session
end

Instance Attribute Details

#conversationsObject (readonly)

Returns the value of attribute conversations.



9
10
11
# File 'lib/sinbotra/bot/user.rb', line 9

def conversations
  @conversations
end

#current_messageObject (readonly)

Returns the value of attribute current_message.



8
9
10
# File 'lib/sinbotra/bot/user.rb', line 8

def current_message
  @current_message
end

#historyObject (readonly)

Returns the value of attribute history.



10
11
12
# File 'lib/sinbotra/bot/user.rb', line 10

def history
  @history
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/sinbotra/bot/user.rb', line 6

def id
  @id
end

#session_idObject (readonly)

Returns the value of attribute session_id.



7
8
9
# File 'lib/sinbotra/bot/user.rb', line 7

def session_id
  @session_id
end

Instance Method Details

#current_conversationObject



45
46
47
# File 'lib/sinbotra/bot/user.rb', line 45

def current_conversation
  conversations.find { |c| c.active? }
end

#destroyObject

remove user while not removing history



30
31
32
# File 'lib/sinbotra/bot/user.rb', line 30

def destroy
  end_session
end

#handle_message(msg) ⇒ Object



20
21
22
23
# File 'lib/sinbotra/bot/user.rb', line 20

def handle_message(msg)
  @current_message = msg
  history.add_message(msg)
end

#in_conversation?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/sinbotra/bot/user.rb', line 41

def in_conversation?
  !current_conversation.nil?
end

#logged_in?Boolean

Sessions

Returns:

  • (Boolean)


27
# File 'lib/sinbotra/bot/user.rb', line 27

def logged_in?() !@session_id.nil? end

#start_conversation(convo) ⇒ Object

Conversations



36
37
38
39
# File 'lib/sinbotra/bot/user.rb', line 36

def start_conversation(convo)
  conversations.unshift(convo)
  convo.start
end