From 91cdd9cae8a08cbdf412347aece53d6b36501ea5 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Sat, 13 Jun 2020 18:11:18 -0400 Subject: [PATCH] Remove router.ex and move behavior to Omnibot.Irc Omnibot.Router was useful when it was used for actually routing messages. However, its responsibilities have spread such that it's just a single function at this point. So this single function has been moved to Omnibot.Irc as a private function instead. Signed-off-by: Alek Ratzloff --- lib/irc.ex | 8 +++++++- lib/router.ex | 48 ------------------------------------------------ 2 files changed, 7 insertions(+), 49 deletions(-) delete mode 100644 lib/router.ex diff --git a/lib/irc.ex b/lib/irc.ex index 404da00..c138209 100644 --- a/lib/irc.ex +++ b/lib/irc.ex @@ -30,6 +30,12 @@ defmodule Omnibot.Irc do def sync_channels(irc), do: GenServer.cast(irc, :sync_channels) + defp route_msg(irc, msg) do + channel = Msg.channel(msg) + State.channel_modules(channel) + |> Enum.each(fn {module, _} -> module.on_msg(irc, msg) end) + end + ## Server callbacks @impl true @@ -91,7 +97,7 @@ defmodule Omnibot.Irc do irc = self() {:ok, _task} = Task.Supervisor.start_child( Omnibot.RouterSupervisor, - fn -> Omnibot.Router.route(irc, msg) end + fn -> route_msg(irc, msg) end ) {:noreply, socket} end diff --git a/lib/router.ex b/lib/router.ex deleted file mode 100644 index 6e444ef..0000000 --- a/lib/router.ex +++ /dev/null @@ -1,48 +0,0 @@ -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