Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private boolean wasThreadAlreadyHandled(long threadChannelId) {
Instant now = Instant.now();
// NOTE It is necessary to do the "check if exists, otherwise insert" atomic
Instant createdAt = threadIdToCreatedAtCache.get(threadChannelId, _ -> now);
return createdAt != now;
return !createdAt.equals(now);
}

private void handleHelpThreadCreated(ThreadChannel threadChannel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void onMessageReceived(MessageReceivedEvent event) {
private boolean wasThreadAlreadyHandled(long threadChannelId) {
Instant now = Instant.now();
Instant createdAt = threadIdToCreatedAtCache.get(threadChannelId, any -> now);
return createdAt != now;
return !createdAt.equals(now);
}

private boolean isPostMessage(ThreadChannel threadChannel, MessageReceivedEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import java.time.Duration;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.regex.Pattern;
Expand All @@ -35,7 +35,7 @@ public final class RoleApplicationHandler {
private static final Logger logger = LoggerFactory.getLogger(RoleApplicationHandler.class);

private static final int APPLICATION_SUBMIT_COOLDOWN_MINUTES = 5;
private final Cache<Member, OffsetDateTime> applicationSubmitCooldown;
private final Cache<Member, Instant> applicationSubmitCooldown;
private final Predicate<String> applicationChannelPattern;
private final RoleApplicationSystemConfig roleApplicationSystemConfig;

Expand Down Expand Up @@ -125,10 +125,6 @@ private Optional<TextChannel> getApplicationChannel(Guild guild) {
.findFirst();
}

public Cache<Member, OffsetDateTime> getApplicationSubmitCooldown() {
return applicationSubmitCooldown;
}

void submitApplicationFromModalInteraction(ModalInteractionEvent event, List<String> args) {
Guild guild = event.getGuild();

Expand All @@ -150,13 +146,13 @@ void submitApplicationFromModalInteraction(ModalInteractionEvent event, List<Str
.queue();
}

applicationSubmitCooldown.put(event.getMember(), OffsetDateTime.now());
applicationSubmitCooldown.put(Objects.requireNonNull(event.getMember()), Instant.now());
}

long getMemberCooldownMinutes(Member member) {
OffsetDateTime timeSentCache = getApplicationSubmitCooldown().getIfPresent(member);
Instant timeSentCache = applicationSubmitCooldown.getIfPresent(member);
if (timeSentCache != null) {
Duration duration = Duration.between(timeSentCache, OffsetDateTime.now());
Duration duration = Duration.between(timeSentCache, Instant.now());
return APPLICATION_SUBMIT_COOLDOWN_MINUTES - duration.toMinutes();
}
return 0L;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.togetherjava.tjbot.features.rss;

import java.time.ZonedDateTime;
import java.time.Instant;

record FailureState(int count, ZonedDateTime lastFailure) {
record FailureState(int count, Instant lastFailure) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
import javax.annotation.Nonnull;

import java.io.IOException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.temporal.ChronoUnit;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -434,7 +436,7 @@ private List<Item> fetchRSSItemsFromURL(String rssUrl) {
"Possibly dead RSS feed URL: {} - Failed {} times. Please remove it from config.",
rssUrl, newCount);
}
circuitBreaker.put(rssUrl, new FailureState(newCount, ZonedDateTime.now()));
circuitBreaker.put(rssUrl, new FailureState(newCount, Instant.now()));

long blacklistedHours = calculateWaitHours(newCount);

Expand Down Expand Up @@ -476,8 +478,8 @@ private boolean isBackingOff(String url) {
}

long waitHours = calculateWaitHours(state.count());
ZonedDateTime retryAt = state.lastFailure().plusHours(waitHours);
Instant retryAt = state.lastFailure().plus(waitHours, ChronoUnit.HOURS);

return ZonedDateTime.now().isBefore(retryAt);
return Instant.now().isBefore(retryAt);
}
}
Loading