summaryrefslogtreecommitdiff
path: root/lib/irc
diff options
context:
space:
mode:
authorhref <href@random.sh>2021-09-01 10:30:18 +0200
committerhref <href@random.sh>2021-09-01 10:30:18 +0200
commit75687711f35355bc30e4829439384aab28fcac6d (patch)
tree8f3256f472893c39720a684d390e890a152f7303 /lib/irc
parentlink: post_* callbacks; html & pdftitle. (diff)
Commit all the changes that hasn't been committed + updates.
Diffstat (limited to 'lib/irc')
-rw-r--r--lib/irc/account.ex3
-rw-r--r--lib/irc/connection.ex11
-rw-r--r--lib/irc/plugin_supervisor.ex14
3 files changed, 19 insertions, 9 deletions
diff --git a/lib/irc/account.ex b/lib/irc/account.ex
index 6f9eb05..0aa8638 100644
--- a/lib/irc/account.ex
+++ b/lib/irc/account.ex
@@ -19,7 +19,8 @@ defmodule IRC.Account do
# FIXME: Ensure uniqueness of name?
defstruct [:id, :name, :token]
- @type t :: %__MODULE__{id: String.t(), name: String.t()}
+ @type t :: %__MODULE__{id: id(), name: String.t()}
+ @type id :: String.t()
defimpl Inspect, for: __MODULE__ do
import Inspect.Algebra
diff --git a/lib/irc/connection.ex b/lib/irc/connection.ex
index d115d88..b83c4d3 100644
--- a/lib/irc/connection.ex
+++ b/lib/irc/connection.ex
@@ -211,13 +211,13 @@ defmodule IRC.Connection do
else
Logger.info("Connecting")
{:ok, client} = ExIRC.Client.start_link(debug: false)
+ ExIRC.Client.add_handler(client, self())
client
end
- ExIRC.Client.add_handler(client, self())
if state.conn.tls do
- ExIRC.Client.connect_ssl!(client, state.conn.host, state.conn.port)
+ ExIRC.Client.connect_ssl!(client, state.conn.host, state.conn.port, [])#[{:ifaddr, {45,150,150,33}}])
else
- ExIRC.Client.connect!(client, state.conn.host, state.conn.port)
+ ExIRC.Client.connect!(client, state.conn.host, state.conn.port, [])#[{:ifaddr, {45,150,150,33}}])
end
{:noreply, %{state | client: client}}
end
@@ -241,8 +241,9 @@ defmodule IRC.Connection do
# Connection successful
def handle_info({:connected, server, port}, state) do
Logger.info("#{inspect(self())} Connected to #{server}:#{port} #{inspect state}")
+ {_, backoff} = :backoff.succeed(state.backoff)
ExIRC.Client.logon(state.client, state.conn.pass || "", state.conn.nick, state.conn.user, state.conn.name)
- {:noreply, state}
+ {:noreply, %{state | backoff: backoff}}
end
# Logon successful
@@ -344,7 +345,7 @@ defmodule IRC.Connection do
end
def handle_info({:parted, channel, %ExIRC.SenderInfo{nick: nick}}, state) do
- IRC.UserTrack.parted(channel, nick)
+ IRC.UserTrack.parted(network(state), channel, nick)
{:noreply, state}
end
diff --git a/lib/irc/plugin_supervisor.ex b/lib/irc/plugin_supervisor.ex
index ca092dc..5f93f17 100644
--- a/lib/irc/plugin_supervisor.ex
+++ b/lib/irc/plugin_supervisor.ex
@@ -3,15 +3,24 @@ defmodule IRC.Plugin do
defmodule Supervisor do
use DynamicSupervisor
+ require Logger
def start_link() do
DynamicSupervisor.start_link(__MODULE__, [], name: __MODULE__)
end
def start_child(module, opts \\ []) do
- IO.inspect(module)
+ Logger.info("Starting #{module}")
spec = %{id: {IRC.Plugin,module}, start: {IRC.Plugin, :start_link, [module, opts]}, name: module, restart: :transient}
- DynamicSupervisor.start_child(__MODULE__, spec)
+ case DynamicSupervisor.start_child(__MODULE__, spec) do
+ {:ok, _} = res -> res
+ :ignore ->
+ Logger.info("Ignored #{module}")
+ :ignore
+ {:error,_} = res ->
+ Logger.error("Could not start #{module}: #{inspect(res, pretty: true)}")
+ res
+ end
end
@impl true
@@ -88,4 +97,3 @@ defmodule IRC.Plugin do
end
end
-