diff options
author | href <href@random.sh> | 2022-12-11 01:47:26 +0000 |
---|---|---|
committer | Jordan Bracco <href@random.sh> | 2022-12-11 02:03:36 +0000 |
commit | d97e6d09f0db87989df42993499429883f1c224a (patch) | |
tree | 314132c1d68b271979c293318b6bf8e7aacbedce /lib/lsg_irc | |
parent | fix(user-track): ensure we only get an user per network even if it's over mul... (diff) |
feat(message): assign id (flake_id)
Diffstat (limited to 'lib/lsg_irc')
-rw-r--r-- | lib/lsg_irc/logger_plugin.ex | 15 | ||||
-rw-r--r-- | lib/lsg_irc/sms_plugin.ex | 3 |
2 files changed, 14 insertions, 4 deletions
diff --git a/lib/lsg_irc/logger_plugin.ex b/lib/lsg_irc/logger_plugin.ex index 667f714..e5307bc 100644 --- a/lib/lsg_irc/logger_plugin.ex +++ b/lib/lsg_irc/logger_plugin.ex @@ -13,6 +13,7 @@ defmodule LSG.IRC.LoggerPlugin do regopts = [plugin: __MODULE__] {:ok, _} = Registry.register(IRC.PubSub, "triggers", regopts) {:ok, _} = Registry.register(IRC.PubSub, "messages", regopts) + {:ok, _} = Registry.register(IRC.PubSub, "messages:private", regopts) {:ok, nil} end @@ -49,12 +50,20 @@ defmodule LSG.IRC.LoggerPlugin do state end - def format_to_db(m = %IRC.Message{}) do - %IRC.Message{m | replyfun: nil} + def format_to_db(msg = %IRC.Message{id: id}) do + msg + |> Poison.encode!() + |> Map.drop("id") + + %{"_id" => id || FlakeId.get(), + "type" => "irc.message/v1", + "object" => msg} end def format_to_db(anything) do - anything + %{"_id" => FlakeId.get(), + "type" => "object", + "object" => anything} end end diff --git a/lib/lsg_irc/sms_plugin.ex b/lib/lsg_irc/sms_plugin.ex index b183f7d..be1611f 100644 --- a/lib/lsg_irc/sms_plugin.ex +++ b/lib/lsg_irc/sms_plugin.ex @@ -34,6 +34,7 @@ defmodule LSG.IRC.SmsPlugin do "!"<>message end message = %IRC.Message{ + id: FlakeId.get(), transport: :sms, network: "sms", channel: nil, @@ -43,7 +44,7 @@ defmodule LSG.IRC.SmsPlugin do replyfun: reply_fun, trigger: IRC.Connection.extract_trigger(trigger_text) } - IO.puts("converted sms to message: #{inspect message}") + Logger.debug("converted sms to message: #{inspect message}") IRC.Connection.publish(message, ["messages:sms"]) message end |