Class: ActiveMatrix::Agent
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- ActiveMatrix::Agent
- 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
-
#password ⇒ Object
Password handling.
Instance Method Summary collapse
- #authenticate(password) ⇒ Object
-
#bot_instance ⇒ Object
Instance methods.
- #client ⇒ Object
- #increment_messages_handled! ⇒ Object
- #memory ⇒ Object
- #running? ⇒ Boolean
- #update_activity! ⇒ Object
Instance Attribute Details
#password ⇒ Object
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_instance ⇒ Object
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 |
#client ⇒ Object
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 update!(messages_handled: + 1) end |
#memory ⇒ Object
89 90 91 |
# File 'app/models/active_matrix/agent.rb', line 89 def memory @memory ||= ActiveMatrix::Memory::AgentMemory.new(self) end |
#running? ⇒ 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 |