diff options
Diffstat (limited to 'lib/irc')
-rw-r--r-- | lib/irc/connection.ex | 18 | ||||
-rw-r--r-- | lib/irc/puppet_connection.ex | 28 |
2 files changed, 23 insertions, 23 deletions
diff --git a/lib/irc/connection.ex b/lib/irc/connection.ex index cff556d..7a0ca9d 100644 --- a/lib/irc/connection.ex +++ b/lib/irc/connection.ex @@ -1,4 +1,4 @@ -defmodule IRC.Connection do +defmodule Nola.Irc.Connection do require Logger use Ecto.Schema @@ -10,7 +10,7 @@ defmodule IRC.Connection do ## Start connections ``` - IRC.Connection.start_link(host: "irc.random.sh", port: 6697, nick: "pouetbot", channels: ["#dev"]) + Nola.Irc.Connection.start_link(host: "irc.random.sh", port: 6697, nick: "pouetbot", channels: ["#dev"]) ## PubSub topics @@ -53,8 +53,8 @@ defmodule IRC.Connection do DynamicSupervisor.start_link(__MODULE__, [], name: __MODULE__) end - def start_child(%IRC.Connection{} = conn) do - spec = %{id: conn.id, start: {IRC.Connection, :start_link, [conn]}, restart: :transient} + def start_child(%Nola.Irc.Connection{} = conn) do + spec = %{id: conn.id, start: {Nola.Irc.Connection, :start_link, [conn]}, restart: :transient} DynamicSupervisor.start_child(__MODULE__, spec) end @@ -106,7 +106,7 @@ defmodule IRC.Connection do end def start_all() do - for conn <- connections(), do: {conn, IRC.Connection.Supervisor.start_child(conn)} + for conn <- connections(), do: {conn, Nola.Irc.Connection.Supervisor.start_child(conn)} end def get_network(network, channel \\ nil) do @@ -140,7 +140,7 @@ defmodule IRC.Connection do end def start_connection(%__MODULE__{} = conn) do - IRC.Connection.Supervisor.start_child(conn) + Nola.Irc.Connection.Supervisor.start_child(conn) end def stop_connection(%__MODULE__{id: id}) do @@ -158,7 +158,7 @@ defmodule IRC.Connection do {:error, {:existing, conn}} else :dets.insert(dets(), to_tuple(conn)) - IRC.Connection.Supervisor.start_child(conn) + Nola.Irc.Connection.Supervisor.start_child(conn) end error -> error end @@ -173,7 +173,7 @@ defmodule IRC.Connection do end def broadcast_message(net, chan, message) do - dispatch("conn", {:broadcast, net, chan, message}, IRC.ConnectionPubSub) + 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 @@ -212,7 +212,7 @@ defmodule IRC.Connection do def handle_continue(:connect, state) do client_opts = [] |> Keyword.put(:network, state.conn.network) - {:ok, _} = Registry.register(IRC.ConnectionPubSub, "conn", []) + {:ok, _} = Registry.register(Nola.Irc.ConnectionPubSub, "conn", []) client = if state.client && Process.alive?(state.client) do Logger.info("Reconnecting client") state.client diff --git a/lib/irc/puppet_connection.ex b/lib/irc/puppet_connection.ex index 2604876..f5e2e5c 100644 --- a/lib/irc/puppet_connection.ex +++ b/lib/irc/puppet_connection.ex @@ -1,4 +1,4 @@ -defmodule IRC.PuppetConnection do +defmodule Nola.Irc.PuppetConnection do require Logger @min_backoff :timer.seconds(5) @max_backoff :timer.seconds(2*60) @@ -12,8 +12,8 @@ defmodule IRC.PuppetConnection do DynamicSupervisor.start_link(__MODULE__, [], name: __MODULE__) end - def start_child(%Nola.Account{id: account_id}, %IRC.Connection{id: connection_id}) do - spec = %{id: {account_id, connection_id}, start: {IRC.PuppetConnection, :start_link, [account_id, connection_id]}, restart: :transient} + def start_child(%Nola.Account{id: account_id}, %Nola.Irc.Connection{id: connection_id}) do + spec = %{id: {account_id, connection_id}, start: {Nola.Irc.PuppetConnection, :start_link, [account_id, connection_id]}, restart: :transient} DynamicSupervisor.start_child(__MODULE__, spec) end @@ -27,7 +27,7 @@ defmodule IRC.PuppetConnection do end end - def whereis(account = %Nola.Account{id: account_id}, connection = %IRC.Connection{id: connection_id}) do + def whereis(account = %Nola.Account{id: account_id}, connection = %Nola.Irc.Connection{id: connection_id}) do {:global, name} = name(account_id, connection_id) case :global.whereis_name(name) do :undefined -> nil @@ -35,15 +35,15 @@ defmodule IRC.PuppetConnection do end end - def send_message(account = %Nola.Account{id: account_id}, connection = %IRC.Connection{id: connection_id}, channel, text) do + def send_message(account = %Nola.Account{id: account_id}, connection = %Nola.Irc.Connection{id: connection_id}, channel, text) do GenServer.cast(name(account_id, connection_id), {:send_message, self(), channel, text}) end - def start_and_send_message(account = %Nola.Account{id: account_id}, connection = %IRC.Connection{id: connection_id}, channel, text) do + def start_and_send_message(account = %Nola.Account{id: account_id}, connection = %Nola.Irc.Connection{id: connection_id}, channel, text) do {:global, name} = name(account_id, connection_id) pid = whereis(account, connection) pid = if !pid do - case IRC.PuppetConnection.Supervisor.start_child(account, connection) do + case Nola.Irc.PuppetConnection.Supervisor.start_child(account, connection) do {:ok, pid} -> pid {:error, {:already_started, pid}} -> pid end @@ -53,8 +53,8 @@ defmodule IRC.PuppetConnection do GenServer.cast(pid, {:send_message, self(), channel, text}) end - def start(account = %Nola.Account{}, connection = %IRC.Connection{}) do - IRC.PuppetConnection.Supervisor.start_child(account, connection) + def start(account = %Nola.Account{}, connection = %Nola.Irc.Connection{}) do + Nola.Irc.PuppetConnection.Supervisor.start_child(account, connection) end def start_link(account_id, connection_id) do @@ -67,7 +67,7 @@ defmodule IRC.PuppetConnection do def init([account_id, connection_id]) do account = %Nola.Account{} = Nola.Account.get(account_id) - connection = %IRC.Connection{} = IRC.Connection.lookup(connection_id) + connection = %Nola.Irc.Connection{} = Nola.Irc.Connection.lookup(connection_id) Logger.metadata(puppet_conn: account.id <> "@" <> connection.id) backoff = :backoff.init(@min_backoff, @max_backoff) |> :backoff.type(:jitter) @@ -85,7 +85,7 @@ defmodule IRC.PuppetConnection do # ipv6 #end - conn = IRC.Connection.lookup(state.connection_id) + conn = Nola.Irc.Connection.lookup(state.connection_id) client_opts = [] |> Keyword.put(:network, conn.network) client = if state.client && Process.alive?(state.client) do @@ -150,14 +150,14 @@ defmodule IRC.PuppetConnection do nick = make_nick(state) sender = %ExIRC.SenderInfo{network: state.network, nick: suffix_nick(nick), user: nick, host: "puppet."} reply_fun = fn(text) -> - IRC.Connection.broadcast_message(state.network, channel, text) + Nola.Irc.Connection.broadcast_message(state.network, channel, text) end - message = %Nola.Message{id: FlakeId.get(), at: NaiveDateTime.utc_now(), text: text, network: state.network, account: account, sender: sender, channel: channel, replyfun: reply_fun, trigger: IRC.Connection.extract_trigger(text), meta: meta} + message = %Nola.Message{id: FlakeId.get(), at: NaiveDateTime.utc_now(), text: text, network: state.network, account: account, sender: sender, channel: channel, replyfun: reply_fun, trigger: Nola.Irc.Connection.extract_trigger(text), meta: meta} message = case Nola.UserTrack.messaged(message) do :ok -> message {:ok, message} -> message end - IRC.Connection.publish(message, ["#{message.network}/#{channel}:messages"]) + Nola.Irc.Connection.publish(message, ["#{message.network}/#{channel}:messages"]) idle = if length(state.buffer) == 0 do :erlang.cancel_timer(state.idle) |