Skip to content

Commit

Permalink
Release 1.13.13
Browse files Browse the repository at this point in the history
  • Loading branch information
rainbowdashlabs authored Apr 30, 2023
2 parents ca14dd6 + 9ae4e09 commit 06687a5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = "de.chojo"
version = "1.13.12"
version = "1.13.13"

repositories {
maven("https://eldonexus.de/repository/maven-public")
Expand Down
33 changes: 17 additions & 16 deletions src/main/java/de/chojo/repbot/analyzer/MessageAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.util.concurrent.UncheckedExecutionException;
import de.chojo.jdautil.parsing.DiscordResolver;
import de.chojo.jdautil.parsing.WeightedEntry;
import de.chojo.repbot.analyzer.results.AnalyzerResult;
Expand All @@ -12,21 +13,17 @@
import de.chojo.repbot.dao.provider.Guilds;
import de.chojo.repbot.dao.provider.Metrics;
import de.chojo.repbot.util.LogNotify;

import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;

import javax.validation.constraints.Null;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.regex.Pattern;
Expand All @@ -40,9 +37,9 @@ public class MessageAnalyzer {
private static final Object PLACEHOLDER = new Object();
private final ContextResolver contextResolver;
private final Cache<Long, AnalyzerResult> resultCache = CacheBuilder.newBuilder()
.expireAfterWrite(10, TimeUnit.MINUTES)
.maximumSize(100000)
.build();
.expireAfterWrite(10, TimeUnit.MINUTES)
.maximumSize(100000)
.build();
private final Cache<Long, Object> rejectionCache = CacheBuilder.newBuilder()
.expireAfterWrite(1, TimeUnit.MINUTES)
.build();
Expand Down Expand Up @@ -75,10 +72,13 @@ public AnalyzerResult processMessage(Pattern pattern, @NotNull Message message,
var analyzer = guilds.guild(message.getGuild()).reputation().analyzer();
try {
return analyzer.log(message, resultCache.get(message.getIdLong(), () -> analyzeWithTimeout(pattern, message, settings, limitTargets, limit)));
} catch (ExecutionException e) {
} catch (ExecutionException | UncheckedExecutionException e) {
if (e.getCause() instanceof TimeoutException) {
log.warn(LogNotify.NOTIFY_ADMIN, "Timeout when analyzing message using pattern {} for guild {}", pattern.pattern(), settings.guildId());
rejectionCache.put(settings.guildId(), PLACEHOLDER);
} else if (e.getCause().getCause() instanceof TimeoutException) {
log.warn(LogNotify.NOTIFY_ADMIN, "Timeout when analyzing message using pattern {} for guild {}", pattern.pattern(), settings.guildId());
rejectionCache.put(settings.guildId(), PLACEHOLDER);
} else {
log.error("Could not compute analyzer result", e);
}
Expand All @@ -105,7 +105,8 @@ private AnalyzerResult analyze(Pattern pattern, Message message, @Nullable Setti
if (message.getType() == MessageType.INLINE_REPLY) {

var referencedMessage = message.getReferencedMessage();
if (referencedMessage == null) return AnalyzerResult.empty(match, EmptyResultReason.REFERENCE_MESSAGE_NOT_FOUND);
if (referencedMessage == null)
return AnalyzerResult.empty(match, EmptyResultReason.REFERENCE_MESSAGE_NOT_FOUND);

Member user;

Expand Down Expand Up @@ -200,15 +201,15 @@ private AnalyzerResult resolveMessage(String matchPattern, Message message, Patt
}

memberMatches = memberMatches.stream()
.filter(e -> e.score() >= configuration.analyzerSettings().minFuzzyScore())
.toList();
.filter(e -> e.score() >= configuration.analyzerSettings().minFuzzyScore())
.toList();

var members = users.stream()
.filter(e -> e.getWeight() >= configuration.analyzerSettings().minFuzzyScore())
.distinct()
.sorted()
.limit(limit)
.collect(Collectors.toList());
.filter(e -> e.getWeight() >= configuration.analyzerSettings().minFuzzyScore())
.distinct()
.sorted()
.limit(limit)
.collect(Collectors.toList());
if (members.isEmpty()) return AnalyzerResult.empty(matchPattern, EmptyResultReason.INSUFFICIENT_SCORE);

var thankwords = thankWordIndices.stream().map(words::get).collect(Collectors.toList());
Expand Down

0 comments on commit 06687a5

Please sign in to comment.