Minor changes all around
* Wordbot does not IO.inspect() the winners of the round * Split Omnibot.Plugin.base_children/1 into base_children_before/1 and base_children_after/1 for plugins that come before and after the children in the module * Other minor changes Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -127,7 +127,6 @@ defmodule Omnibot.Contrib.Wordbot do
|
|||||||
|> Enum.reverse()
|
|> Enum.reverse()
|
||||||
|> Enum.with_index()
|
|> Enum.with_index()
|
||||||
|> Map.new()
|
|> Map.new()
|
||||||
|> IO.inspect()
|
|
||||||
|
|
||||||
Enum.each(scores, &Irc.send_to(irc, channel, "#{rankings[&1.score] + 1}. #{Util.denotify_nick(&1.user)}. #{&1.score}"))
|
Enum.each(scores, &Irc.send_to(irc, channel, "#{rankings[&1.score] + 1}. #{Util.denotify_nick(&1.user)}. #{&1.score}"))
|
||||||
|
|
||||||
|
|||||||
@@ -34,15 +34,15 @@ defmodule Omnibot.Plugin do
|
|||||||
GenServer.start_link(__MODULE__, cfg, opts)
|
GenServer.start_link(__MODULE__, cfg, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
def cfg() do
|
def cfg() when unquote(opts[:include_base]) do
|
||||||
Omnibot.Plugin.CfgState.cfg(__MODULE__.CfgState)
|
Omnibot.Plugin.CfgState.cfg(__MODULE__.CfgState)
|
||||||
end
|
end
|
||||||
|
|
||||||
def state() do
|
def state() when unquote(opts[:include_base]) do
|
||||||
Omnibot.Plugin.CfgState.state(__MODULE__.CfgState)
|
Omnibot.Plugin.CfgState.state(__MODULE__.CfgState)
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_state(fun) do
|
def update_state(fun) when unquote(opts[:include_base]) do
|
||||||
Omnibot.Plugin.CfgState.update_state(__MODULE__.CfgState, fun)
|
Omnibot.Plugin.CfgState.update_state(__MODULE__.CfgState, fun)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -54,7 +54,13 @@ defmodule Omnibot.Plugin do
|
|||||||
## Server callbacks
|
## Server callbacks
|
||||||
|
|
||||||
@impl GenServer
|
@impl GenServer
|
||||||
def init(_cfg) do
|
def init(cfg) do
|
||||||
|
# call on_init(cfg) for the plugin
|
||||||
|
state = on_init(cfg)
|
||||||
|
# If we know this plugin uses CfgState, then use that
|
||||||
|
if unquote(opts[:include_base]) do
|
||||||
|
Omnibot.Plugin.CfgState.update_state(__MODULE__.CfgState, fn _ -> state end)
|
||||||
|
end
|
||||||
{:ok, nil}
|
{:ok, nil}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -64,19 +70,22 @@ defmodule Omnibot.Plugin do
|
|||||||
{:noreply, state}
|
{:noreply, state}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp base_children(cfg, state) when unquote(opts[:include_base]) do
|
defp base_children_before(cfg) when unquote(opts[:include_base]) do
|
||||||
[
|
[{Omnibot.Plugin.CfgState, cfg: cfg, name: __MODULE__.CfgState}]
|
||||||
{Omnibot.Plugin.CfgState, cfg: cfg, state: state, name: __MODULE__.CfgState},
|
|
||||||
{__MODULE__, name: __MODULE__},
|
|
||||||
]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp base_children(_cfg, _state), do: []
|
defp base_children_after(cfg) when unquote(opts[:include_base]) do
|
||||||
|
[{__MODULE__, cfg: cfg, name: __MODULE__}]
|
||||||
|
end
|
||||||
|
|
||||||
|
defp base_children_before(_cfg), do: []
|
||||||
|
|
||||||
|
defp base_children_after(_cfg), do: []
|
||||||
|
|
||||||
@impl Omnibot.Plugin
|
@impl Omnibot.Plugin
|
||||||
def children(cfg), do: []
|
def children(cfg), do: []
|
||||||
|
|
||||||
def plugin_children(cfg, state), do: base_children(cfg, state) ++ children(cfg)
|
def plugin_children(cfg), do: base_children_before(cfg) ++ children(cfg) ++ base_children_after(cfg)
|
||||||
|
|
||||||
@behaviour Omnibot.Plugin
|
@behaviour Omnibot.Plugin
|
||||||
defoverridable Omnibot.Plugin
|
defoverridable Omnibot.Plugin
|
||||||
|
|||||||
@@ -21,8 +21,7 @@ defmodule Omnibot.Plugin.Supervisor do
|
|||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def init({plugin, cfg}) when is_atom(plugin) do
|
def init({plugin, cfg}) when is_atom(plugin) do
|
||||||
state = plugin.on_init(cfg)
|
children = plugin.plugin_children(cfg)
|
||||||
children = IO.inspect(plugin.plugin_children(cfg, state))
|
|
||||||
Supervisor.init(children, strategy: :one_for_one)
|
Supervisor.init(children, strategy: :one_for_one)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user