summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhref <href@random.sh>2021-09-08 15:58:34 +0200
committerhref <href@random.sh>2021-09-08 15:58:34 +0200
commite5f3327afc6699e1f3d5a5a674f8b4421ff2443f (patch)
tree528c34515b2e12524b667e4b666c39d6f2af1331
parent;o custom subnets (diff)
various fixes
-rw-r--r--lib/irc/connection.ex30
-rw-r--r--lib/lsg_irc/alcolog_plugin.ex10
2 files changed, 22 insertions, 18 deletions
diff --git a/lib/irc/connection.ex b/lib/irc/connection.ex
index 52910ac..fafb0d7 100644
--- a/lib/irc/connection.ex
+++ b/lib/irc/connection.ex
@@ -264,8 +264,11 @@ defmodule IRC.Connection do
# ISUP
def handle_info({:isup, network}, state) do
- IRC.UserTrack.clear_network(network)
- {:noreply, %{state | network: network}}
+ IRC.UserTrack.clear_network(state.network)
+ if network != state.network do
+ Logger.warn("Possibly misconfigured network: #{network} != #{state.network}")
+ end
+ {:noreply, state}
end
# Been kicked
@@ -276,11 +279,11 @@ defmodule IRC.Connection do
# Received something in a channel
def handle_info({:received, text, sender, chan}, state) do
- user = IRC.UserTrack.find_by_nick(network(state), sender.nick)
+ user = IRC.UserTrack.find_by_nick(state.network, sender.nick)
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: network(state), account: account, sender: sender, channel: chan, replyfun: reply_fun, trigger: extract_trigger(text)}
+ 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 = case IRC.UserTrack.messaged(message) do
:ok -> message
{:ok, message} -> message
@@ -294,7 +297,7 @@ 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: network(state), account: account, sender: sender, replyfun: reply_fun, trigger: extract_trigger(text)}
+ message = %IRC.Message{text: text, network: state.network, account: account, sender: sender, replyfun: reply_fun, trigger: extract_trigger(text)}
message = case IRC.UserTrack.messaged(message) do
:ok -> message
{:ok, message} -> message
@@ -357,22 +360,22 @@ defmodule IRC.Connection do
end
def handle_info({:kicked, nick, _by, channel, _reason}, state) do
- IRC.UserTrack.parted(network(state), channel, nick)
+ IRC.UserTrack.parted(state.network, channel, nick)
{:noreply, state}
end
def handle_info({:parted, channel, %ExIRC.SenderInfo{nick: nick}}, state) do
- IRC.UserTrack.parted(network(state), channel, nick)
+ IRC.UserTrack.parted(state.network, channel, nick)
{:noreply, state}
end
def handle_info({:mode, [channel, mode, nick]}, state) do
- track_mode(network(state), channel, nick, mode)
+ track_mode(state.network, channel, nick, mode)
{:noreply, state}
end
def handle_info({:nick_changed, old_nick, new_nick}, state) do
- IRC.UserTrack.renamed(network(state), old_nick, new_nick)
+ IRC.UserTrack.renamed(state.network, old_nick, new_nick)
{:noreply, state}
end
@@ -499,13 +502,4 @@ defmodule IRC.Connection do
host <> ":" <> to_string(port)
end
- defp network(state = %{conn: %{network: network}}) do
- if network do
- network
- else
- # FIXME performance meheeeee
- ExIRC.Client.state(state.client)[:network]
- end
- end
-
end
diff --git a/lib/lsg_irc/alcolog_plugin.ex b/lib/lsg_irc/alcolog_plugin.ex
index 8a7bcb9..46c43f4 100644
--- a/lib/lsg_irc/alcolog_plugin.ex
+++ b/lib/lsg_irc/alcolog_plugin.ex
@@ -66,6 +66,16 @@ defmodule LSG.IRC.AlcoologPlugin do
{:ok, meta} = :dets.open_file(dets_meta_filename, [{:type,:set}])
traverse_fun = fn(obj, dets) ->
case obj do
+ object = {nick, naive = %NaiveDateTime{}, volumes, active, cl, deg, name, comment} ->
+ date = naive
+ |> DateTime.from_naive!("Etc/UTC")
+ |> DateTime.to_unix()
+ new = {nick, date, volumes, active, cl, deg, name, comment, Map.new()}
+ :dets.delete_object(dets, object)
+ :dets.insert(dets, new)
+ :ets.insert(ets, {{nick, date}, volumes, active, cl, deg, name, comment, Map.new()})
+ dets
+
object = {nick, naive = %NaiveDateTime{}, volumes, active, cl, deg, name, comment, meta} ->
date = naive
|> DateTime.from_naive!("Etc/UTC")