WIP: Move Config.all_channels/0 and Config.channel_modules/1 logic into State; add State.add_loaded_module/2
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>
This commit is contained in:
@@ -25,17 +25,6 @@ defmodule Omnibot.Config do
|
||||
|> MapSet.to_list()
|
||||
end
|
||||
|
||||
@doc ~S"""
|
||||
Gets a list of all `{module, mod_cfg}` pairs from the given configuration
|
||||
that are listening to the given channel.
|
||||
"""
|
||||
def channel_modules(cfg, channel) do
|
||||
cfg.modules
|
||||
|> Enum.filter(fn {_, cfg} ->
|
||||
cfg[:channels] == :all or Enum.member?(cfg[:channels] || [], channel)
|
||||
end)
|
||||
end
|
||||
|
||||
def msg_prefix(cfg) do
|
||||
%Msg.Prefix {
|
||||
nick: cfg.nick,
|
||||
|
||||
Reference in New Issue
Block a user