Class: ActiveMatrix::Agent

Inherits:
ApplicationRecord show all
Defined in:
app/models/active_matrix/agent.rb,
app/models/active_matrix/agent/jobs/memory_reaper.rb

Defined Under Namespace

Modules: Jobs

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#passwordObject

Password handling



102
103
104
# File 'app/models/active_matrix/agent.rb', line 102

def password
  @password
end

Instance Method Details

#authenticate(password) ⇒ Object



104
105
106
107
108
# File 'app/models/active_matrix/agent.rb', line 104

def authenticate(password)
  return false if encrypted_password.blank?

  BCrypt::Password.new(encrypted_password) == password
end

#bot_instanceObject

Instance methods



73
74
75
# File 'app/models/active_matrix/agent.rb', line 73

def bot_instance
  @bot_instance ||= bot_class.constantize.new(client) if running?
end

#clientObject



77
78
79
80
81
82
83
# File 'app/models/active_matrix/agent.rb', line 77

def client
  @client ||= if access_token.present?
                ActiveMatrix::Client.new(homeserver, access_token: access_token)
              else
                ActiveMatrix::Client.new(homeserver)
              end
end

#increment_messages_handled!Object



93
94
95
# File 'app/models/active_matrix/agent.rb', line 93

def increment_messages_handled!
  update!(messages_handled: messages_handled + 1)
end

#memoryObject



89
90
91
# File 'app/models/active_matrix/agent.rb', line 89

def memory
  @memory ||= ActiveMatrix::Memory::AgentMemory.new(self)
end

#running?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'app/models/active_matrix/agent.rb', line 85

def running?
  %i[online_idle online_busy].include?(state.to_sym)
end

#update_activity!Object



97
98
99
# File 'app/models/active_matrix/agent.rb', line 97

def update_activity!
  update(last_active_at: Time.current)
end