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:
2020-06-13 17:13:05 -04:00
parent 590b3ddbec
commit 304a8d4164
12 changed files with 172 additions and 106 deletions

View File

@@ -22,16 +22,12 @@ defmodule Omnibot.Irc do
def send_msg(irc, command, param), do: send_msg(irc, command, [param])
def send_to(channel, text), do: send_to(__MODULE__, channel, text)
def send_to(irc, channel, text), do: send_msg(irc, "PRIVMSG", [channel, text])
def join(channel), do: join(__MODULE__, channel)
def join(irc, channel), do: send_msg(irc, "JOIN", channel)
def part(channel), do: part(__MODULE__, channel)
def part(irc, channel), do: send_msg(irc, "PART", channel)
def sync_channels(), do: sync_channels(__MODULE__)
def sync_channels(irc), do: GenServer.cast(irc, :sync_channels)
## Server callbacks
@@ -45,7 +41,6 @@ defmodule Omnibot.Irc do
:gen_tcp.connect(to_charlist(cfg.server), cfg.port, [:binary, active: false, packet: :line])
# Wait for first message
#{:ok, _} = :gen_tcp.recv(socket, 0)
send_msg(self(), "NICK", cfg.nick)
send_msg(self(), "USER", [cfg.user, "0", "*", cfg.real])
:inet.setopts(socket, [active: true])