Previously, core behavior was handled in the Omnibot.Router module. However, since the module system is robust enough, this work has been delegated to the Omnibot.Core module. Additionally, the Omnibot.State module has been augmented to keep track of the modules that have been currently loaded, and methods that are used to get the list of loaded modules and routing information for those modules are coming from Omnibot.State as well (as opposed to Omnibot.Config). This is to avoid requiring the Omnibot.Core module be included in the config, plus avoiding modification of the runtime config after it has already been loaded. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
49 lines
1.3 KiB
Elixir
49 lines
1.3 KiB
Elixir
defmodule Omnibot.Router do
|
|
require Logger
|
|
alias Omnibot.{Irc.Msg, State}
|
|
|
|
def route(irc, msg) do
|
|
channel = Msg.channel(msg)
|
|
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
|