From 528334bff8d2e6d83a1a2c1ab45d3d5c2730f535 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Tue, 18 Aug 2020 16:41:51 -0700 Subject: [PATCH] Rearrange lib/core.ex code some more Signed-off-by: Alek Ratzloff --- lib/core.ex | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/core.ex b/lib/core.ex index 3dfca18..9e3735d 100644 --- a/lib/core.ex +++ b/lib/core.ex @@ -23,6 +23,20 @@ defmodule Omnibot.Core do update_state(fn cfg -> %{cfg | last_reply: last_reply} 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 @impl true @@ -90,20 +104,6 @@ defmodule Omnibot.Core do %{channels: MapSet.new(), last_reply: Util.now_unix()} 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 defp ping_watcher(irc) do