Files
omnibot/lib/router.ex
Alek Ratzloff 304a8d4164 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>
2020-06-13 17:13:05 -04:00

51 lines
1.4 KiB
Elixir

defmodule Omnibot.Router do
require Logger
alias Omnibot.{Irc.Msg, State}
def route(irc, msg) do
#channel = Msg.channel(msg)
channel = IO.inspect(Msg.channel(msg))
IO.inspect(State.channel_modules(channel))
State.channel_modules(channel)
|> Enum.each(fn {module, _} -> module.on_msg(irc, msg) end)
end
#def handle(_irc, :privmsg, msg) do
# [channel | _params] = msg.params
# # Find modules that want this message
# State.cfg()
# |> Config.channel_modules(channel)
# |> Enum.each(fn {module, _} -> module.on_msg(msg) end)
#end
#def handle(_irc, :join, msg: %Msg {params: [channel | _]}) do
# State.cfg()
# |> Config.channel_modules(channel)
# |> Enum.each(fn {module, _} -> module.on_join(msg) end)
#end
#def handle(irc, :kick, msg: %Msg {params: [channel | _]}) do
# State.cfg()
# |> Config.channel_modules(channel)
# |> Enum.each(fn {module, _} -> module.on_kick(msg) end)
#end
#def handle(_irc, :part, %Msg {prefix: %Msg.Prefix{nick: nick}, params: [channel | _]}) do
# cfg = State.cfg()
# if nick == cfg.nick do
# State.remove_channel(State, channel)
# end
#end
#def handle(irc, :ping, msg) do
# cfg = State.cfg()
# reply = Config.msg(cfg, "PONG", msg.params)
# Irc.send_msg(irc, reply)
#end
#def handle(irc, :welcome, _msg) do
# Irc.sync_channels(irc)
#end
end