Skip to content

Commit d3c5663

Browse files
committed
Javadoc, Linter
1 parent 616a0e8 commit d3c5663

8 files changed

Lines changed: 121 additions & 17 deletions

File tree

application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public final class BanCommand extends SlashCommandAdapter {
4545
private static final String REASON_OPTION = "reason";
4646
private static final String COMMAND_NAME = "ban";
4747
private static final String ACTION_VERB = "ban";
48+
@SuppressWarnings("StaticCollection")
4849
private static final List<String> DURATIONS = List.of(ModerationUtils.PERMANENT_DURATION,
4950
"1 hour", "3 hours", "1 day", "2 days", "3 days", "7 days", "30 days");
5051
private final Predicate<String> hasRequiredRole;
@@ -152,6 +153,7 @@ private RestAction<InteractionHook> banUserFlow(@NotNull User target, @NotNull M
152153
.flatMap(event::replyEmbeds);
153154
}
154155

156+
@SuppressWarnings("MethodWithTooManyParameters")
155157
private AuditableRestAction<Void> banUser(@NotNull User target, @NotNull Member author,
156158
@Nullable ModerationUtils.TemporaryData temporaryData, @NotNull String reason,
157159
int deleteHistoryDays, @NotNull Guild guild) {

application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationActionsStore.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ public ModerationActionsStore(@NotNull Database database) {
3939
this.database = Objects.requireNonNull(database);
4040
}
4141

42-
// FIXME javadoc
42+
/**
43+
* Gets all already expired actions, measured by the current time, which have been written to
44+
* the store, chronologically ascending with the action issued the earliest first.
45+
*
46+
* @return a list of all expired actions, chronologically ascending
47+
*/
4348
public @NotNull List<ActionRecord> getExpiredActionsAscending() {
4449
return getActionsAscendingWhere(
4550
ModerationActions.MODERATION_ACTIONS.ACTION_EXPIRES_AT.isNotNull()
@@ -92,7 +97,16 @@ public ModerationActionsStore(@NotNull Database database) {
9297
ModerationActions.MODERATION_ACTIONS.AUTHOR_ID.eq(authorId));
9398
}
9499

95-
// FIXME javadoc
100+
/**
101+
* Gets the action of the given type that was issued the latest against the given target, if
102+
* present.
103+
*
104+
* @param guildId the id of the guild, only actions that happened in the context of that guild
105+
* will be retrieved
106+
* @param targetId the id of the target user to filter for
107+
* @param actionType the type of the action
108+
* @return the last action issued against the given user of the given type, if present
109+
*/
96110
public @NotNull Optional<ActionRecord> findLastActionAgainstTargetByType(long guildId,
97111
long targetId, @NotNull ModerationAction actionType) {
98112
return database

application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,20 @@ public enum ModerationUtils {
3030
* {@link Guild#ban(User, int, String)}.
3131
*/
3232
private static final int REASON_MAX_LENGTH = 512;
33-
// FIXME Javadoc
33+
/**
34+
* Human-readable text representing the duration of a permanent action, will be shown to the
35+
* user as option for selection.
36+
*/
3437
static final String PERMANENT_DURATION = "permanent";
38+
/**
39+
* The ambient color used by moderation actions, often used to streamline the color theme of
40+
* embeds.
41+
*/
3542
static final Color AMBIENT_COLOR = Color.decode("#895FE8");
36-
// FIXME Javadoc
43+
/**
44+
* Matches the name of the role that is used to mute users, as used by {@link MuteCommand} and
45+
* similar.
46+
*/
3747
public static final Predicate<String> isMuteRole =
3848
Pattern.compile(Config.getInstance().getMutedRolePattern()).asMatchPredicate();
3949

@@ -331,6 +341,15 @@ static boolean handleHasAuthorRole(@NotNull String actionVerb,
331341
return guild.getRoles().stream().filter(role -> isMuteRole.test(role.getName())).findAny();
332342
}
333343

344+
/**
345+
* Computes a temporary data wrapper representing the action with the given duration.
346+
*
347+
* @param durationText the duration of the action, either {@code "permanent"} or a time window
348+
* such as {@code 1 day} or {@code 2 minutes}. Supports all units supported by
349+
* {@link Instant#plus(long, TemporalUnit)}.
350+
* @return the temporary data represented by the given duration or empty if the duration is
351+
* {@code "permanent"}
352+
*/
334353
static @NotNull Optional<TemporaryData> computeTemporaryData(@NotNull String durationText) {
335354
if (PERMANENT_DURATION.equals(durationText)) {
336355
return Optional.empty();
@@ -350,6 +369,13 @@ static boolean handleHasAuthorRole(@NotNull String actionVerb,
350369
return Optional.of(new TemporaryData(Instant.now().plus(duration, unit), durationText));
351370
}
352371

372+
/**
373+
* Wrapper to hold data relevant to temporary actions, for example the time it expires.
374+
*
375+
* @param expiresAt the time the temporary action expires
376+
* @param duration a human-readable text representing the duration of the temporary action, such
377+
* as {@code "1 day"}.
378+
*/
353379
record TemporaryData(@NotNull Instant expiresAt, @NotNull String duration) {
354380
}
355381
}

application/src/main/java/org/togetherjava/tjbot/commands/moderation/MuteCommand.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public final class MuteCommand extends SlashCommandAdapter {
3838
private static final String REASON_OPTION = "reason";
3939
private static final String COMMAND_NAME = "mute";
4040
private static final String ACTION_VERB = "mute";
41+
@SuppressWarnings("StaticCollection")
4142
private static final List<String> DURATIONS = List.of("10 minutes", "30 minutes", "1 hour",
4243
"3 hours", "1 day", "3 days", "7 days", ModerationUtils.PERMANENT_DURATION);
4344
private final Predicate<String> hasRequiredRole;
@@ -119,6 +120,7 @@ private AuditableRestAction<Void> muteUser(@NotNull Member target, @NotNull Memb
119120
.reason(reason);
120121
}
121122

123+
@SuppressWarnings("MethodWithTooManyParameters")
122124
private void muteUserFlow(@NotNull Member target, @NotNull Member author,
123125
@Nullable ModerationUtils.TemporaryData temporaryData, @NotNull String reason,
124126
@NotNull Guild guild, @NotNull SlashCommandEvent event) {

application/src/main/java/org/togetherjava/tjbot/commands/moderation/temp/RevocableModerationAction.java

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,67 @@
66
import org.jetbrains.annotations.NotNull;
77
import org.togetherjava.tjbot.commands.moderation.ModerationAction;
88

9-
// FIXME Javadoc
9+
/**
10+
* Represents revocable moderation actions, such as temporary bans. Primarily used by
11+
* {@link TemporaryModerationRoutine} to identify and revoke such actions.
12+
*/
1013
interface RevocableModerationAction {
14+
/**
15+
* Classification of a revocation failure.
16+
*/
17+
@SuppressWarnings("PublicInnerClass")
1118
enum FailureIdentification {
19+
/**
20+
* Acknowledges that the failure is known and has been handled. Hence, further error
21+
* handling should not be continued.
22+
*/
1223
KNOWN,
24+
/**
25+
* The failure is unknown and has not been handled. Hence, further error handling should be
26+
* continued.
27+
*/
1328
UNKNOWN
1429
}
1530

31+
/**
32+
* The type to apply the temporary action, such as
33+
* {@link net.dv8tion.jda.api.audit.ActionType#BAN}.
34+
*
35+
* @return the type to apply the temporary action
36+
*/
1637
@NotNull
1738
ModerationAction getApplyType();
1839

40+
/**
41+
* The type to revoke the temporary action, such as
42+
* {@link net.dv8tion.jda.api.audit.ActionType#UNBAN}.
43+
*
44+
* @return the type to revoke the temporary action
45+
*/
1946
@NotNull
2047
ModerationAction getRevokeType();
2148

49+
/**
50+
* Revokes the temporary action against the given target.
51+
*
52+
* @param guild the guild the user belongs to
53+
* @param target the target to revoke the action against
54+
* @param reason why the action is revoked
55+
* @return the unsubmitted revocation action
56+
*/
2257
@NotNull
2358
RestAction<Void> revokeAction(@NotNull Guild guild, @NotNull User target,
2459
@NotNull String reason);
2560

61+
/**
62+
* Handle a failure that might occur during revocation, i.e. execution of the action returned by
63+
* {@link #revokeAction(Guild, User, String)}.
64+
*
65+
* @param failure the failure to handle
66+
* @param targetId the id of the user who is targeted by the revocation
67+
* @return a classification of the failure, decides whether the surrounding flow will continue
68+
* to handle the error further or not
69+
*/
2670
@NotNull
2771
FailureIdentification handleRevokeFailure(@NotNull Throwable failure, long targetId);
2872
}

application/src/main/java/org/togetherjava/tjbot/commands/moderation/temp/TemporaryBanAction.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
import org.slf4j.LoggerFactory;
1111
import org.togetherjava.tjbot.commands.moderation.ModerationAction;
1212

13-
// FIXME Javadoc
13+
/**
14+
* Action to revoke temporary bans, as applied by
15+
* {@link org.togetherjava.tjbot.commands.moderation.BanCommand} and executed by
16+
* {@link TemporaryModerationRoutine}.
17+
*/
1418
final class TemporaryBanAction implements RevocableModerationAction {
1519
private static final Logger logger = LoggerFactory.getLogger(TemporaryBanAction.class);
1620

application/src/main/java/org/togetherjava/tjbot/commands/moderation/temp/TemporaryModerationRoutine.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,16 @@
2121
import java.util.stream.Collectors;
2222
import java.util.stream.Stream;
2323

24-
// FIXME javadoc
24+
/**
25+
* Routine that revokes temporary moderation actions, such as temporary bans, as listed by
26+
* {@link ModerationActionsStore}.
27+
* <p>
28+
* The routine is started by using {@link #start()} and then automatically executes on a schedule.
29+
* <p>
30+
* Revoked actions are compatible with {@link ModerationActionsStore} and commands such as
31+
* {@link org.togetherjava.tjbot.commands.moderation.UnbanCommand} and
32+
* {@link org.togetherjava.tjbot.commands.moderation.AuditCommand}.
33+
*/
2534
public final class TemporaryModerationRoutine {
2635
private static final Logger logger = LoggerFactory.getLogger(TemporaryModerationRoutine.class);
2736

@@ -142,15 +151,15 @@ private void handleFailure(@NotNull Throwable failure,
142151
public void start() {
143152
// TODO This should be registered at some sort of routine system instead (see GH issue #235
144153
// which adds support for routines)
145-
// NOTE The initial run has to be delayed until after the guild cache has been updated
154+
// TODO The initial run has to be delayed until after the guild cache has been updated
146155
// (during CommandSystem startup)
147156
checkExpiredActionsService.scheduleWithFixedDelay(this::checkExpiredActions, 5, 5,
148157
TimeUnit.MINUTES);
149158
}
150159

151160
private record RevocationGroupIdentifier(long guildId, long targetId,
152161
@NotNull ModerationAction type) {
153-
public static RevocationGroupIdentifier of(@NotNull ActionRecord actionRecord) {
162+
static RevocationGroupIdentifier of(@NotNull ActionRecord actionRecord) {
154163
return new RevocationGroupIdentifier(actionRecord.guildId(), actionRecord.targetId(),
155164
actionRecord.actionType());
156165
}

application/src/main/java/org/togetherjava/tjbot/commands/moderation/temp/TemporaryMuteAction.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
import org.togetherjava.tjbot.commands.moderation.ModerationAction;
1212
import org.togetherjava.tjbot.commands.moderation.ModerationUtils;
1313

14-
// FIXME Javadoc
14+
/**
15+
* Action to revoke temporary mutes, as applied by
16+
* {@link org.togetherjava.tjbot.commands.moderation.MuteCommand} and executed by
17+
* {@link TemporaryModerationRoutine}.
18+
*/
1519
final class TemporaryMuteAction implements RevocableModerationAction {
1620
private static final Logger logger = LoggerFactory.getLogger(TemporaryMuteAction.class);
1721

@@ -37,13 +41,12 @@ final class TemporaryMuteAction implements RevocableModerationAction {
3741
@Override
3842
public @NotNull FailureIdentification handleRevokeFailure(@NotNull Throwable failure,
3943
long targetId) {
40-
if (failure instanceof ErrorResponseException errorResponseException) {
41-
if (errorResponseException.getErrorResponse() == ErrorResponse.UNKNOWN_USER) {
42-
logger.info(
43-
"Attempted to revoke a temporary mute but user '{}' does not exist anymore.",
44-
targetId);
45-
return FailureIdentification.KNOWN;
46-
}
44+
if (failure instanceof ErrorResponseException errorResponseException
45+
&& errorResponseException.getErrorResponse() == ErrorResponse.UNKNOWN_USER) {
46+
logger.info(
47+
"Attempted to revoke a temporary mute but user '{}' does not exist anymore.",
48+
targetId);
49+
return FailureIdentification.KNOWN;
4750
}
4851
return FailureIdentification.UNKNOWN;
4952
}

0 commit comments

Comments
 (0)