@@ -97,7 +97,7 @@ public void warn(User user, WarnSeverity severity, String reason, Member warnedB
9797 */
9898 public SeverityInformation getTotalSeverityWeight (Guild guild , long userId ) {
9999 ModerationConfig moderationConfig = botConfig .get (guild ).getModerationConfig ();
100- List <Warn > activeWarns = warnRepository .getActiveWarnsByUserId (userId , LocalDateTime . now (). minusDays ( moderationConfig . getMaxWarnValidityDays () ));
100+ List <Warn > activeWarns = warnRepository .getActiveWarnsByUserId (userId , getEarliestActiveWarnTimestamp ( moderationConfig ));
101101 return calculateSeverityWeight (moderationConfig , activeWarns );
102102 }
103103
@@ -132,9 +132,10 @@ static SeverityInformation calculateSeverityWeight(ModerationConfig moderationCo
132132 * @param clearedBy The user who cleared the warns.
133133 */
134134 public void discardAllWarns (User user , Member clearedBy ) {
135+ ModerationConfig moderationConfig = getModerationConfig (clearedBy );
135136 asyncPool .execute (() -> {
136137 try {
137- warnRepository .discardAll (user .getIdLong ());
138+ warnRepository .discardAll (user .getIdLong (), getEarliestActiveWarnTimestamp ( moderationConfig ) );
138139 MessageEmbed embed = buildClearWarnsEmbed (user , clearedBy .getUser ());
139140 notificationService .withUser (user , clearedBy .getGuild ()).sendDirectMessage (c -> c .sendMessageEmbeds (embed ));
140141 notificationService .withGuild (clearedBy .getGuild ()).sendToModerationLog (c -> c .sendMessageEmbeds (embed ));
@@ -144,6 +145,10 @@ public void discardAllWarns(User user, Member clearedBy) {
144145 });
145146 }
146147
148+ private LocalDateTime getEarliestActiveWarnTimestamp (ModerationConfig moderationConfig ) {
149+ return LocalDateTime .now ().minusDays (moderationConfig .getMaxWarnValidityDays ());
150+ }
151+
147152 /**
148153 * Clears a warn by discarding the Warn with the corresponding id.
149154 *
@@ -177,7 +182,7 @@ public List<Warn> getWarns(Guild guild, long userId) {
177182 try {
178183 ModerationConfig moderationConfig = botConfig .get (guild ).getModerationConfig ();
179184 WarnRepository repo = warnRepository ;
180- LocalDateTime cutoff = LocalDateTime . now (). minusDays ( moderationConfig . getMaxWarnValidityDays () );
185+ LocalDateTime cutoff = getEarliestActiveWarnTimestamp ( moderationConfig );
181186 return repo .getActiveWarnsByUserId (userId , cutoff );
182187 } catch (DataAccessException e ) {
183188 ExceptionLogger .capture (e , getClass ().getSimpleName ());
0 commit comments