Rearrange lib/core.ex code some more
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
28
lib/core.ex
28
lib/core.ex
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user