diff options
author | Jordan Bracco <href@random.sh> | 2022-12-20 03:37:05 +0000 |
---|---|---|
committer | Jordan Bracco <href@random.sh> | 2022-12-20 19:29:42 +0100 |
commit | 8a130bbafe90b45bf99e63091d11082e0a675c1b (patch) | |
tree | b0c129724b9d00da2a9cff261891955ab98cb739 /lib/irc/irc.ex | |
parent | Rename IRC.{Message,Trigger} to Nola.{Message,Trigger}, refs T77. (diff) |
More IRC. cleanup, refs T77.
Diffstat (limited to '')
-rw-r--r-- | lib/irc/irc.ex | 44 |
1 files changed, 17 insertions, 27 deletions
diff --git a/lib/irc/irc.ex b/lib/irc/irc.ex index a1d97a2..dd1a5d2 100644 --- a/lib/irc/irc.ex +++ b/lib/irc/irc.ex @@ -1,4 +1,8 @@ -defmodule IRC do +defmodule Nola.Irc do + require Logger + + def env(), do: Nola.env(:irc) + def env(key, default \\ nil), do: Keyword.get(env(), key, default) def send_message_as(account, network, channel, text, force_puppet \\ false) do connection = IRC.Connection.get_network(network) @@ -11,13 +15,6 @@ defmodule IRC do end end - def register(key) do - case Registry.register(Nola.PubSub, key, []) do - {:ok, _} -> :ok - error -> error - end - end - def admin?(%Message{sender: sender}), do: admin?(sender) def admin?(%{nick: nick, user: user, host: host}) do @@ -31,29 +28,22 @@ defmodule IRC do defp admin_part_match?(a, a), do: true defp admin_part_match?(_, _), do: false - @max_chars 440 - - def splitlong(string, max_chars \\ 440) + def application_childs do + import Supervisor.Spec - def splitlong(string, max_chars) when is_list(string) do - Enum.map(string, fn(s) -> splitlong(s, max_chars) end) - |> List.flatten() - end + IRC.Connection.setup() - def splitlong(string, max_chars) do - string - |> String.codepoints - |> Enum.chunk_every(max_chars) - |> Enum.map(&Enum.join/1) + [ + worker(Registry, [[keys: :duplicate, name: IRC.ConnectionPubSub]], id: :registr_irc_conn), + supervisor(IRC.Connection.Supervisor, [], [name: IRC.Connection.Supervisor]), + supervisor(IRC.PuppetConnection.Supervisor, [], [name: IRC.PuppetConnection.Supervisor]), + ] end - def splitlong_with_prefix(string, prefix, max_chars \\ 440) do - prefix = "#{prefix} " - max_chars = max_chars - (length(String.codepoints(prefix))) - string - |> String.codepoints - |> Enum.chunk_every(max_chars) - |> Enum.map(fn(line) -> prefix <> Enum.join(line) end) + # Start plugins first to let them get on connection events. + def after_start() do + Logger.info("Starting connections") + IRC.Connection.start_all() end end |