-
-
Notifications
You must be signed in to change notification settings - Fork 116
Added /audit button to reports (moderation) #1499
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
Open
modwodmm
wants to merge
15
commits into
Together-Java:develop
Choose a base branch
from
modwodmm:develop
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b4a2d5e
Button to view reported user's previous warns, mutes and punishments
modwodmm 27d66db
Changed the code according to the reviewer's requirements
modwodmm 4b9b662
Changed some stuff as requested
modwodmm ece6dbf
Made the methods private in auditcommand and extracted them into mode…
modwodmm 9c71eca
Added pages to see throught reported user's history
modwodmm 940e390
Used helper methods so the code is easier to understand
modwodmm 9681b28
Used map instead of queue(...queue())
modwodmm 3def321
Made some changes as requested also brought back config.json.template
modwodmm 6e1805f
Removed a comment which suraj asked to be removed
modwodmm c919cd9
Made requested changes and made the audit message ephemeral
modwodmm 7ab5a46
Changed the names according to context
modwodmm 9804c59
Changed unused parameter msg to -
modwodmm 5cea235
Merge branch 'develop' into develop
modwodmm 189463b
Fixed the issues in the CI test
modwodmm 2e2336d
The audit button copies the style of the command and also fixed the i…
modwodmm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package org.togetherjava.tjbot.features.moderation; | ||
|
|
||
| import net.dv8tion.jda.api.EmbedBuilder; | ||
| import net.dv8tion.jda.api.JDA; | ||
| import net.dv8tion.jda.api.Permission; | ||
| import net.dv8tion.jda.api.entities.Guild; | ||
| import net.dv8tion.jda.api.entities.IPermissionHolder; | ||
|
|
@@ -25,11 +26,17 @@ | |
|
|
||
| import java.awt.Color; | ||
| import java.time.Instant; | ||
| import java.time.ZoneOffset; | ||
| import java.time.temporal.ChronoUnit; | ||
| import java.time.temporal.TemporalUnit; | ||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
| import java.util.function.Predicate; | ||
| import java.util.regex.Pattern; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| /** | ||
| * Utility class offering helpers revolving around user moderation, such as banning or kicking. | ||
|
|
@@ -273,7 +280,7 @@ static boolean handleHasAuthorPermissions(String actionVerb, Permission permissi | |
| * Creates a message to be displayed as response to a moderation action. | ||
| * <p> | ||
| * Essentially, it informs others about the action, such as "John banned Bob for playing with | ||
| * the fire.". | ||
| * the fire". | ||
| * | ||
| * @param author the author executing the action | ||
| * @param action the action that is executed | ||
|
|
@@ -442,4 +449,84 @@ static RestAction<Boolean> sendModActionDm(RestAction<EmbedBuilder> embedBuilder | |
| */ | ||
| record TemporaryData(Instant expiresAt, String duration) { | ||
| } | ||
|
|
||
| /** | ||
| * Splits a list of moderation records into discrete pages capped at 10 items each. | ||
| * | ||
| * @param actions the list of chronological actions against a target | ||
| * @return a list of sub-lists where each sub-list contains a maximum of 10 items | ||
| */ | ||
| public static List<List<ActionRecord>> groupActionsByPages(List<ActionRecord> actions) { | ||
| List<List<ActionRecord>> groupedActions = new ArrayList<>(); | ||
| final int maxPageLength = 10; | ||
|
|
||
| for (int i = 0; i < actions.size(); i++) { | ||
| if (i % maxPageLength == 0) { | ||
| groupedActions.add(new ArrayList<>(maxPageLength)); | ||
| } | ||
| groupedActions.getLast().add(actions.get(i)); | ||
| } | ||
|
|
||
| return groupedActions; | ||
| } | ||
|
|
||
| /** | ||
| * Generates a structural text overview outlining the count total of each action type. | ||
| * | ||
| * @param actions a collection of history records | ||
| * @return a formatted markdown description summary | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: The "markdown" word should be capitalized, considering you are referring to the formatting language. |
||
| */ | ||
| public static String createSummaryMessageDescription(Collection<ActionRecord> actions) { | ||
| int actionAmount = actions.size(); | ||
|
|
||
| String shortSummary = "There are **%s actions** against the user." | ||
| .formatted(actionAmount == 0 ? "no" : actionAmount); | ||
|
|
||
| if (actionAmount == 0) { | ||
| return shortSummary; | ||
| } | ||
|
|
||
| Map<ModerationAction, Long> actionTypeToCount = actions.stream() | ||
| .collect(Collectors.groupingBy(ActionRecord::actionType, Collectors.counting())); | ||
|
|
||
| String typeCountSummary = actionTypeToCount.entrySet() | ||
| .stream() | ||
| .filter(typeAndCount -> typeAndCount.getValue() > 0) | ||
| .sorted(Map.Entry.<ModerationAction, Long>comparingByValue().reversed()) | ||
| .map(typeAndCount -> "- **%s**: %d".formatted(typeAndCount.getKey(), | ||
| typeAndCount.getValue())) | ||
| .collect(Collectors.joining("\n")); | ||
|
|
||
| return shortSummary + "\n" + typeCountSummary; | ||
| } | ||
|
|
||
| /** | ||
| * Converts an action record item asynchronously into a formatted embed data field. | ||
| * | ||
| * @param action the record data item | ||
| * @param jda the active JDA instance used to resolve the moderator's handle | ||
| * @return a field representation task mapping out the execution card detail | ||
| */ | ||
| public static RestAction<MessageEmbed.Field> actionToField(ActionRecord action, JDA jda) { | ||
|
Zabuzard marked this conversation as resolved.
Outdated
|
||
| return jda.retrieveUserById(action.authorId()) | ||
| .map(author -> author == null ? "(unknown user)" : author.getName()) | ||
| .map(authorText -> { | ||
| String expiresAtFormatted = action.actionExpiresAt() == null ? "" | ||
| : "\nTemporary action, expires at: " + net.dv8tion.jda.api.utils.TimeUtil | ||
| .getDateTimeString(action.actionExpiresAt().atOffset(ZoneOffset.UTC)); | ||
|
|
||
| String fieldName = "%s by %s".formatted(action.actionType().name(), authorText); | ||
| String fieldDescription = | ||
| """ | ||
| %s | ||
| Issued at: %s%s | ||
| """.formatted(action.reason(), | ||
| net.dv8tion.jda.api.utils.TimeUtil | ||
| .getDateTimeString(action.issuedAt().atOffset(ZoneOffset.UTC)), | ||
| expiresAtFormatted); | ||
|
|
||
| return new MessageEmbed.Field(fieldName, fieldDescription, false); | ||
| }); | ||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.