2020-06-12 17:29:35 -04:00
|
|
|
defmodule Omnibot.Supervisor do
|
|
|
|
|
@moduledoc false
|
|
|
|
|
|
|
|
|
|
use Supervisor
|
2020-07-01 12:04:51 -07:00
|
|
|
require IEx
|
2020-06-12 17:29:35 -04:00
|
|
|
|
|
|
|
|
def start_link(opts) do
|
|
|
|
|
Supervisor.start_link(__MODULE__, :ok, opts)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
|
def init(:ok) do
|
|
|
|
|
{_, bindings} = Code.eval_file("omnibot.exs")
|
|
|
|
|
cfg = bindings[:config]
|
|
|
|
|
|
|
|
|
|
children = [
|
|
|
|
|
{Task.Supervisor, name: Omnibot.RouterSupervisor, strategy: :one_for_one},
|
|
|
|
|
{Omnibot.State, cfg: cfg, name: Omnibot.State},
|
2020-07-02 18:53:45 -07:00
|
|
|
{Omnibot.Plugin.Supervisor, cfg: cfg, name: Omnibot.Plugin.Supervisor},
|
2020-06-14 16:47:44 -04:00
|
|
|
] ++ unless IEx.started?(),
|
|
|
|
|
do: [{Omnibot.Irc, name: Omnibot.Irc}],
|
|
|
|
|
else: []
|
2020-06-12 17:29:35 -04:00
|
|
|
|
|
|
|
|
# TODO : how to handle config reloading?
|
|
|
|
|
|
|
|
|
|
# :one_for_all here because the RouterSupervisor and IRC server are co-dependent
|
|
|
|
|
Supervisor.init(children, strategy: :one_for_all)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|