WIP: Move to using modules for implementing core behavior

Since modules can now intercept all messages in the channels they're
listening for, it'd be cool to have modules handling things like making
sure the Omnibot.State stays updated as appropriate, and that pings are
ponged, etc.

This will probably deprecate the router, since it's been reduced to a
single function call, but we'll see about that.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-06-13 16:04:19 -04:00
parent 5f251d22ce
commit 73c5f58243
5 changed files with 65 additions and 60 deletions

View File

@@ -17,7 +17,10 @@ defmodule Omnibot.Config do
Gets all channels that the bot should join via its modules.
"""
def all_channels(cfg) do
Enum.flat_map(cfg.modules, fn {_, [channels: channels]} -> channels end)
Enum.flat_map(cfg.modules, fn
{_, [channels: :all]} -> []
{_, [channels: channels]} -> channels
end)
|> MapSet.new()
|> MapSet.to_list()
end
@@ -28,7 +31,9 @@ defmodule Omnibot.Config do
"""
def channel_modules(cfg, channel) do
cfg.modules
|> Enum.filter(fn {_, cfg} -> Enum.member?(cfg[:channels] || [], channel) end)
|> Enum.filter(fn {_, cfg} ->
cfg[:channels] == :all or Enum.member?(cfg[:channels] || [], channel)
end)
end
def msg_prefix(cfg) do