2
2
3
3
import com .google .common .cache .Cache ;
4
4
import com .google .common .cache .CacheBuilder ;
5
+ import com .google .common .util .concurrent .UncheckedExecutionException ;
5
6
import de .chojo .jdautil .parsing .DiscordResolver ;
6
7
import de .chojo .jdautil .parsing .WeightedEntry ;
7
8
import de .chojo .repbot .analyzer .results .AnalyzerResult ;
12
13
import de .chojo .repbot .dao .provider .Guilds ;
13
14
import de .chojo .repbot .dao .provider .Metrics ;
14
15
import de .chojo .repbot .util .LogNotify ;
15
-
16
16
import net .dv8tion .jda .api .entities .Member ;
17
17
import net .dv8tion .jda .api .entities .Message ;
18
18
import net .dv8tion .jda .api .entities .MessageType ;
19
19
import org .jetbrains .annotations .NotNull ;
20
20
import org .jetbrains .annotations .Nullable ;
21
21
import org .slf4j .Logger ;
22
22
23
- import javax .validation .constraints .Null ;
24
23
import java .util .ArrayList ;
25
24
import java .util .List ;
26
25
import java .util .concurrent .CompletableFuture ;
27
26
import java .util .concurrent .ExecutionException ;
28
- import java .util .concurrent .Executors ;
29
- import java .util .concurrent .ForkJoinPool ;
30
27
import java .util .concurrent .TimeUnit ;
31
28
import java .util .concurrent .TimeoutException ;
32
29
import java .util .regex .Pattern ;
@@ -40,9 +37,9 @@ public class MessageAnalyzer {
40
37
private static final Object PLACEHOLDER = new Object ();
41
38
private final ContextResolver contextResolver ;
42
39
private final Cache <Long , AnalyzerResult > resultCache = CacheBuilder .newBuilder ()
43
- .expireAfterWrite (10 , TimeUnit .MINUTES )
44
- .maximumSize (100000 )
45
- .build ();
40
+ .expireAfterWrite (10 , TimeUnit .MINUTES )
41
+ .maximumSize (100000 )
42
+ .build ();
46
43
private final Cache <Long , Object > rejectionCache = CacheBuilder .newBuilder ()
47
44
.expireAfterWrite (1 , TimeUnit .MINUTES )
48
45
.build ();
@@ -75,10 +72,13 @@ public AnalyzerResult processMessage(Pattern pattern, @NotNull Message message,
75
72
var analyzer = guilds .guild (message .getGuild ()).reputation ().analyzer ();
76
73
try {
77
74
return analyzer .log (message , resultCache .get (message .getIdLong (), () -> analyzeWithTimeout (pattern , message , settings , limitTargets , limit )));
78
- } catch (ExecutionException e ) {
75
+ } catch (ExecutionException | UncheckedExecutionException e ) {
79
76
if (e .getCause () instanceof TimeoutException ) {
80
77
log .warn (LogNotify .NOTIFY_ADMIN , "Timeout when analyzing message using pattern {} for guild {}" , pattern .pattern (), settings .guildId ());
81
78
rejectionCache .put (settings .guildId (), PLACEHOLDER );
79
+ } else if (e .getCause ().getCause () instanceof TimeoutException ) {
80
+ log .warn (LogNotify .NOTIFY_ADMIN , "Timeout when analyzing message using pattern {} for guild {}" , pattern .pattern (), settings .guildId ());
81
+ rejectionCache .put (settings .guildId (), PLACEHOLDER );
82
82
} else {
83
83
log .error ("Could not compute analyzer result" , e );
84
84
}
@@ -105,7 +105,8 @@ private AnalyzerResult analyze(Pattern pattern, Message message, @Nullable Setti
105
105
if (message .getType () == MessageType .INLINE_REPLY ) {
106
106
107
107
var referencedMessage = message .getReferencedMessage ();
108
- if (referencedMessage == null ) return AnalyzerResult .empty (match , EmptyResultReason .REFERENCE_MESSAGE_NOT_FOUND );
108
+ if (referencedMessage == null )
109
+ return AnalyzerResult .empty (match , EmptyResultReason .REFERENCE_MESSAGE_NOT_FOUND );
109
110
110
111
Member user ;
111
112
@@ -200,15 +201,15 @@ private AnalyzerResult resolveMessage(String matchPattern, Message message, Patt
200
201
}
201
202
202
203
memberMatches = memberMatches .stream ()
203
- .filter (e -> e .score () >= configuration .analyzerSettings ().minFuzzyScore ())
204
- .toList ();
204
+ .filter (e -> e .score () >= configuration .analyzerSettings ().minFuzzyScore ())
205
+ .toList ();
205
206
206
207
var members = users .stream ()
207
- .filter (e -> e .getWeight () >= configuration .analyzerSettings ().minFuzzyScore ())
208
- .distinct ()
209
- .sorted ()
210
- .limit (limit )
211
- .collect (Collectors .toList ());
208
+ .filter (e -> e .getWeight () >= configuration .analyzerSettings ().minFuzzyScore ())
209
+ .distinct ()
210
+ .sorted ()
211
+ .limit (limit )
212
+ .collect (Collectors .toList ());
212
213
if (members .isEmpty ()) return AnalyzerResult .empty (matchPattern , EmptyResultReason .INSUFFICIENT_SCORE );
213
214
214
215
var thankwords = thankWordIndices .stream ().map (words ::get ).collect (Collectors .toList ());
0 commit comments