diff options
Diffstat (limited to 'lib/irc/connection.ex')
-rw-r--r-- | lib/irc/connection.ex | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/lib/irc/connection.ex b/lib/irc/connection.ex index 62d52d8..87da466 100644 --- a/lib/irc/connection.ex +++ b/lib/irc/connection.ex @@ -172,14 +172,14 @@ defmodule Nola.Irc.Connection do GenServer.start_link(__MODULE__, [conn], name: {:global, conn.id}) end - def broadcast_message(net, chan, message) do - dispatch("conn", {:broadcast, net, chan, message}, Nola.Irc.ConnectionPubSub) - end - def broadcast_message(list, message) when is_list(list) do - for {net, chan} <- list do - broadcast_message(net, chan, message) - end + def broadcast_message(net, chan, message, meta \\ []) do + dispatch("conn", {:broadcast, net, chan, message}, meta, Nola.Irc.ConnectionPubSub) end + #def broadcast_message(list, message, meta \\ []) when is_list(list) do + # for {net, chan} <- list do + # broadcast_message(net, chan, message, meta) + # end + #send def privmsg(channel, line) do GenServer.cast(__MODULE__, {:privmsg, channel, line}) @@ -412,11 +412,11 @@ defmodule Nola.Irc.Connection do def publish(pub), do: publish(pub, []) def publish(m = %Nola.Message{trigger: nil}, keys) do - dispatch(["messages"] ++ keys, {:irc, :text, m}) + dispatch(["messages"] ++ keys, {:irc, :text, m}, Enum.into(m.meta, [])) end def publish(m = %Nola.Message{trigger: t = %Nola.Trigger{trigger: trigger}}, keys) do - dispatch(["triggers", "#{m.network}/#{m.channel}:triggers", "trigger:"<>trigger], {:irc, :trigger, trigger, m}) + dispatch(["triggers", "#{m.network}/#{m.channel}:triggers", "trigger:"<>trigger], {:irc, :trigger, trigger, m}, Enum.into(m.meta, [])) end def publish_event(net, event = %{type: _}) when is_binary(net) do @@ -433,15 +433,17 @@ defmodule Nola.Irc.Connection do dispatch("#{net}/#{chan}:events", {:irc, :event, event}) end - def dispatch(keys, content, sub \\ Nola.PubSub) + def dispatch(keys, content, meta \\ [], sub \\ Nola.PubSub) - def dispatch(key, content, sub) when is_binary(key), do: dispatch([key], content, sub) - def dispatch(keys, content, sub) when is_list(keys) do + def dispatch(key, content, meta, sub) when is_binary(key), do: dispatch([key], content, meta, sub) + def dispatch(keys, content, meta, sub) when is_list(keys) do + Logger.debug("dispatching: #{inspect keys} #{inspect content}") should_dispatch_data = should_dispatch_data(content) + origin = Keyword.get(meta, :origin, :no_origin) for key <- keys do spawn(fn() -> Registry.dispatch(sub, key, fn h -> - for {pid, reg} <- h, do: if(should_dispatch?(key, should_dispatch_data, reg), do: send(pid, content)) + for {pid, reg} <- h, do: if(should_dispatch?(key, origin, should_dispatch_data, reg), do: send(pid, content)) end) end) end @@ -461,10 +463,10 @@ defmodule Nola.Irc.Connection do [] end - def should_dispatch?(_, [], _), do: true - def should_dispatch?(_, data, reg) do + def should_dispatch?(_, _, [], _), do: true + def should_dispatch?(key, origin, data, reg) do if plugin = Keyword.get(reg, :plugin) do - !Enum.member?(data, plugin) + plugin != origin || !Enum.member?(data, plugin) else true end |