diff options
Diffstat (limited to 'lib/irc')
-rw-r--r-- | lib/irc/connection.ex | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/lib/irc/connection.ex b/lib/irc/connection.ex index fee84c3..e856114 100644 --- a/lib/irc/connection.ex +++ b/lib/irc/connection.ex @@ -239,7 +239,7 @@ defmodule IRC.Connection do end def handle_cast({:privmsg, channel, line}, state) do - irc_reply(state.client, {channel, nil}, line) + irc_reply(state, {channel, nil}, line) {:noreply, state} end @@ -273,20 +273,20 @@ defmodule IRC.Connection do # Received something in a channel def handle_info({:received, text, sender, chan}, state) do - reply_fun = fn(text) -> irc_reply(state.client, {chan, sender}, text) end + reply_fun = fn(text) -> irc_reply(state, {chan, sender}, text) end account = IRC.Account.lookup(sender) message = %IRC.Message{text: text, network: network(state), account: account, sender: sender, channel: chan, replyfun: reply_fun, trigger: extract_trigger(text)} message = case IRC.UserTrack.messaged(message) do :ok -> message {:ok, message} -> message end - publish(message, ["message:#{chan}"]) + publish(message, ["message:#{chan}", "#{message.network}/#{chan}:message"]) {:noreply, state} end # Received a private message def handle_info({:received, text, sender}, state) do - reply_fun = fn(text) -> irc_reply(state.client, {sender.nick, sender}, text) end + reply_fun = fn(text) -> irc_reply(state, {sender.nick, sender}, text) end account = IRC.Account.lookup(sender) message = %IRC.Message{text: text, network: network(state), account: account, sender: sender, replyfun: reply_fun, trigger: extract_trigger(text)} message = case IRC.UserTrack.messaged(message) do @@ -302,14 +302,14 @@ defmodule IRC.Connection do if net == state.conn.network do user = IRC.UserTrack.find_by_account(net, account) if user do - irc_reply(state.client, {user.nick, nil}, message) + irc_reply(state, {user.nick, nil}, message) end end {:noreply, state} end def handle_info({:broadcast, net, chan, message}, state) do if net == state.conn.network && Enum.member?(state.conn.channels, chan) do - irc_reply(state.client, {chan, nil}, message) + irc_reply(state, {chan, nil}, message) end {:noreply, state} end @@ -382,7 +382,7 @@ defmodule IRC.Connection do end def publish(m = %IRC.Message{trigger: t = %IRC.Trigger{trigger: trigger}}, keys) do - dispatch(["triggers", "trigger:"<>trigger], {:irc, :trigger, trigger, m}) + dispatch(["triggers", "#{m.network}/#{m.channel}:triggers", "trigger:"<>trigger], {:irc, :trigger, trigger, m}) end def dispatch(keys, content, sub \\ IRC.PubSub) @@ -419,32 +419,36 @@ defmodule IRC.Connection do # irc_reply(ExIRC.Client pid, {channel or nick, ExIRC.Sender}, binary | replies # replies :: {:kick, reason} | {:kick, nick, reason} | {:mode, mode, nick} - defp irc_reply(client, {target, _}, text) when is_binary(text) or is_list(text) do + defp irc_reply(%{client: client, network: network}, {target, _}, text) when is_binary(text) or is_list(text) do lines = IRC.splitlong(text) |> Enum.map(fn(x) -> if(is_list(x), do: x, else: String.split(x, "\n")) end) |> List.flatten() for line <- lines do ExIRC.Client.msg(client, :privmsg, target, line) end + case :global.whereis_name({LSG.TelegramRoom, network, target}) do + pid when is_pid(pid) -> send(pid, {:raw, text}) + _ -> :ok + end end - defp irc_reply(client, {target, %{nick: nick}}, {:kick, reason}) do + defp irc_reply(%{client: client}, {target, %{nick: nick}}, {:kick, reason}) do ExIRC.Client.kick(client, target, nick, reason) end - defp irc_reply(client, {target, _}, {:kick, nick, reason}) do + defp irc_reply(%{client: client}, {target, _}, {:kick, nick, reason}) do ExIRC.Client.kick(client, target, nick, reason) end - defp irc_reply(client, {target, %{nick: nick}}, {:mode, mode}) do - ExIRC.Client.mode(client, target, mode, nick) + defp irc_reply(%{client: client}, {target, %{nick: nick}}, {:mode, mode}) do + ExIRC.Client.mode(%{client: client}, target, mode, nick) end - defp irc_reply(client, target, {:mode, mode, nick}) do + defp irc_reply(%{client: client}, target, {:mode, mode, nick}) do ExIRC.Client.mode(client, target, mode, nick) end - defp irc_reply(client, target, {:channel_mode, mode}) do + defp irc_reply(%{client: client}, target, {:channel_mode, mode}) do ExIRC.Client.mode(client, target, mode) end |