Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various moderation-facing bugfixes #327

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ repos:
# language: system
# pass_filenames: false
# files: \.exs*$
- id: mix-dialyzer
name: "elixir: mix dialyzer"
entry: mix dialyzer
language: system
pass_filenames: false
files: \.exs*$
# - id: mix-dialyzer
# name: "elixir: mix dialyzer"
# entry: mix dialyzer
# language: system
# pass_filenames: false
# files: \.exs*$

2 changes: 1 addition & 1 deletion lib/teiserver/moderation/libs/action_lib.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Teiserver.Moderation.ActionLib do

# Functions
@spec icon :: String.t()
def icon, do: "fa-regular fa-exclamation"
def icon, do: "fa-regular fa-triangle-exclamation"

@spec colour :: atom
def colour, do: :primary
Expand Down
10 changes: 10 additions & 0 deletions lib/teiserver/moderation/queries/report_group_queries.ex
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@
where: report_groups.inserted_at >= ^datetime
end

defp _where(query, :has_reports_of_kind, kind) do
from report_groups in query,
join: reports in assoc(report_groups, :reports),
where: fragment("? ~* ?", reports.type, ^kind)
end

defp _where(query, :has_reports_of_kind, nil), do: query

Check warning on line 87 in lib/teiserver/moderation/queries/report_group_queries.ex

View workflow job for this annotation

GitHub Actions / mix format

this clause cannot match because a previous clause at line 81 always matches

Check warning on line 87 in lib/teiserver/moderation/queries/report_group_queries.ex

View workflow job for this annotation

GitHub Actions / Dialyzer

this clause cannot match because a previous clause at line 81 always matches

Check warning on line 87 in lib/teiserver/moderation/queries/report_group_queries.ex

View workflow job for this annotation

GitHub Actions / Build and test

this clause cannot match because a previous clause at line 81 always matches

@spec do_order_by(Ecto.Query.t(), list | nil) :: Ecto.Query.t()
defp do_order_by(query, nil), do: query

Expand Down Expand Up @@ -128,6 +136,8 @@
from report_groups in query,
left_join: reports in assoc(report_groups, :reports),
preload: [reports: reports]

# TODO add reporters here
end

# defp _preload(query, :users) do
Expand Down
154 changes: 5 additions & 149 deletions lib/teiserver_web/controllers/admin/match_controller.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
defmodule TeiserverWeb.Admin.MatchController do
use TeiserverWeb, :controller

alias Teiserver.{Battle, Game, Account, Telemetry}

Check warning on line 4 in lib/teiserver_web/controllers/admin/match_controller.ex

View workflow job for this annotation

GitHub Actions / mix format

unused alias Telemetry

Check warning on line 4 in lib/teiserver_web/controllers/admin/match_controller.ex

View workflow job for this annotation

GitHub Actions / Dialyzer

unused alias Telemetry

Check warning on line 4 in lib/teiserver_web/controllers/admin/match_controller.ex

View workflow job for this annotation

GitHub Actions / Build and test

unused alias Telemetry
alias Teiserver.Battle.{MatchLib, BalanceLib}

Check warning on line 5 in lib/teiserver_web/controllers/admin/match_controller.ex

View workflow job for this annotation

GitHub Actions / mix format

unused alias BalanceLib

Check warning on line 5 in lib/teiserver_web/controllers/admin/match_controller.ex

View workflow job for this annotation

GitHub Actions / mix format

unused alias MatchLib

Check warning on line 5 in lib/teiserver_web/controllers/admin/match_controller.ex

View workflow job for this annotation

GitHub Actions / Dialyzer

unused alias BalanceLib

Check warning on line 5 in lib/teiserver_web/controllers/admin/match_controller.ex

View workflow job for this annotation

GitHub Actions / Dialyzer

unused alias MatchLib

Check warning on line 5 in lib/teiserver_web/controllers/admin/match_controller.ex

View workflow job for this annotation

GitHub Actions / Build and test

unused alias BalanceLib

Check warning on line 5 in lib/teiserver_web/controllers/admin/match_controller.ex

View workflow job for this annotation

GitHub Actions / Build and test

unused alias MatchLib
import Teiserver.Helper.StringHelper, only: [get_hash_id: 1]
require Logger

Expand Down Expand Up @@ -68,126 +68,12 @@

@spec show(Plug.Conn.t(), Map.t()) :: Plug.Conn.t()
def show(conn, %{"id" => id}) do
match =
Battle.get_match!(id,
joins: [],
preload: [:members_and_users]
)

members =
match.members
|> Enum.sort_by(fn m -> m.user.name end, &<=/2)
|> Enum.sort_by(fn m -> m.team_id end, &<=/2)

match
|> MatchLib.make_favourite()
|> insert_recently(conn)

match_name = MatchLib.make_match_name(match)

rating_logs =
Game.list_rating_logs(
search: [
match_id: match.id
]
)
|> Map.new(fn log -> {log.user_id, log} end)

# Creates a map where the party_id refers to an integer
# but only includes parties with 2 or more members
parties =
members
|> Enum.group_by(fn m -> m.party_id end)
|> Map.drop([nil])
|> Map.filter(fn {_id, members} -> Enum.count(members) > 1 end)
|> Map.keys()
|> Enum.zip(Teiserver.Helper.StylingHelper.bright_hex_colour_list())
|> Map.new()

# Now for balance related stuff
partied_players =
members
|> Enum.group_by(fn p -> p.party_id end, fn p -> p.user_id end)

