10
10
import org .slf4j .LoggerFactory ;
11
11
12
12
import javax .annotation .Nonnull ;
13
+ import java .time .Instant ;
13
14
import java .util .*;
14
15
15
16
/**
@@ -45,6 +46,11 @@ private static void muteMember(@NotNull Member member) {
45
46
.queue ();
46
47
}
47
48
49
+ private static boolean isActionEffective (@ NotNull ActionRecord action ) {
50
+ // Effective if permanent or expires in the future
51
+ return action .actionExpiresAt () == null || action .actionExpiresAt ().isAfter (Instant .now ());
52
+ }
53
+
48
54
@ Override
49
55
public void onGuildMemberJoin (@ Nonnull GuildMemberJoinEvent event ) {
50
56
Member member = event .getMember ();
@@ -55,27 +61,24 @@ public void onGuildMemberJoin(@Nonnull GuildMemberJoinEvent event) {
55
61
}
56
62
57
63
private boolean shouldMemberBeMuted (@ NotNull IPermissionHolder member ) {
58
- List <ActionRecord > actions = new ArrayList <>(actionsStore
59
- .getActionsByTargetAscending (member .getGuild ().getIdLong (), member .getIdLong ()));
60
- Collections .reverse (actions );
61
-
62
- Optional <ActionRecord > lastMute = actions .stream ()
63
- .filter (action -> action .actionType () == ModerationAction .MUTE )
64
- .findFirst ();
64
+ Optional <ActionRecord > lastMute = actionsStore .findLastActionAgainstTargetByType (
65
+ member .getGuild ().getIdLong (), member .getIdLong (), ModerationAction .MUTE );
65
66
if (lastMute .isEmpty ()) {
66
67
// User was never muted
67
68
return false ;
68
69
}
69
70
70
- Optional <ActionRecord > lastUnmute = actions .stream ()
71
- .filter (action -> action .actionType () == ModerationAction .UNMUTE )
72
- .findFirst ();
71
+ Optional <ActionRecord > lastUnmute = actionsStore .findLastActionAgainstTargetByType (
72
+ member .getGuild ().getIdLong (), member .getIdLong (), ModerationAction .UNMUTE );
73
73
if (lastUnmute .isEmpty ()) {
74
74
// User was never unmuted
75
- return true ;
75
+ return isActionEffective ( lastMute . orElseThrow ()) ;
76
76
}
77
77
78
78
// The last issued action takes priority
79
- return lastMute .orElseThrow ().issuedAt ().isAfter (lastUnmute .orElseThrow ().issuedAt ());
79
+ if (lastMute .orElseThrow ().issuedAt ().isAfter (lastUnmute .orElseThrow ().issuedAt ())) {
80
+ return isActionEffective (lastMute .orElseThrow ());
81
+ }
82
+ return false ;
80
83
}
81
84
}
0 commit comments