From c1602065ae92396641f86034d9dae216797902dd Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Tue, 11 Aug 2020 16:17:42 -0700 Subject: [PATCH] Update Omnibot.Core state to use a map for flexibility More things need to be added to Omnibot.Core's state, so it's been expanded to a map to allow for that. Signed-off-by: Alek Ratzloff --- lib/core.ex | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/core.ex b/lib/core.ex index 25f5571..261c970 100644 --- a/lib/core.ex +++ b/lib/core.ex @@ -47,13 +47,13 @@ defmodule Omnibot.Core do @impl true def on_init(_cfg) do - MapSet.new() + %{channels: MapSet.new()} end defp sync_channels(irc) do cfg = Irc.cfg(irc) desired = MapSet.new(Config.all_channels(cfg)) - present = state() + present = state().channels to_join = MapSet.difference(desired, present) |> MapSet.to_list() @@ -65,11 +65,11 @@ defmodule Omnibot.Core do end defp add_channel(channel) do - update_state(fn state -> MapSet.put(state, channel) end) + update_state(fn cfg = %{channels: channels} -> %{cfg | channels: MapSet.put(channels, channel)} end) end defp remove_channel(channel) do - update_state(fn state -> MapSet.delete(state, channel) end) + update_state(fn cfg = %{channels: channels} -> %{cfg | channels: MapSet.delete(channels, channel)} end) end end