The problem: When we're going through the list of modules to send messages to based on the channels they're a part of, it was being done so through the config. Since the config doesn't (and shouldn't) list all of the core modules that get included, any core modules that were loaded and running under the ModuleSupervisor would not get included in the router's attempt to send messages to a module. Now, the Config.all_channels and Config.channel_modules functions live in State, and State has a new "add_loaded_module" function where loaded modules are registered. The aforementioned moved functions will use this as the "source of truth" when deciding where to send messages for modules to handle. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
47 lines
904 B
Elixir
47 lines
904 B
Elixir
defmodule Omnibot.Config do
|
|
alias Omnibot.Irc.Msg
|
|
|
|
@enforce_keys [:server]
|
|
defstruct [
|
|
:server,
|
|
nick: "omnibot",
|
|
user: "omnibot",
|
|
real: "omnibot",
|
|
port: 6667,
|
|
ssl: false,
|
|
modules: [],
|
|
module_paths: []
|
|
]
|
|
|
|
@doc ~S"""
|
|
Gets all channels that the bot should join via its modules.
|
|
"""
|
|
def all_channels(cfg) do
|
|
Enum.flat_map(cfg.modules, fn
|
|
{_, [channels: :all]} -> []
|
|
{_, [channels: channels]} -> channels
|
|
end)
|
|
|> MapSet.new()
|
|
|> MapSet.to_list()
|
|
end
|
|
|
|
def msg_prefix(cfg) do
|
|
%Msg.Prefix {
|
|
nick: cfg.nick,
|
|
user: cfg.user,
|
|
}
|
|
end
|
|
|
|
@doc ~S"""
|
|
Make a new message with the given command and parameters using the given
|
|
configuration to build the prefix.
|
|
"""
|
|
def msg(cfg, command, params \\ []) do
|
|
%Msg {
|
|
prefix: msg_prefix(cfg),
|
|
command: command,
|
|
params: params,
|
|
}
|
|
end
|
|
end
|