Add default_config, and cfg[:timeout] for tasks

- Using the @default_config attribute in a module will fill out a default
value.
- cfg[:timeout] sets the timeout for the task for this module to finish.
- Update Omnibot.Irc.route_msg/2 to have each task spawn a second task,
  while the first task waits for its child to finish, otherwise killing
  it.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-06-13 21:47:46 -04:00
parent a6a07adf7a
commit 4083b5b858
5 changed files with 30 additions and 11 deletions

View File

@@ -15,16 +15,15 @@ defmodule Omnibot.ModuleSupervisor do
# These are modules that need to be loaded for core functionality of the bot
core = [
{Omnibot.Core, cfg: [channels: :all]},
Omnibot.Core
]
# Map the modules in the configuration to the children
children =
core ++
for mod <- cfg.modules do
for mod <- (core ++ cfg.modules) do
case mod do
{name, cfg} -> {name, cfg: cfg, name: name}
name -> {name, cfg: [], name: name}
{name, cfg} -> {name, cfg: cfg ++ name.default_config(), name: name}
name -> {name, cfg: name.default_config(), name: name}
end
end