Sha256: d8669d9d2372fd8c2c446b1a09fa2f5b6dc6b86b4bf265a0d015624d0204a88f

Contents?: true

Size: 1.08 KB

Versions: 7

Compression:

Stored size: 1.08 KB

Contents

require "securerandom"
require "sinbotra/bot/default_message_history"

class Sinbotra::Bot
  class User
    attr_reader :id
    attr_reader :session_id
    attr_reader :current_message
    attr_reader :conversations
    attr_reader :history

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

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

    # Sessions

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

    # remove user while not removing history
    def destroy
      end_session
    end

    # Conversations

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

    def in_conversation?
      !current_conversation.nil?
    end

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

    private

    def start_session
      @session_id = SecureRandom.uuid
    end

    def end_session
      @session_id = nil
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sinbotra-0.1.6 lib/sinbotra/bot/user.rb
sinbotra-0.1.5 lib/sinbotra/bot/user.rb
sinbotra-0.1.4 lib/sinbotra/bot/user.rb
sinbotra-0.1.3 lib/sinbotra/bot/user.rb
sinbotra-0.1.2 lib/sinbotra/bot/user.rb
sinbotra-0.1.1 lib/sinbotra/bot/user.rb
sinbotra-0.1.0 lib/sinbotra/bot/user.rb