mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2025-01-14 20:21:21 +01:00
Add DiscordUser as context if DiscordGuildMember is present
This commit is contained in:
parent
350bd38c80
commit
53ced9be86
@ -74,6 +74,7 @@ import java.util.*;
|
|||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class JDAConnectionManager implements DiscordConnectionManager {
|
public class JDAConnectionManager implements DiscordConnectionManager {
|
||||||
|
|
||||||
@ -228,7 +229,7 @@ public class JDAConnectionManager implements DiscordConnectionManager {
|
|||||||
|
|
||||||
// Map JDA objects to 1st party API objects
|
// Map JDA objects to 1st party API objects
|
||||||
Set<Object> newContext = new HashSet<>();
|
Set<Object> newContext = new HashSet<>();
|
||||||
boolean anyConverted = false;
|
boolean contextChanged = false;
|
||||||
for (Object o : event.getContexts()) {
|
for (Object o : event.getContexts()) {
|
||||||
Object converted;
|
Object converted;
|
||||||
boolean isConversion = true;
|
boolean isConversion = true;
|
||||||
@ -257,13 +258,29 @@ public class JDAConnectionManager implements DiscordConnectionManager {
|
|||||||
isConversion = false;
|
isConversion = false;
|
||||||
}
|
}
|
||||||
if (isConversion) {
|
if (isConversion) {
|
||||||
anyConverted = true;
|
contextChanged = true;
|
||||||
}
|
}
|
||||||
newContext.add(converted);
|
newContext.add(converted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add DiscordUser as context if it is missing and DiscordGuildMember is present
|
||||||
|
List<DiscordGuildMember> members = newContext.stream()
|
||||||
|
.filter(context -> context instanceof DiscordGuildMember)
|
||||||
|
.map(context -> (DiscordGuildMember) context)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
for (DiscordGuildMember member : members) {
|
||||||
|
DiscordUser user = member.getUser();
|
||||||
|
boolean userMissing = newContext.stream()
|
||||||
|
.filter(context -> context instanceof DiscordUser)
|
||||||
|
.noneMatch(context -> ((DiscordUser) context).getId() == user.getId());
|
||||||
|
if (!userMissing) {
|
||||||
|
newContext.add(user);
|
||||||
|
contextChanged = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Prevent infinite recursion
|
// Prevent infinite recursion
|
||||||
if (anyConverted) {
|
if (contextChanged) {
|
||||||
event.process(PlaceholderLookupResult.newLookup(event.getPlaceholder(), newContext));
|
event.process(PlaceholderLookupResult.newLookup(event.getPlaceholder(), newContext));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user