From 1f574dd0eb7c9b6bd8dc99ef36acbd8d0a10ee2d Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Tue, 11 Aug 2020 15:58:42 -0700 Subject: [PATCH] Remove lib/state.ex Signed-off-by: Alek Ratzloff --- lib/state.ex | 108 --------------------------------------------------- 1 file changed, 108 deletions(-) delete mode 100644 lib/state.ex diff --git a/lib/state.ex b/lib/state.ex deleted file mode 100644 index 9482e1b..0000000 --- a/lib/state.ex +++ /dev/null @@ -1,108 +0,0 @@ -defmodule Omnibot.State do - - @moduledoc "" - - use GenServer - - @enforce_keys [:cfg] - defstruct [:cfg, channels: MapSet.new(), plugin_map: %{}] - - ## Client API - - @deprecated "Get rid of this" - def start_link(opts) do - cfg = opts[:cfg] - GenServer.start_link(__MODULE__, %Omnibot.State{ - cfg: cfg - }, opts) - end - - @deprecated "Use Irc.cfg/1 instead" - @doc "Gets the current configuration from the default State process." - def cfg(), do: cfg(__MODULE__) - - @deprecated "Get rid of this" - @doc "Gets the current configuration from the given State process." - def cfg(state) do - GenServer.call(state, :cfg) - end - - @deprecated "Get rid of this" - @doc "Adds a loaded plugin to the default state." - def add_loaded_plugin(plugin), do: add_loaded_plugin(__MODULE__, plugin) - - @deprecated "Get rid of this" - @doc "Adds a loaded plugin to the given state." - def add_loaded_plugin(state, {plugin, cfg}), do: GenServer.cast(state, {:add_loaded_plugin, {plugin, cfg}}) - - @deprecated "Get rid of this" - @doc "Adds a loaded plugin to the given state." - def add_loaded_plugin(state, plugin), do: add_loaded_plugin(state, {plugin, []}) - - @deprecated "Get rid of this" - @doc "Gets all loaded plugins from the default state." - def loaded_plugins(), do: loaded_plugins(__MODULE__) - - @deprecated "Get rid of this" - @doc "Gets all loaded plugins from the given state." - def loaded_plugins(state), do: GenServer.call(state, :loaded_plugins) - - @deprecated "Get rid of this" - def all_channels(), do: all_channels(__MODULE__) - - @deprecated "Get rid of this" - def all_channels(state) do - loaded_plugins(state) |> Enum.flat_map( - fn {_, cfg} -> - case cfg[:channels] do - :all -> [] - nil -> [] - channels -> channels - end - end) - |> MapSet.new() - |> MapSet.to_list() - end - - @deprecated "Get rid of this" - def channel_plugins(channel), do: channel_plugins(__MODULE__, channel) - - @deprecated "Get rid of this" - @doc ~S""" - Gets a list of all `{plugin, plug_cfg}` from the given State that are both - loaded, and listening to the given channel. - """ - def channel_plugins(state, channel) do - loaded_plugins(state) |> Enum.filter( - fn {_, cfg} -> - cfg[:channels] == :all or Enum.member?(cfg[:channels] || [], channel) - end) - end - - ## Server API - - @deprecated "Get rid of this" - @impl true - def init(state) do - {:ok, state} - end - - @deprecated "Get rid of this" - @impl true - def handle_call(:cfg, _from, state) do - {:reply, state.cfg, state} - end - - @deprecated "Get rid of this" - @impl true - def handle_call(:loaded_plugins, _from, state) do - {:reply, state.plugin_map, state} - end - - @deprecated "Get rid of this" - @impl true - def handle_cast({:add_loaded_plugin, {plugin, cfg}}, state) do - state = %{state | plugin_map: Map.put(state.plugin_map, plugin, cfg)} - {:noreply, state} - end -end