Rearrange lib/core.ex code
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
36
lib/core.ex
36
lib/core.ex
@@ -5,6 +5,26 @@ defmodule Omnibot.Core do
|
||||
|
||||
@default_config quit_after: 180, ping_after: 60, channels: :all
|
||||
|
||||
## Client API
|
||||
|
||||
defp add_channel(channel) do
|
||||
update_state(fn cfg = %{channels: channels} -> %{cfg | channels: MapSet.put(channels, channel)} end)
|
||||
end
|
||||
|
||||
defp remove_channel(channel) do
|
||||
update_state(fn cfg = %{channels: channels} -> %{cfg | channels: MapSet.delete(channels, channel)} end)
|
||||
end
|
||||
|
||||
defp last_reply() do
|
||||
state().last_reply
|
||||
end
|
||||
|
||||
defp update_last_reply(last_reply) do
|
||||
update_state(fn cfg -> %{cfg | last_reply: last_reply} end)
|
||||
end
|
||||
|
||||
## Server callbacks
|
||||
|
||||
@impl true
|
||||
def children(_cfg) do
|
||||
[{Task.Supervisor, name: Omnibot.Core.PingWatchers}]
|
||||
@@ -84,21 +104,7 @@ defmodule Omnibot.Core do
|
||||
Enum.each(to_part, fn channel -> Irc.part(irc, channel) end)
|
||||
end
|
||||
|
||||
defp add_channel(channel) do
|
||||
update_state(fn cfg = %{channels: channels} -> %{cfg | channels: MapSet.put(channels, channel)} end)
|
||||
end
|
||||
|
||||
defp remove_channel(channel) do
|
||||
update_state(fn cfg = %{channels: channels} -> %{cfg | channels: MapSet.delete(channels, channel)} end)
|
||||
end
|
||||
|
||||
defp last_reply() do
|
||||
state().last_reply
|
||||
end
|
||||
|
||||
defp update_last_reply(last_reply) do
|
||||
update_state(fn cfg -> %{cfg | last_reply: last_reply} end)
|
||||
end
|
||||
## Ping watcher worker
|
||||
|
||||
defp ping_watcher(irc) do
|
||||
since_reply = Util.now_unix() - last_reply()
|
||||
|
||||
Reference in New Issue
Block a user