Rearrange lib/core.ex code some more

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-08-18 16:41:51 -07:00
parent d3de274e48
commit 528334bff8

View File

@@ -23,6 +23,20 @@ defmodule Omnibot.Core do
update_state(fn cfg -> %{cfg | last_reply: last_reply} end) update_state(fn cfg -> %{cfg | last_reply: last_reply} end)
end end
defp sync_channels(irc) do
cfg = Irc.cfg(irc)
desired = MapSet.new(Config.all_channels(cfg))
present = state().channels
to_join = MapSet.difference(desired, present)
|> MapSet.to_list()
to_part = MapSet.difference(present, desired)
|> MapSet.to_list()
Enum.each(to_join, fn channel -> Irc.join(irc, channel) end)
Enum.each(to_part, fn channel -> Irc.part(irc, channel) end)
end
## Server callbacks ## Server callbacks
@impl true @impl true
@@ -90,20 +104,6 @@ defmodule Omnibot.Core do
%{channels: MapSet.new(), last_reply: Util.now_unix()} %{channels: MapSet.new(), last_reply: Util.now_unix()}
end end
defp sync_channels(irc) do
cfg = Irc.cfg(irc)
desired = MapSet.new(Config.all_channels(cfg))
present = state().channels
to_join = MapSet.difference(desired, present)
|> MapSet.to_list()
to_part = MapSet.difference(present, desired)
|> MapSet.to_list()
Enum.each(to_join, fn channel -> Irc.join(irc, channel) end)
Enum.each(to_part, fn channel -> Irc.part(irc, channel) end)
end
## Ping watcher worker ## Ping watcher worker
defp ping_watcher(irc) do defp ping_watcher(irc) do