Add deprecations for Omnibot.State functions

We're getting rid of the State hack module, because each IRC connection
should hold onto its own config.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-08-11 12:46:54 -07:00
parent f89b31520b
commit b423507796

View File

@@ -1,4 +1,7 @@
defmodule Omnibot.State do defmodule Omnibot.State do
@moduledoc ""
use GenServer use GenServer
@enforce_keys [:cfg] @enforce_keys [:cfg]
@@ -6,6 +9,7 @@ defmodule Omnibot.State do
## Client API ## Client API
@deprecated "Get rid of this"
def start_link(opts) do def start_link(opts) do
cfg = opts[:cfg] cfg = opts[:cfg]
GenServer.start_link(__MODULE__, %Omnibot.State{ GenServer.start_link(__MODULE__, %Omnibot.State{
@@ -13,31 +17,40 @@ defmodule Omnibot.State do
}, opts) }, opts)
end end
@deprecated "Use Irc.cfg/1 instead"
@doc "Gets the current configuration from the default State process." @doc "Gets the current configuration from the default State process."
def cfg(), do: cfg(__MODULE__) def cfg(), do: cfg(__MODULE__)
@deprecated "Get rid of this"
@doc "Gets the current configuration from the given State process." @doc "Gets the current configuration from the given State process."
def cfg(state) do def cfg(state) do
GenServer.call(state, :cfg) GenServer.call(state, :cfg)
end end
@deprecated "Get rid of this"
@doc "Adds a loaded plugin to the default state." @doc "Adds a loaded plugin to the default state."
def add_loaded_plugin(plugin), do: add_loaded_plugin(__MODULE__, plugin) 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." @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}}) 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." @doc "Adds a loaded plugin to the given state."
def add_loaded_plugin(state, plugin), do: add_loaded_plugin(state, {plugin, []}) 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." @doc "Gets all loaded plugins from the default state."
def loaded_plugins(), do: loaded_plugins(__MODULE__) def loaded_plugins(), do: loaded_plugins(__MODULE__)
@deprecated "Get rid of this"
@doc "Gets all loaded plugins from the given state." @doc "Gets all loaded plugins from the given state."
def loaded_plugins(state), do: GenServer.call(state, :loaded_plugins) def loaded_plugins(state), do: GenServer.call(state, :loaded_plugins)
@deprecated "Get rid of this"
def all_channels(), do: all_channels(__MODULE__) def all_channels(), do: all_channels(__MODULE__)
@deprecated "Get rid of this"
def all_channels(state) do def all_channels(state) do
loaded_plugins(state) |> Enum.flat_map( loaded_plugins(state) |> Enum.flat_map(
fn {_, cfg} -> fn {_, cfg} ->
@@ -51,8 +64,10 @@ defmodule Omnibot.State do
|> MapSet.to_list() |> MapSet.to_list()
end end
@deprecated "Get rid of this"
def channel_plugins(channel), do: channel_plugins(__MODULE__, channel) def channel_plugins(channel), do: channel_plugins(__MODULE__, channel)
@deprecated "Get rid of this"
@doc ~S""" @doc ~S"""
Gets a list of all `{plugin, plug_cfg}` from the given State that are both Gets a list of all `{plugin, plug_cfg}` from the given State that are both
loaded, and listening to the given channel. loaded, and listening to the given channel.
@@ -66,21 +81,25 @@ defmodule Omnibot.State do
## Server API ## Server API
@deprecated "Get rid of this"
@impl true @impl true
def init(state) do def init(state) do
{:ok, state} {:ok, state}
end end
@deprecated "Get rid of this"
@impl true @impl true
def handle_call(:cfg, _from, state) do def handle_call(:cfg, _from, state) do
{:reply, state.cfg, state} {:reply, state.cfg, state}
end end
@deprecated "Get rid of this"
@impl true @impl true
def handle_call(:loaded_plugins, _from, state) do def handle_call(:loaded_plugins, _from, state) do
{:reply, state.plugin_map, state} {:reply, state.plugin_map, state}
end end
@deprecated "Get rid of this"
@impl true @impl true
def handle_cast({:add_loaded_plugin, {plugin, cfg}}, state) do def handle_cast({:add_loaded_plugin, {plugin, cfg}}, state) do
state = %{state | plugin_map: Map.put(state.plugin_map, plugin, cfg)} state = %{state | plugin_map: Map.put(state.plugin_map, plugin, cfg)}