cover/Elixir.Agent.Ask.html

1 defmodule Agent.Ask do
2 import String, only: [trim: 1]
3 import Tape, only: [handle: 4]
4 import Agent.Watch, only: [start: 3]
5
6 def reply(message, body, state) do
7
:-(
process(message, body, state)
8 end
9
10 defp process(message, body, %{name: n, tape: t, runner: r, folder: f}) do
11
:-(
start(n, message, f)
12
:-(
opts = [tape: t]
13
:-(
emit(handle(body, n, fn -> r.(message, f) end, opts), n)
14 end
15
16 defp emit([%{"text" => text, "type" => "text"}], name) do
17
:-(
text = trim(text)
18
:-(
answer(name, text)
19
:-(
text
20 end
21
22 defp emit([%{"text" => text}], name) do
23
:-(
text = trim(text)
24
:-(
answer(name, text)
25
:-(
text
26 end
27
28
:-(
defp emit(_, _), do: ""
29
30 defp answer(agent, text) do
31
:-(
:erlang.apply(:"Elixir.Tools.Sys.Ask", :answer, [agent, text])
32 end
33 end
Line Hits Source