summaryrefslogtreecommitdiff
path: root/logic/cartridge/interaction.rb
blob: 160d8184d890d14f051d0c0f27dab8c9fe96a203 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# frozen_string_literal: true

require 'sweet-moon'

require_relative './affixes'
require_relative './adapters'

module NanoBot
  module Logic
    module Cartridge
      module Interaction
        def self.input(cartridge, interface, content)
          lua = Adapter.expression(cartridge, interface, :input, :lua)
          fennel = Adapter.expression(cartridge, interface, :input, :fennel)

          prefix = Affixes.get(cartridge, interface, :input, :prefix)
          suffix = Affixes.get(cartridge, interface, :input, :suffix)

          { content:, prefix:, suffix:, lua:, fennel: }
        end

        def self.output(cartridge, interface, result, streaming, _finished)
          if streaming
            result[:message] = { content: result[:message], lua: nil, fennel: nil }
            return result
          end

          lua = Adapter.expression(cartridge, interface, :output, :lua)
          fennel = Adapter.expression(cartridge, interface, :output, :fennel)

          result[:message] = { content: result[:message], lua:, fennel: }

          result
        end
      end
    end
  end
end