summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Bracco <href@random.sh>2022-12-20 03:37:05 +0000
committerJordan Bracco <href@random.sh>2022-12-20 19:29:42 +0100
commit8a130bbafe90b45bf99e63091d11082e0a675c1b (patch)
treeb0c129724b9d00da2a9cff261891955ab98cb739
parentRename IRC.{Message,Trigger} to Nola.{Message,Trigger}, refs T77. (diff)
More IRC. cleanup, refs T77.
-rw-r--r--lib/irc/connection.ex2
-rw-r--r--lib/irc/irc.ex44
-rw-r--r--lib/irc/message.ex28
-rw-r--r--lib/irc/nola_irc.ex25
-rw-r--r--lib/nola/application.ex4
-rw-r--r--lib/plugins/link/html.ex2
-rw-r--r--lib/plugins/link/twitter.ex4
7 files changed, 51 insertions, 58 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
diff --git a/lib/nola/application.ex b/lib/nola/application.ex
index fa880ea..d56d4cb 100644
--- a/lib/nola/application.ex
+++ b/lib/nola/application.ex
@@ -26,7 +26,7 @@ defmodule Nola.Application do
worker(Nola.UserTrack.Storage, []),
worker(Nola.Plugins.Account, []),
supervisor(Nola.Plugins.Supervisor, [], [name: Nola.Plugins.Supervisor]),
- ] ++ Nola.IRC.application_childs
+ ] ++ Nola.Irc.application_childs
++ Nola.Matrix.application_childs
opts = [strategy: :one_for_one, name: Nola.Supervisor]
@@ -34,7 +34,7 @@ defmodule Nola.Application do
start_telegram()
Nola.Plugins.start_all()
- spawn_link(fn() -> Nola.IRC.after_start() end)
+ spawn_link(fn() -> Nola.Irc.after_start() end)
spawn_link(fn() -> Nola.Matrix.after_start() end)
spawn_link(fn() -> Nola.TelegramRoom.after_start() end)
sup
diff --git a/lib/plugins/link/html.ex b/lib/plugins/link/html.ex
index 9b44319..a941aac 100644
--- a/lib/plugins/link/html.ex
+++ b/lib/plugins/link/html.ex
@@ -46,7 +46,7 @@ defmodule Nola.Plugins.Link.HTML do
else
""
end
- [clean_text("#{prefix}#{Map.get(opengraph, "title")}")] ++ IRC.splitlong(clean_text("#{date}#{Map.get(opengraph, "description")}"))
+ [clean_text("#{prefix}#{Map.get(opengraph, "title")}")] ++ Nola.Irc.Message.splitlong(clean_text("#{date}#{Map.get(opengraph, "description")}"))
else
clean_text(title)
end
diff --git a/lib/plugins/link/twitter.ex b/lib/plugins/link/twitter.ex
index e7f3e63..48e6bae 100644
--- a/lib/plugins/link/twitter.ex
+++ b/lib/plugins/link/twitter.ex
@@ -68,7 +68,7 @@ defmodule Nola.Plugins.Link.Twitter do
else
text
end
- text = IRC.splitlong(text)
+ text = Nola.Irc.Message.splitlong(text)
reply_to = if tweet.in_reply_to_status_id do
reply_url = link_tweet({tweet.in_reply_to_screen_name, tweet.in_reply_to_status_id}, opts)
@@ -79,7 +79,7 @@ defmodule Nola.Plugins.Link.Twitter do
quoted = if tweet.quoted_status do
full_text = tweet.quoted_status
|> expand_twitter_text(opts)
- |> IRC.splitlong_with_prefix(">")
+ |> Nola.Irc.Message.splitlong_with_prefix(">")
head = format_tweet_header(tweet.quoted_status, opts, details: false, prefix: "↓ quoting")