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 | |
parent | Rename IRC.{Message,Trigger} to Nola.{Message,Trigger}, refs T77. (diff) |
More IRC. cleanup, refs T77.
Diffstat (limited to 'lib/irc')
-rw-r--r-- | lib/irc/connection.ex | 2 | ||||
-rw-r--r-- | lib/irc/irc.ex | 44 | ||||
-rw-r--r-- | lib/irc/message.ex | 28 | ||||
-rw-r--r-- | lib/irc/nola_irc.ex | 25 |
4 files changed, 46 insertions, 53 deletions
diff --git a/lib/irc/connection.ex b/lib/irc/connection.ex index 037b7d6..cff556d 100644 --- a/lib/irc/connection.ex +++ b/lib/irc/connection.ex @@ -458,7 +458,7 @@ 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(state = %{client: client, network: network}, {target, _}, text) when is_binary(text) or is_list(text) do - lines = IRC.splitlong(text) + lines = Nola.Irc.Message.splitlong(text) |> Enum.map(fn(x) -> if(is_list(x), do: x, else: String.split(x, "\n")) end) |> List.flatten() outputs = for line <- lines do 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 diff --git a/lib/irc/message.ex b/lib/irc/message.ex new file mode 100644 index 0000000..3927079 --- /dev/null +++ b/lib/irc/message.ex @@ -0,0 +1,28 @@ +defmodule Nola.Irc.Message do + + @max_chars 440 + + def splitlong(string, max_chars \\ 440) + + def splitlong(string, max_chars) when is_list(string) do + Enum.map(string, fn(s) -> splitlong(s, max_chars) end) + |> List.flatten() + end + + def splitlong(string, max_chars) do + string + |> String.codepoints + |> Enum.chunk_every(max_chars) + |> Enum.map(&Enum.join/1) + 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) + end + +end diff --git a/lib/irc/nola_irc.ex b/lib/irc/nola_irc.ex deleted file mode 100644 index 4ed94d1..0000000 --- a/lib/irc/nola_irc.ex +++ /dev/null @@ -1,25 +0,0 @@ -defmodule Nola.IRC do - require Logger - - def env(), do: Nola.env(:irc) - def env(key, default \\ nil), do: Keyword.get(env(), key, default) - - def application_childs do - import Supervisor.Spec - - IRC.Connection.setup() - - [ - 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 - - # Start plugins first to let them get on connection events. - def after_start() do - Logger.info("Starting connections") - IRC.Connection.start_all() - end - -end |