summaryrefslogtreecommitdiff
path: root/lib/irc
diff options
context:
space:
mode:
authorhref <href@random.sh>2022-12-11 01:47:26 +0000
committerJordan Bracco <href@random.sh>2022-12-11 02:03:36 +0000
commitd97e6d09f0db87989df42993499429883f1c224a (patch)
tree314132c1d68b271979c293318b6bf8e7aacbedce /lib/irc
parentfix(user-track): ensure we only get an user per network even if it's over mul... (diff)
feat(message): assign id (flake_id)
Diffstat (limited to 'lib/irc')
-rw-r--r--lib/irc/connection.ex10
-rw-r--r--lib/irc/irc.ex6
-rw-r--r--lib/irc/puppet_connection.ex48
3 files changed, 35 insertions, 29 deletions
diff --git a/lib/irc/connection.ex b/lib/irc/connection.ex
index fcb6c5e..1e94003 100644
--- a/lib/irc/connection.ex
+++ b/lib/irc/connection.ex
@@ -294,7 +294,9 @@ defmodule IRC.Connection do
if !Map.get(user.options, :puppet) do
reply_fun = fn(text) -> irc_reply(state, {chan, sender}, text) end
account = IRC.Account.lookup(sender)
- message = %IRC.Message{at: NaiveDateTime.utc_now(), text: text, network: state.network, account: account, sender: sender, channel: chan, replyfun: reply_fun, trigger: extract_trigger(text)}
+ message = %IRC.Message{id: FlakeId.get(), transport: :irc, at: NaiveDateTime.utc_now(), text: text, network: state.network,
+ account: account, sender: sender, channel: chan, replyfun: reply_fun,
+ trigger: extract_trigger(text)}
message = case IRC.UserTrack.messaged(message) do
:ok -> message
{:ok, message} -> message
@@ -309,7 +311,8 @@ defmodule IRC.Connection do
def handle_info({:received, text, sender}, state) do
reply_fun = fn(text) -> irc_reply(state, {sender.nick, sender}, text) end
account = IRC.Account.lookup(sender)
- message = %IRC.Message{text: text, network: state.network, account: account, sender: sender, replyfun: reply_fun, trigger: extract_trigger(text)}
+ message = %IRC.Message{id: FlakeId.get(), transport: irc, text: text, network: state.network, at: NaiveDateTime.utc_now(),
+ account: account, sender: sender, replyfun: reply_fun, trigger: extract_trigger(text)}
message = case IRC.UserTrack.messaged(message) do
:ok -> message
{:ok, message} -> message
@@ -460,7 +463,8 @@ defmodule IRC.Connection do
|> List.flatten()
outputs = for line <- lines do
ExIRC.Client.msg(client, :privmsg, target, line)
- {:irc, :out, %IRC.Message{network: network, channel: target, text: line, sender: %ExIRC.SenderInfo{nick: state.conn.nick}, at: NaiveDateTime.utc_now(), meta: %{self: true}}}
+ {:irc, :out, %IRC.Message{id: FlakeId.get(), transport: :irc, network: network,
+ channel: target, text: line, sender: %ExIRC.SenderInfo{nick: state.conn.nick}, at: NaiveDateTime.utc_now(), meta: %{self: true}}}
end
for f <- outputs, do: dispatch(["irc:outputs", "#{network}/#{target}:outputs"], f)
end
diff --git a/lib/irc/irc.ex b/lib/irc/irc.ex
index 78b0611..fbad6e1 100644
--- a/lib/irc/irc.ex
+++ b/lib/irc/irc.ex
@@ -1,8 +1,9 @@
defmodule IRC do
- @derive {Poison.Encoder, except: [:replyfun]}
defmodule Message do
- defstruct [:text,
+ @derive {Poison.Encoder, except: [:replyfun]}
+ defstruct [:id,
+ :text,
{:transport, :irc},
:network,
:account,
@@ -15,6 +16,7 @@ defmodule IRC do
]
end
defmodule Trigger do
+ @derive Poison.Encoder
defstruct [:type, :trigger, :args]
end
diff --git a/lib/irc/puppet_connection.ex b/lib/irc/puppet_connection.ex
index 4604b04..f12cbf7 100644
--- a/lib/irc/puppet_connection.ex
+++ b/lib/irc/puppet_connection.ex
@@ -76,14 +76,14 @@ defmodule IRC.PuppetConnection do
end
def handle_continue(:connect, state) do
- ipv6 = if @env == :prod do
- subnet = LSG.Subnet.assign(state.account_id)
- IRC.Account.put_meta(IRC.Account.get(state.account_id), "subnet", subnet)
- ip = Pfx.host(subnet, 1)
- {:ok, ipv6} = :inet_parse.ipv6_address(to_charlist(ip))
- System.cmd("add-ip6", [ip])
- ipv6
- end
+ #ipv6 = if @env == :prod do
+ # subnet = LSG.Subnet.assign(state.account_id)
+ # IRC.Account.put_meta(IRC.Account.get(state.account_id), "subnet", subnet)
+ # ip = Pfx.host(subnet, 1)
+ # {:ok, ipv6} = :inet_parse.ipv6_address(to_charlist(ip))
+ # System.cmd("add-ip6", [ip])
+ # ipv6
+ #end
conn = IRC.Connection.lookup(state.connection_id)
client_opts = []
@@ -102,21 +102,21 @@ defmodule IRC.PuppetConnection do
{:nodelay, true}
]
- {ip, opts} = case {ipv6, :inet_res.resolve(to_charlist(conn.host), :in, :aaaa)} do
- {ipv6, {:ok, {:dns_rec, _dns_header, _query, rrs = [{:dns_rr, _, _, _, _, _, _, _, _, _} | _], _, _}}} ->
- ip = rrs
- |> Enum.map(fn({:dns_rr, _, :aaaa, :in, _, _, ipv6, _, _, _}) -> ipv6 end)
- |> Enum.shuffle()
- |> List.first()
-
- opts = [
- :inet6,
- {:ifaddr, ipv6}
- ]
- {ip, opts}
- _ ->
- {to_charlist(conn.host), []}
- end
+ #{ip, opts} = case {ipv6, :inet_res.resolve(to_charlist(conn.host), :in, :aaaa)} do
+ # {ipv6, {:ok, {:dns_rec, _dns_header, _query, rrs = [{:dns_rr, _, _, _, _, _, _, _, _, _} | _], _, _}}} ->
+ # ip = rrs
+ # |> Enum.map(fn({:dns_rr, _, :aaaa, :in, _, _, ipv6, _, _, _}) -> ipv6 end)
+ # |> Enum.shuffle()
+ # |> List.first()
+
+ # opts = [
+ # :inet6,
+ # {:ifaddr, ipv6}
+ # ]
+ # {ip, opts}
+ # _ ->
+ {ip, opts} = {to_charlist(conn.host), []}
+ #end
conn_fun = if conn.tls, do: :connect_ssl!, else: :connect!
apply(ExIRC.Client, conn_fun, [client, ip, conn.port, base_opts ++ opts])
@@ -152,7 +152,7 @@ defmodule IRC.PuppetConnection do
reply_fun = fn(text) ->
IRC.Connection.broadcast_message(state.network, channel, text)
end
- message = %IRC.Message{at: NaiveDateTime.utc_now(), text: text, network: state.network, account: account, sender: sender, channel: channel, replyfun: reply_fun, trigger: IRC.Connection.extract_trigger(text), meta: meta}
+ message = %IRC.Message{id: FlakeId.get(), at: NaiveDateTime.utc_now(), text: text, network: state.network, account: account, sender: sender, channel: channel, replyfun: reply_fun, trigger: IRC.Connection.extract_trigger(text), meta: meta}
message = case IRC.UserTrack.messaged(message) do
:ok -> message
{:ok, message} -> message