Skip to content

Commit

Permalink
1.13.14 (#523)
Browse files Browse the repository at this point in the history
  • Loading branch information
rainbowdashlabs authored Apr 30, 2023
2 parents 06687a5 + 5e58bc3 commit 3d41eee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 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.13"
version = "1.13.14"

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

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -71,7 +72,7 @@ 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)));
return analyzer.log(message, resultCache.get(message.getIdLong(), () -> analyze(pattern, message, settings, limitTargets, limit)));
} 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());
Expand All @@ -86,21 +87,26 @@ public AnalyzerResult processMessage(Pattern pattern, @NotNull Message message,
return analyzer.log(message, AnalyzerResult.empty(EmptyResultReason.INTERNAL_ERROR));
}

private AnalyzerResult analyzeWithTimeout(Pattern pattern, Message message, @Nullable Settings settings, boolean limitTargets, int limit) {
return CompletableFuture.supplyAsync(() -> analyze(pattern, message, settings, limitTargets, limit))
@SuppressWarnings("DataFlowIssue") // We got no issues c:
private Optional<String> getThankword(Message message, Pattern pattern) {
return CompletableFuture.supplyAsync(() -> {
var contentRaw = message.getContentRaw().toLowerCase();
var matcher = pattern.matcher(contentRaw);
if (!matcher.find()) return Optional.ofNullable((String) null); // Yes this is intended
return Optional.ofNullable(matcher.group("match"));
})
.orTimeout(1L, TimeUnit.SECONDS)
.join();
}

private AnalyzerResult analyze(Pattern pattern, Message message, @Nullable Settings settings, boolean limitTargets, int limit) {
metrics.messages().countMessage();
if (pattern.pattern().isBlank()) return AnalyzerResult.empty(EmptyResultReason.NO_PATTERN);
var contentRaw = message.getContentRaw().toLowerCase();

var matcher = pattern.matcher(contentRaw);
if (!matcher.find()) return AnalyzerResult.empty(EmptyResultReason.NO_MATCH);
var thankword = getThankword(message, pattern);
if (thankword.isEmpty()) return AnalyzerResult.empty(EmptyResultReason.NO_MATCH);

var match = matcher.group("match");
var match = thankword.get();

if (message.getType() == MessageType.INLINE_REPLY) {

Expand Down

0 comments on commit 3d41eee

Please sign in to comment.