summaryrefslogtreecommitdiff
path: root/lib/lsg_irc/preums_plugin.ex
diff options
context:
space:
mode:
authorhref <href@random.sh>2021-09-02 05:08:59 +0200
committerhref <href@random.sh>2021-09-02 05:08:59 +0200
commitd490638c0747b8e37b1874c9dc56758cd1784dc1 (patch)
tree043f99b956148ae9cc75185517ab7ec696c6a95e /lib/lsg_irc/preums_plugin.ex
parenttelegram: update (diff)
Revert "preums: remove migration code"
Diffstat (limited to 'lib/lsg_irc/preums_plugin.ex')
-rw-r--r--lib/lsg_irc/preums_plugin.ex33
1 files changed, 31 insertions, 2 deletions
diff --git a/lib/lsg_irc/preums_plugin.ex b/lib/lsg_irc/preums_plugin.ex
index 31615e6..7bb2c78 100644
--- a/lib/lsg_irc/preums_plugin.ex
+++ b/lib/lsg_irc/preums_plugin.ex
@@ -89,6 +89,35 @@ defmodule LSG.IRC.PreumsPlugin do
{:ok, _} = Registry.register(IRC.PubSub, "account", regopts)
{:ok, _} = Registry.register(IRC.PubSub, "message", regopts)
{:ok, _} = Registry.register(IRC.PubSub, "triggers", regopts)
+ {:ok, dets} = :dets.open_file(dets(), [{:repair, :force}])
+ Util.ets_mutate_select_each(:dets, dets, [{:"$1", [], [:"$1"]}], fn(table, obj) ->
+ {key, nick, now, perfect, text} = obj
+ case key do
+ {{net, {bork,chan}}, date} ->
+ :dets.delete(table, key)
+ nick = if IRC.Account.get(nick) do
+ nick
+ else
+ if acct = IRC.Account.find_always_by_nick(net, nil, nick) do
+ acct.id
+ else
+ nick
+ end
+ end
+ :dets.insert(table, { { {net,chan}, date }, nick, now, perfect, text})
+ {{_net, nil}, _} ->
+ :dets.delete(table, key)
+ {{net, chan}, date} ->
+ if !IRC.Account.get(nick) do
+ if acct = IRC.Account.find_always_by_nick(net, chan, nick) do
+ :dets.delete(table, key)
+ :dets.insert(table, { { {net,chan}, date }, acct.id, now, perfect, text})
+ end
+ end
+ _ ->
+ Logger.debug("DID NOT FIX: #{inspect key}")
+ end
+ end)
{:ok, %{dets: dets}}
end
@@ -126,11 +155,11 @@ defmodule LSG.IRC.PreumsPlugin do
channel = {m.network, m.channel}
state = handle_preums(m, state)
top = topnicks(state.dets, channel, sort_by: :score)
- |> Enum.map(fn({account_id, {count, _score}}) ->
+ |> Enum.map(fn({account_id, {count, score}}) ->
account = IRC.Account.get(account_id)
user = IRC.UserTrack.find_by_account(m.network, account)
nick = if(user, do: user.nick, else: account.name)
- "#{nick}: #{count}"
+ "#{nick}: #{score} (#{count})"
end)
|> Enum.intersperse(", ")
|> Enum.join("")