Finish migration to using a module to control core behavior
Previously, core behavior was handled in the Omnibot.Router module. However, since the module system is robust enough, this work has been delegated to the Omnibot.Core module. Additionally, the Omnibot.State module has been augmented to keep track of the modules that have been currently loaded, and methods that are used to get the list of loaded modules and routing information for those modules are coming from Omnibot.State as well (as opposed to Omnibot.Config). This is to avoid requiring the Omnibot.Core module be included in the config, plus avoiding modification of the runtime config after it has already been loaded. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -14,11 +14,13 @@ defmodule Omnibot.ModuleSupervisor do
|
||||
compile_files(cfg.module_paths || [])
|
||||
|
||||
# These are modules that need to be loaded for core functionality of the bot
|
||||
#{Omnibot.Core.Welcome, cfg: [channels: :all]},
|
||||
#{Omnibot.Core.Join, cfg: [channels: :all]},
|
||||
core = [
|
||||
{Omnibot.Core, cfg: [channels: :all]},
|
||||
]
|
||||
|
||||
# Map the modules in the configuration to the children
|
||||
children =
|
||||
core ++
|
||||
for mod <- cfg.modules do
|
||||
case mod do
|
||||
{name, cfg} -> {name, cfg: cfg, name: name}
|
||||
@@ -27,7 +29,7 @@ defmodule Omnibot.ModuleSupervisor do
|
||||
end
|
||||
|
||||
# Add each child to the "loaded modules" list in the State
|
||||
Enum.each(children, fn module -> State.add_loaded_module(module) end)
|
||||
Enum.each(IO.inspect(children), fn {module, opts} -> State.add_loaded_module({module, opts[:cfg]}) end)
|
||||
|
||||
Supervisor.init(children, strategy: :one_for_one)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user