groups =
partied_players
|> Enum.map(fn
# The nil group is players without a party, they need to
# be broken out of the party
{nil, player_id_list} ->
player_id_list
|> Enum.filter(fn userid -> rating_logs[userid] != nil end)
|> Enum.map(fn userid ->
%{userid => rating_logs[userid].value["rating_value"]}
end)

{_party_id, player_id_list} ->
player_id_list
|> Enum.filter(fn userid -> rating_logs[userid] != nil end)
|> Map.new(fn userid ->
{userid, rating_logs[userid].value["rating_value"]}
end)
end)
|> List.flatten()

past_balance =
BalanceLib.create_balance(groups, match.team_count, mode: :loser_picks)
|> Map.put(:balance_mode, :grouped)

# What about new balance?
new_balance = generate_new_balance_data(match)

raw_events =
Telemetry.list_simple_match_events(where: [match_id: match.id], preload: [:event_types])

events_by_type =
raw_events
|> Enum.group_by(
fn e ->
e.event_type.name
end,
fn _ ->
1
end
)
|> Enum.map(fn {name, vs} ->
{name, Enum.count(vs)}
end)
|> Enum.sort_by(fn v -> v end, &<=/2)

team_lookup =
members
|> Map.new(fn m ->
{m.user_id, m.team_id}
end)

events_by_team_and_type =
raw_events
|> Enum.group_by(
fn e ->
{team_lookup[e.user_id] || -1, e.event_type.name}
end,
fn _ ->
1
end
)
|> Enum.map(fn {key, vs} ->
{key, Enum.count(vs)}
end)
|> Enum.sort_by(fn v -> v end, &<=/2)

conn
|> assign(:match, match)
|> assign(:match_name, match_name)
|> assign(:members, members)
|> assign(:rating_logs, rating_logs)
|> assign(:parties, parties)
|> assign(:past_balance, past_balance)
|> assign(:new_balance, new_balance)
|> assign(:events_by_type, events_by_type)
|> assign(:events_by_team_and_type, events_by_team_and_type)
|> add_breadcrumb(name: "Show: #{match_name}", url: conn.request_path)
|> render("show.html")
|> put_flash(
:info,
"/teiserver/admin/matches/:match_id is deprecated in favor of /battle/:id"
)
|> redirect(to: ~p"/battle/#{id}")
end

@spec user_show(Plug.Conn.t(), Map.t()) :: Plug.Conn.t()
Expand Down Expand Up @@ -229,34 +115,4 @@
|> assign(:matches, matches)
|> render("server_index.html")
end

defp generate_new_balance_data(match) do
rating_type = MatchLib.game_type(match.team_size, match.team_count)

partied_players =
match.members
|> Enum.group_by(fn p -> p.party_id end, fn p -> p.user_id end)

groups =
partied_players
|> Enum.map(fn
# The nil group is players without a party, they need to
# be broken out of the party
{nil, player_id_list} ->
player_id_list
|> Enum.map(fn userid ->
%{userid => BalanceLib.get_user_rating_rank(userid, rating_type)}
end)

{_party_id, player_id_list} ->
player_id_list
|> Map.new(fn userid ->
{userid, BalanceLib.get_user_rating_rank(userid, rating_type)}
end)
end)
|> List.flatten()

BalanceLib.create_balance(groups, match.team_count, mode: :loser_picks)
|> Map.put(:balance_mode, :grouped)
end
end
12 changes: 12 additions & 0 deletions lib/teiserver_web/controllers/moderation/report_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ defmodule TeiserverWeb.Moderation.ReportController do
order_by: params["order"]
)

reports =
case params["kind"] do
"Chat" ->
reports |> Enum.filter(fn report -> String.contains?(report.type, "chat") end)

"Actions" ->
reports |> Enum.filter(fn report -> String.contains?(report.type, "actions") end)

"Any" ->
reports
end

target =
if params["target_id"] do
Account.get_user(params["target_id"])
Expand Down
12 changes: 11 additions & 1 deletion lib/teiserver_web/live/battles/match/chat.ex
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ defmodule TeiserverWeb.Battle.MatchLive.Chat do
end)
|> Enum.reject(&(&1 == nil))

user_exclude_list =
String.trim(filters["user-raw-exclude"] || "")
|> String.split(",")
|> Enum.map(fn username ->
Account.get_userid_from_name(username)
end)
|> Enum.reject(&(&1 == nil))

contains_filter =
filters["message-contains"]
|> String.trim()
Expand All @@ -102,7 +110,8 @@ defmodule TeiserverWeb.Battle.MatchLive.Chat do
Chat.list_lobby_messages(
search: [
match_id: match_id,
user_id_in: user_id_list
user_id_in: user_id_list,
user_id_not_in: user_exclude_list
],
preload: [:user],
limit: 1_000,
Expand Down Expand Up @@ -183,6 +192,7 @@ defmodule TeiserverWeb.Battle.MatchLive.Chat do
"bot-messages" => "Include bot messages",
"message-format" => "Table",
"user-raw-filter" => "",
"user-raw-exclude" => "Coordinator",
"user-raw-highlight" => highlight_names,
"message-contains" => "",
"order_by" => "Oldest first"
Expand Down
11 changes: 11 additions & 0 deletions lib/teiserver_web/live/battles/match/chat.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@
/>
</div>

<div class="col">
<.input
type="text"
label="User exclude (split with commas)"
name="user-raw-exclude"
value={@filters["user-raw-exclude"]}
phx-change="filter-update"
phx-debounce="400"
/>
</div>

<div :if={@filters["message-format"] == "Table"} class="col">
<.input
type="text"
Expand Down
2 changes: 1 addition & 1 deletion lib/teiserver_web/live/battles/match/match_components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ defmodule TeiserverWeb.Battle.MatchComponents do
bsname={@view_colour}
icon={StylingHelper.icon(:admin)}
active={false}
url={~p"/teiserver/admin/matches/#{@match_id}"}
url={~p"/battle/#{@match_id}"}
>
Admin view
</.section_menu_button>
Expand Down
Loading
Loading