diff options
author | Jordan Bracco <href@random.sh> | 2022-12-20 02:47:33 +0000 |
---|---|---|
committer | Jordan Bracco <href@random.sh> | 2022-12-20 19:29:41 +0100 |
commit | 2127553ad058bfa688feb73097e604a8fb5a1899 (patch) | |
tree | 3246c31aef0f6c3a110376de21265a6f5d02c597 /lib/irc | |
parent | IRC.PubSub -> Nola.PubSub, refs T77 (diff) |
Rename IRC.Account to Nola.Account, refs T77
Diffstat (limited to '')
-rw-r--r-- | lib/irc/connection.ex | 10 | ||||
-rw-r--r-- | lib/irc/membership.ex | 10 | ||||
-rw-r--r-- | lib/irc/nola_irc.ex | 2 | ||||
-rw-r--r-- | lib/irc/puppet_connection.ex | 18 | ||||
-rw-r--r-- | lib/irc/user_track.ex | 16 | ||||
-rw-r--r-- | lib/nola/account.ex (renamed from lib/irc/account.ex) | 4 |
6 files changed, 30 insertions, 30 deletions
diff --git a/lib/irc/connection.ex b/lib/irc/connection.ex index 4472466..49f5774 100644 --- a/lib/irc/connection.ex +++ b/lib/irc/connection.ex @@ -293,7 +293,7 @@ defmodule IRC.Connection do else if !Map.get(user.options, :puppet) do reply_fun = fn(text) -> irc_reply(state, {chan, sender}, text) end - account = IRC.Account.lookup(sender) + account = Nola.Account.lookup(sender) 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)} @@ -310,7 +310,7 @@ defmodule IRC.Connection do # Received a private message 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) + account = Nola.Account.lookup(sender) 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 @@ -322,7 +322,7 @@ defmodule IRC.Connection do end ## -- Broadcast - def handle_info({:broadcast, net, account = %IRC.Account{}, message}, state) do + def handle_info({:broadcast, net, account = %Nola.Account{}, message}, state) do if net == state.conn.network do user = IRC.UserTrack.find_by_account(net, account) if user do @@ -350,7 +350,7 @@ defmodule IRC.Connection do priv = if operator, do: [:operator], else: [] # Don't touch -- on WHO the bot joined, not the users. IRC.UserTrack.joined(channel, who, priv, false) - account = IRC.Account.lookup(who) + account = Nola.Account.lookup(who) if account do {:account, who.network, channel, who.nick, account.id} end @@ -367,7 +367,7 @@ defmodule IRC.Connection do def handle_info({:joined, channel, sender}, state) do IRC.UserTrack.joined(channel, sender, []) - account = IRC.Account.lookup(sender) + account = Nola.Account.lookup(sender) if account do dispatch("account", {:account, sender.network, channel, sender.nick, account.id}) end diff --git a/lib/irc/membership.ex b/lib/irc/membership.ex index b727dfd..25a0cfc 100644 --- a/lib/irc/membership.ex +++ b/lib/irc/membership.ex @@ -19,7 +19,7 @@ defmodule IRC.Membership do {:ok, dets} end - def of_account(%IRC.Account{id: id}) do + def of_account(%Nola.Account{id: id}) do spec = [{{{:"$1", :"$2", :"$3"}, :_}, [{:==, :"$1", {:const, id}}], [{{:"$2", :"$3"}}]}] :dets.select(dets(), spec) end @@ -33,11 +33,11 @@ defmodule IRC.Membership do end) end - def touch(%IRC.Account{id: id}, network, channel) do + def touch(%Nola.Account{id: id}, network, channel) do :dets.insert(dets(), {{id, network, channel}, NaiveDateTime.utc_now()}) end def touch(account_id, network, channel) do - if account = IRC.Account.get(account_id) do + if account = Nola.Account.get(account_id) do touch(account, network, channel) end end @@ -91,7 +91,7 @@ defmodule IRC.Membership do :dets.select(dets(), spec) end - def friends(account = %IRC.Account{id: id}) do + def friends(account = %Nola.Account{id: id}) do for({net, chan} <- of_account(account), do: members(net, chan)) |> List.flatten() |> Enum.uniq() @@ -116,7 +116,7 @@ defmodule IRC.Membership do defp expand(network, list) do for id <- list do - if account = IRC.Account.get(id) do + if account = Nola.Account.get(id) do user = IRC.UserTrack.find_by_account(network, account) nick = if(user, do: user.nick, else: account.name) {account, user, nick} diff --git a/lib/irc/nola_irc.ex b/lib/irc/nola_irc.ex index dde99af..2d355d3 100644 --- a/lib/irc/nola_irc.ex +++ b/lib/irc/nola_irc.ex @@ -13,7 +13,7 @@ defmodule Nola.IRC do [ worker(Registry, [[keys: :duplicate, name: IRC.ConnectionPubSub]], id: :registr_irc_conn), worker(IRC.Membership, []), - worker(IRC.Account, []), + worker(Nola.Account, []), worker(IRC.UserTrack.Storage, []), worker(Nola.Plugins.Account, []), supervisor(Nola.Plugins.Supervisor, [], [name: Nola.Plugins.Supervisor]), diff --git a/lib/irc/puppet_connection.ex b/lib/irc/puppet_connection.ex index 91a26b3..fd0a98e 100644 --- a/lib/irc/puppet_connection.ex +++ b/lib/irc/puppet_connection.ex @@ -12,7 +12,7 @@ defmodule IRC.PuppetConnection do DynamicSupervisor.start_link(__MODULE__, [], name: __MODULE__) end - def start_child(%IRC.Account{id: account_id}, %IRC.Connection{id: connection_id}) do + def start_child(%Nola.Account{id: account_id}, %IRC.Connection{id: connection_id}) do spec = %{id: {account_id, connection_id}, start: {IRC.PuppetConnection, :start_link, [account_id, connection_id]}, restart: :transient} DynamicSupervisor.start_child(__MODULE__, spec) end @@ -27,7 +27,7 @@ defmodule IRC.PuppetConnection do end end - def whereis(account = %IRC.Account{id: account_id}, connection = %IRC.Connection{id: connection_id}) do + def whereis(account = %Nola.Account{id: account_id}, connection = %IRC.Connection{id: connection_id}) do {:global, name} = name(account_id, connection_id) case :global.whereis_name(name) do :undefined -> nil @@ -35,11 +35,11 @@ defmodule IRC.PuppetConnection do end end - def send_message(account = %IRC.Account{id: account_id}, connection = %IRC.Connection{id: connection_id}, channel, text) do + def send_message(account = %Nola.Account{id: account_id}, connection = %IRC.Connection{id: connection_id}, channel, text) do GenServer.cast(name(account_id, connection_id), {:send_message, self(), channel, text}) end - def start_and_send_message(account = %IRC.Account{id: account_id}, connection = %IRC.Connection{id: connection_id}, channel, text) do + def start_and_send_message(account = %Nola.Account{id: account_id}, connection = %IRC.Connection{id: connection_id}, channel, text) do {:global, name} = name(account_id, connection_id) pid = whereis(account, connection) pid = if !pid do @@ -53,7 +53,7 @@ defmodule IRC.PuppetConnection do GenServer.cast(pid, {:send_message, self(), channel, text}) end - def start(account = %IRC.Account{}, connection = %IRC.Connection{}) do + def start(account = %Nola.Account{}, connection = %IRC.Connection{}) do IRC.PuppetConnection.Supervisor.start_child(account, connection) end @@ -66,7 +66,7 @@ defmodule IRC.PuppetConnection do end def init([account_id, connection_id]) do - account = %IRC.Account{} = IRC.Account.get(account_id) + account = %Nola.Account{} = Nola.Account.get(account_id) connection = %IRC.Connection{} = IRC.Connection.lookup(connection_id) Logger.metadata(puppet_conn: account.id <> "@" <> connection.id) backoff = :backoff.init(@min_backoff, @max_backoff) @@ -78,7 +78,7 @@ defmodule IRC.PuppetConnection do def handle_continue(:connect, state) do #ipv6 = if @env == :prod do # subnet = Nola.Subnet.assign(state.account_id) - # IRC.Account.put_meta(IRC.Account.get(state.account_id), "subnet", subnet) + # Nola.Account.put_meta(Nola.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]) @@ -146,7 +146,7 @@ defmodule IRC.PuppetConnection do ExIRC.Client.msg(state.client, :privmsg, channel, text) meta = %{puppet: true, from: pid} - account = IRC.Account.get(state.account_id) + account = Nola.Account.get(state.account_id) nick = make_nick(state) sender = %ExIRC.SenderInfo{network: state.network, nick: suffix_nick(nick), user: nick, host: "puppet."} reply_fun = fn(text) -> @@ -219,7 +219,7 @@ defmodule IRC.PuppetConnection do end def make_nick(state) do - account = IRC.Account.get(state.account_id) + account = Nola.Account.get(state.account_id) user = IRC.UserTrack.find_by_account(state.network, account) base_nick = if(user, do: user.nick, else: account.name) clean_nick = case String.split(base_nick, ":", parts: 2) do diff --git a/lib/irc/user_track.ex b/lib/irc/user_track.ex index 1efa523..3f144d5 100644 --- a/lib/irc/user_track.ex +++ b/lib/irc/user_track.ex @@ -73,7 +73,7 @@ defmodule IRC.UserTrack do end end - def find_by_account(%IRC.Account{id: id}) do + def find_by_account(%Nola.Account{id: id}) do #iex(15)> :ets.fun2ms(fn(obj = {_, net, acct, _, _, _, _, _, _}) when net == network and acct == account -> obj end) spec = [ {{:_, :_, :"$2", :_, :_, :_, :_, :_, :_, :_, :_, :_}, @@ -90,7 +90,7 @@ defmodule IRC.UserTrack do nil end - def find_by_account(network, %IRC.Account{id: id}) do + def find_by_account(network, %Nola.Account{id: id}) do #iex(15)> :ets.fun2ms(fn(obj = {_, net, acct, _, _, _, _, _, _}) when net == network and acct == account -> obj end) spec = [ {{:_, :"$1", :"$2", :_, :_, :_, :_, :_, :_, :_, :_, :_}, @@ -178,7 +178,7 @@ defmodule IRC.UserTrack do # TODO def connected(network, nick, user, host, account_id, opts \\ %{}) do - if account = IRC.Account.get(account_id) do + if account = Nola.Account.get(account_id) do user = if user = find_by_nick(network, nick) do user else @@ -207,7 +207,7 @@ defmodule IRC.UserTrack do else user = %User{id: IRC.UserTrack.Id.large_id, network: sender.network, nick: nick, username: uname, host: host, privileges: %{channel => privileges}} - account = IRC.Account.lookup(user).id + account = Nola.Account.lookup(user).id user = %User{user | account: account} end user = touch_struct(user, channel) @@ -239,10 +239,10 @@ defmodule IRC.UserTrack do def messaged(%IRC.Message{network: network, account: account, channel: chan, sender: %{nick: nick}} = m) do {user, account} = if user = find_by_nick(network, nick) do - {touch_struct(user, chan), account || IRC.Account.lookup(user)} + {touch_struct(user, chan), account || Nola.Account.lookup(user)} else user = %User{network: network, nick: nick, privileges: %{}} - account = IRC.Account.lookup(user) + account = Nola.Account.lookup(user) {%User{user | account: account.id}, account} end Storage.insert(User.to_tuple(user)) @@ -256,9 +256,9 @@ defmodule IRC.UserTrack do def renamed(network, old_nick, new_nick) do if user = find_by_nick(network, old_nick) do - old_account = IRC.Account.lookup(user) + old_account = Nola.Account.lookup(user) user = %User{user | nick: new_nick, nicks: [old_nick|user.nicks]} - account = IRC.Account.lookup(user, false) || old_account + account = Nola.Account.lookup(user, false) || old_account user = %User{user | nick: new_nick, account: account.id, nicks: [old_nick|user.nicks]} Storage.insert(User.to_tuple(user)) channels = for {channel, _} <- user.privileges, do: channel diff --git a/lib/irc/account.ex b/lib/nola/account.ex index a39733c..cd424ef 100644 --- a/lib/irc/account.ex +++ b/lib/nola/account.ex @@ -1,4 +1,4 @@ -defmodule IRC.Account do +defmodule Nola.Account do alias IRC.UserTrack.User @moduledoc """ @@ -27,7 +27,7 @@ defmodule IRC.Account do import Inspect.Algebra def inspect(%{id: id, name: name}, opts) do - concat(["#IRC.Account[", id, " ", name, "]"]) + concat(["#Nola.Account[", id, " ", name, "]"]) end end |