Finish plugin and routing overhaul, there's a new model in town:
* Plugins all derive from Omnibot.Plugin. There still is a base plugin, in case we want to have another plugin backend instead of a GenServer * All plugins are monitored by a unique Plugin.Supervisor, which is in turn started by the PluginSupervisor (yes this is confusing, yes it needs to be renamed) * Any other auxiliary child processes may be started through the Plugin.children/1 function. * By default, plugins have a CfgState process which is an Agent that keeps track of the plugin's configuration and state * Plugin API is now called through the GenServer backend for better synchronicity. * Very few changes to the front-facing Plugin API, which is nice Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -21,14 +21,15 @@ defmodule Omnibot.PluginSupervisor do
|
||||
# Map the plugins in the configuration to the children
|
||||
children =
|
||||
for plug <- (core ++ cfg.plugins) do
|
||||
case plug do
|
||||
{name, cfg} -> {name, cfg: cfg ++ name.default_config(), name: name}
|
||||
name -> {name, cfg: name.default_config(), name: name}
|
||||
{name, cfg} = case plug do
|
||||
{name, cfg} -> {name, cfg ++ name.default_config()}
|
||||
name -> {name, name.default_config()}
|
||||
end
|
||||
{Omnibot.Plugin.Supervisor, plugin: name, cfg: cfg}
|
||||
end
|
||||
|
||||
# Add each child to the "loaded plugins" list in the State
|
||||
Enum.each(children, fn {plugin, opts} -> State.add_loaded_plugin({plugin, opts[:cfg]}) end)
|
||||
Enum.each(children, fn {_plugin, opts} -> State.add_loaded_plugin({opts[:plugin], opts[:cfg]}) end)
|
||||
|
||||
Supervisor.init(children, strategy: :one_for_one)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user