summaryrefslogtreecommitdiff
path: root/lib/irc
diff options
context:
space:
mode:
authorhref <href@random.sh>2020-03-11 21:18:34 +0100
committerhref <href@random.sh>2020-03-11 21:18:34 +0100
commita28d24470ddeca6196219a1333c1ccac1319efef (patch)
tree4f29e3c8fb6afbb1f99d6b8737f844c95fca54df /lib/irc
parentup to 420*100 (diff)
welp
Diffstat (limited to '')
-rw-r--r--lib/irc.ex25
-rw-r--r--lib/irc/pubsub_handler.ex11
2 files changed, 32 insertions, 4 deletions
diff --git a/lib/irc.ex b/lib/irc.ex
index 6ba819c..f989366 100644
--- a/lib/irc.ex
+++ b/lib/irc.ex
@@ -31,4 +31,29 @@ 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 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/pubsub_handler.ex b/lib/irc/pubsub_handler.ex
index 3e78d7b..450dc2f 100644
--- a/lib/irc/pubsub_handler.ex
+++ b/lib/irc/pubsub_handler.ex
@@ -6,7 +6,7 @@ defmodule IRC.PubSubHandler do
## PubSub topics
- * `message` -- all messages (including triggers)
+ * `message` -- all messages (without triggers)
* `message:private` -- all messages without a channel
* `message:#CHANNEL` -- all messages within `#CHANNEL`
* `triggers` -- all triggers
@@ -34,6 +34,7 @@ defmodule IRC.PubSubHandler do
"-" => :minus,
"?" => :query,
"." => :dot,
+ "~" => :tilde
}
def handle_info({:received, text, sender, chan}, client) do
@@ -62,7 +63,7 @@ defmodule IRC.PubSubHandler do
end
defp publish(m = %IRC.Message{trigger: t = %IRC.Trigger{trigger: trigger}}, keys) do
- dispatch(["message", "triggers", "trigger:"<>trigger]++keys, {:irc, :trigger, trigger, m})
+ dispatch(["triggers", "trigger:"<>trigger], {:irc, :trigger, trigger, m})
end
defp dispatch(key, content) when is_binary(key), do: dispatch([key], content)
@@ -96,8 +97,10 @@ defmodule IRC.PubSubHandler 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(client, {target, _}, text) when is_binary(text) do
- ExIRC.Client.msg(client, :privmsg, target, text)
+ defp irc_reply(client, {target, _}, text) when is_binary(text) or is_list(text) do
+ for line <- IRC.splitlong(text) do
+ ExIRC.Client.msg(client, :privmsg, target, line)
+ end
end
defp irc_reply(client, {target, %{nick: nick}}, {:kick, reason}) do