diff options
Diffstat (limited to 'controllers')
-rw-r--r-- | controllers/cartridges.rb | 2 | ||||
-rw-r--r-- | controllers/instance.rb | 8 | ||||
-rw-r--r-- | controllers/session.rb | 12 |
3 files changed, 14 insertions, 8 deletions
diff --git a/controllers/cartridges.rb b/controllers/cartridges.rb index 151cc46..fe0d56e 100644 --- a/controllers/cartridges.rb +++ b/controllers/cartridges.rb @@ -39,7 +39,7 @@ module NanoBot rescue StandardError => _e end - cartridges.sort_by { |cartridge| cartridge[:meta][:name] } + cartridges = cartridges.sort_by { |cartridge| cartridge[:meta][:name] } cartridges.prepend( { system: { id: '-' }, meta: { name: 'Default', symbol: '🤖' } } diff --git a/controllers/instance.rb b/controllers/instance.rb index a982261..d4e0c1b 100644 --- a/controllers/instance.rb +++ b/controllers/instance.rb @@ -13,14 +13,16 @@ require_relative './session' module NanoBot module Controllers class Instance - def initialize(cartridge_path:, stream:, state: nil) + def initialize(cartridge_path:, stream:, state: nil, environment: {}) @stream = stream load_cartridge!(cartridge_path) - provider = Components::Provider.new(@cartridge[:provider]) + provider = Components::Provider.new(@cartridge[:provider], environment:) - @session = Session.new(provider:, cartridge: @cartridge, state:, stream: @stream) + @session = Session.new( + provider:, cartridge: @cartridge, state:, stream: @stream, environment: + ) end def cartridge diff --git a/controllers/session.rb b/controllers/session.rb index 270b623..4694911 100644 --- a/controllers/session.rb +++ b/controllers/session.rb @@ -9,6 +9,7 @@ require_relative '../logic/cartridge/streaming' require_relative '../logic/cartridge/interaction' require_relative '../components/storage' require_relative '../components/adapter' +require_relative '../components/crypto' module NanoBot module Controllers @@ -17,7 +18,7 @@ module NanoBot class Session attr_accessor :stream - def initialize(provider:, cartridge:, state: nil, stream: $stdout) + def initialize(provider:, cartridge:, state: nil, stream: $stdout, environment: {}) @stream = stream @provider = provider @cartridge = cartridge @@ -28,8 +29,9 @@ module NanoBot @state = { history: [] } else @state_path = Components::Storage.build_path_and_ensure_state_file!( - state.strip, @cartridge + state.strip, @cartridge, environment: ) + @state = load_state end end @@ -39,11 +41,13 @@ module NanoBot end def load_state - @state = Logic::Helpers::Hash.symbolize_keys(JSON.parse(File.read(@state_path))) + @state = Logic::Helpers::Hash.symbolize_keys(JSON.parse( + Components::Crypto.decrypt(File.read(@state_path)) + )) end def store_state! - File.write(@state_path, JSON.generate(@state)) + File.write(@state_path, Components::Crypto.encrypt(JSON.generate(@state))) end def boot(mode:) |