summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Bracco <href@random.sh>2023-03-05 10:12:52 +0100
committerJordan Bracco <href@random.sh>2023-03-05 10:12:52 +0100
commit0ead6760c4b069583a797bc95a6598098ed9c20e (patch)
treea9d494abada4e18ffff652c46914a0f4a50c949a
parentplugin: gpt (diff)
plugins: fix logger
-rw-r--r--lib/plugins/logger.ex23
1 files changed, 17 insertions, 6 deletions
diff --git a/lib/plugins/logger.ex b/lib/plugins/logger.ex
index 3d643d3..9b47cd8 100644
--- a/lib/plugins/logger.ex
+++ b/lib/plugins/logger.ex
@@ -27,8 +27,12 @@ defmodule Nola.Plugins.Logger do
{:noreply, log(m, state)}
end
+ def handle_info({:irc, :out, m}, state) do
+ {:noreply, log(m, state)}
+ end
+
def handle_info(info, state) do
- Logger.debug("logger_plugin: unhandled info: #{info}")
+ Logger.debug("logger_plugin: unhandled info: #{inspect info}")
{:noreply, state}
end
@@ -53,12 +57,19 @@ defmodule Nola.Plugins.Logger do
end
def format_to_db(msg = %Nola.Message{id: id}) do
- msg
- |> Poison.encode!()
- |> Map.drop("id")
+ channel = cond do
+ msg.channel -> msg.channel
+ msg.account -> msg.account.id
+ msg.sender -> msg.sender.nick
+ true -> nil
+ end
+
+ id = [msg.network, channel, id]
+ |> Enum.filter(& &1)
+ |> Enum.join(":")
- %{"_id" => id || FlakeId.get(),
- "type" => "irc.message/v1",
+ %{"_id" => id,
+ "type" => "nola.message:v1",
"object" => msg}
end