fix send message channels, and legacy fe logging
This commit is contained in:
parent
293dcdfba4
commit
a7bfbd26e8
|
@ -25,12 +25,13 @@ defmodule Farmbot.BotState.Transport.GenMQTT do
|
|||
end
|
||||
|
||||
def handle_log_events(logs, {%{client: client} = internal_state, old_bot_state}) do
|
||||
# Logger.error 1, "FIX LOGGING!"
|
||||
# location_data = Map.get(old_bot_state || %{}, :location_data, %{position: %{x: -1, y: -1, z: -1}})
|
||||
# for log_without_pos <- logs do
|
||||
# log = add_position_to_log(log_without_pos, location_data)
|
||||
# Client.push_bot_log(client, log)
|
||||
# end
|
||||
for log <- logs do
|
||||
location_data = Map.get(old_bot_state || %{}, :location_data, %{position: %{x: -1, y: -1, z: -1}})
|
||||
meta = %{type: log.level, x: nil, y: nil, z: nil}
|
||||
log_without_pos = %{meta: meta, channels: log.meta[:channels] || [], message: log.message}
|
||||
log = add_position_to_log(log_without_pos, location_data)
|
||||
Client.push_bot_log(client, log)
|
||||
end
|
||||
|
||||
{:noreply, [], {internal_state, old_bot_state}}
|
||||
end
|
||||
|
|
|
@ -4,12 +4,13 @@ defmodule Farmbot.CeleryScript.AST.Node.SendMessage do
|
|||
use Farmbot.Logger
|
||||
allow_args [:message, :message_type]
|
||||
|
||||
def execute(%{message: m, message_type: type}, _, env) do
|
||||
def execute(%{message: m, message_type: type}, channels, env) do
|
||||
env = mutate_env(env)
|
||||
{:ok, env, channels} = do_reduce(channels, env, [])
|
||||
msg = String.replace(m, "{{", "<%=")
|
||||
|> String.replace("}}", "%>")
|
||||
|> EEx.eval_string(fetch_bindings())
|
||||
apply(Logger, type, [msg])
|
||||
apply(Logger, type, [msg, [channels: channels]])
|
||||
{:ok, env}
|
||||
rescue
|
||||
e in CompileError ->
|
||||
|
@ -23,4 +24,10 @@ defmodule Farmbot.CeleryScript.AST.Node.SendMessage do
|
|||
location = Enum.map(bot_state.location_data.position, fn({axis, val}) -> {axis, val} end)
|
||||
pins ++ location
|
||||
end
|
||||
|
||||
defp do_reduce([%{args: %{channel_name: channel}} | rest], env, acc) do
|
||||
do_reduce(rest, env, [channel | acc])
|
||||
end
|
||||
|
||||
defp do_reduce([], env, acc), do: {:ok, env, acc}
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue