Move more stuff from other places into Omnibot.Core
* Present rooms are tracked by Omnibot.Core now, instead of Omnibot.State * Channel synchronization is done through Omnibot.Core instead of Omnibot.Irc * Add Omnibot.Module.on_init/1 callback, which returns a "state" value for the module to keep track of. By default, the state is nil. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
18
lib/irc.ex
18
lib/irc.ex
@@ -28,8 +28,6 @@ defmodule Omnibot.Irc do
|
||||
|
||||
def part(irc, channel), do: send_msg(irc, "PART", channel)
|
||||
|
||||
def sync_channels(irc), do: GenServer.cast(irc, :sync_channels)
|
||||
|
||||
defp route_msg(irc, msg) do
|
||||
channel = Msg.channel(msg)
|
||||
State.channel_modules(channel)
|
||||
@@ -72,22 +70,6 @@ defmodule Omnibot.Irc do
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_cast(:sync_channels, socket) do
|
||||
cfg = State.cfg()
|
||||
desired = MapSet.new(Config.all_channels(cfg))
|
||||
present = MapSet.new(State.channels())
|
||||
to_join = MapSet.difference(desired, present)
|
||||
|> MapSet.to_list()
|
||||
to_part = MapSet.difference(present, desired)
|
||||
|> MapSet.to_list()
|
||||
|
||||
Enum.each(to_join, fn channel -> join(self(), channel) end)
|
||||
Enum.each(to_part, fn channel -> part(self(), channel) end)
|
||||
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_info({:tcp, _socket, line}, socket) do
|
||||
Logger.debug(String.trim(line))
|
||||
|
||||
Reference in New Issue
Block a user