mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-01-13 04:05:17 +00:00
Compare commits
5 Commits
v1.6.16
...
feature/in
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bd00f6d248 | ||
|
|
0d5b7c5855 | ||
|
|
c791c063e3 | ||
|
|
d293d764db | ||
|
|
a7cd674cdd |
2
.env
2
.env
@@ -1,2 +1,2 @@
|
||||
REGISTRY_PREFIX=harbor.sheldan.dev/abstracto/
|
||||
VERSION=1.6.15
|
||||
VERSION=1.6.16
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>anti-raid</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.listener.DefaultListenerResult;
|
||||
import dev.sheldan.abstracto.core.listener.async.jda.AsyncMessageReceivedListener;
|
||||
import dev.sheldan.abstracto.core.models.listener.MessageReceivedModel;
|
||||
import io.micrometer.tracing.Span;
|
||||
import io.micrometer.tracing.Tracer;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.channel.ChannelType;
|
||||
@@ -19,13 +21,22 @@ public class MassPingMessageListener implements AsyncMessageReceivedListener {
|
||||
@Autowired
|
||||
private MassPingService massPingService;
|
||||
|
||||
@Autowired
|
||||
private Tracer tracer;
|
||||
|
||||
@Override
|
||||
public DefaultListenerResult execute(MessageReceivedModel model) {
|
||||
Message message = model.getMessage();
|
||||
if(message.getAuthor().isBot() || message.isWebhookMessage() || !message.isFromGuild() || !message.isFromType(ChannelType.TEXT)) {
|
||||
return DefaultListenerResult.IGNORED;
|
||||
Span newSpan = tracer.nextSpan().name("mass-ping-filter");
|
||||
try (Tracer.SpanInScope ws = this.tracer.withSpan(newSpan.start())) {
|
||||
Message message = model.getMessage();
|
||||
if (message.getAuthor().isBot() || message.isWebhookMessage() || !message.isFromGuild() || !message.isFromType(ChannelType.TEXT)) {
|
||||
newSpan.end();
|
||||
return DefaultListenerResult.IGNORED;
|
||||
}
|
||||
massPingService.processMessage(message).whenComplete((unused, throwable) -> {
|
||||
newSpan.end();
|
||||
});
|
||||
}
|
||||
massPingService.processMessage(message);
|
||||
return DefaultListenerResult.PROCESSED;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>anti-raid</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>assignable-roles</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>assignable-roles</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>assignable-roles-int</artifactId>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>custom-command</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>custom-command</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>dynamic-activity</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>dynamic-activity</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>entertainment</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>entertainment</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>experience-tracking</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ public class LeaderBoardCommand extends AbstractConditionableCommand {
|
||||
} else {
|
||||
leaderBoard = userExperienceService.findLeaderBoardData(server, page);
|
||||
}
|
||||
List<CompletableFuture> futures = new ArrayList<>();
|
||||
List<CompletableFuture<?>> futures = new ArrayList<>();
|
||||
CompletableFuture<List<LeaderBoardEntryModel>> completableFutures = converter.fromLeaderBoard(leaderBoard, actorUser.getGuild().getIdLong());
|
||||
futures.add(completableFutures);
|
||||
log.info("Rendering leaderboard for page {} in server {} for user {}.", page, actorUser.getId(), actorUser.getGuild().getId());
|
||||
|
||||
@@ -27,6 +27,8 @@ import dev.sheldan.abstracto.experience.service.ExperienceLevelService;
|
||||
import dev.sheldan.abstracto.experience.service.management.UserExperienceManagementService;
|
||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
||||
import io.micrometer.tracing.Span;
|
||||
import io.micrometer.tracing.Tracer;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
@@ -83,11 +85,14 @@ public class Rank extends AbstractConditionableCommand {
|
||||
@Value("${abstracto.experience.leaderboard.externalUrl}")
|
||||
private String leaderboardExternalURL;
|
||||
|
||||
@Autowired
|
||||
private Tracer tracer;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
Member targetMember = !parameters.isEmpty() ? (Member) parameters.get(0) : commandContext.getAuthor();
|
||||
if(!targetMember.getGuild().equals(commandContext.getGuild())) {
|
||||
if (!targetMember.getGuild().equals(commandContext.getGuild())) {
|
||||
throw new EntityGuildMismatchException();
|
||||
}
|
||||
AUserInAServer aUserInAServer = userInServerManagementService.loadOrCreateUser(targetMember);
|
||||
@@ -97,10 +102,13 @@ public class Rank extends AbstractConditionableCommand {
|
||||
.builder()
|
||||
.member(targetMember)
|
||||
.build();
|
||||
Span span = tracer.currentSpan();
|
||||
return future.thenCompose(leaderBoardEntryModel -> {
|
||||
try (Tracer.SpanInScope ws = tracer.withSpan(span)) {
|
||||
MessageToSend messageToSend = self.renderMessageToSend(targetMember, rankModel, leaderBoardEntryModel.get(0));
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(messageToSend, commandContext.getChannel()));
|
||||
}).thenApply(result -> CommandResult.fromIgnored());
|
||||
}
|
||||
}).thenApply(result -> CommandResult.fromIgnored());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@@ -133,7 +141,7 @@ public class Rank extends AbstractConditionableCommand {
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||
Member targetMember;
|
||||
if(slashCommandParameterService.hasCommandOption(MEMBER_PARAMETER, event)) {
|
||||
if (slashCommandParameterService.hasCommandOption(MEMBER_PARAMETER, event)) {
|
||||
targetMember = slashCommandParameterService.getCommandOption(MEMBER_PARAMETER, event, Member.class);
|
||||
} else {
|
||||
targetMember = event.getMember();
|
||||
@@ -145,9 +153,12 @@ public class Rank extends AbstractConditionableCommand {
|
||||
.builder()
|
||||
.member(targetMember)
|
||||
.build();
|
||||
Span span = tracer.currentSpan();
|
||||
return future.thenCompose(leaderBoardEntryModel -> {
|
||||
MessageToSend messageToSend = self.renderMessageToSend(targetMember, rankModel, leaderBoardEntryModel.get(0));
|
||||
return interactionService.replyMessageToSend(messageToSend, event);
|
||||
try (Tracer.SpanInScope ws = tracer.withSpan(span)) {
|
||||
MessageToSend messageToSend = self.renderMessageToSend(targetMember, rankModel, leaderBoardEntryModel.get(0));
|
||||
return interactionService.replyMessageToSend(messageToSend, event);
|
||||
}
|
||||
}).thenApply(result -> CommandResult.fromIgnored());
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,8 @@ import dev.sheldan.abstracto.core.service.MemberService;
|
||||
import dev.sheldan.abstracto.experience.model.LeaderBoard;
|
||||
import dev.sheldan.abstracto.experience.model.LeaderBoardEntry;
|
||||
import dev.sheldan.abstracto.experience.model.template.LeaderBoardEntryModel;
|
||||
import dev.sheldan.abstracto.experience.service.management.UserExperienceManagementService;
|
||||
import io.micrometer.tracing.Span;
|
||||
import io.micrometer.tracing.Tracer;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -29,10 +30,7 @@ public class LeaderBoardModelConverter {
|
||||
private MemberService memberService;
|
||||
|
||||
@Autowired
|
||||
private UserExperienceManagementService userExperienceManagementService;
|
||||
|
||||
@Autowired
|
||||
private LeaderBoardModelConverter self;
|
||||
private Tracer tracer;
|
||||
|
||||
/**
|
||||
* Converts the complete {@link LeaderBoard leaderBoard} into a list of {@link LeaderBoardEntryModel leaderbaordEntryModels} which contain additional
|
||||
@@ -62,12 +60,15 @@ public class LeaderBoardModelConverter {
|
||||
.build();
|
||||
})
|
||||
.collect(Collectors.toMap(LeaderBoardEntryModel::getUserId, Function.identity()));
|
||||
Span span = tracer.currentSpan();
|
||||
return memberService.getMembersInServerAsync(serverId, userIds).thenApply(members -> {
|
||||
members.forEach(member -> models.get(member.getIdLong()).setMember(member));
|
||||
return new ArrayList<>(models.values())
|
||||
.stream()
|
||||
.sorted(Comparator.comparing(LeaderBoardEntryModel::getRank)).
|
||||
collect(Collectors.toList());
|
||||
try (Tracer.SpanInScope ws = tracer.withSpan(span)) {
|
||||
members.forEach(member -> models.get(member.getIdLong()).setMember(member));
|
||||
return new ArrayList<>(models.values())
|
||||
.stream()
|
||||
.sorted(Comparator.comparing(LeaderBoardEntryModel::getRank)).
|
||||
collect(Collectors.toList());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import dev.sheldan.abstracto.core.listener.sync.jda.MessageReceivedListener;
|
||||
import dev.sheldan.abstracto.core.models.listener.MessageReceivedModel;
|
||||
import dev.sheldan.abstracto.experience.config.ExperienceFeatureDefinition;
|
||||
import dev.sheldan.abstracto.experience.service.AUserExperienceService;
|
||||
import io.micrometer.tracing.Span;
|
||||
import io.micrometer.tracing.Tracer;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -23,17 +25,26 @@ public class ExperienceTrackerListener implements AsyncMessageReceivedListener {
|
||||
@Autowired
|
||||
private AUserExperienceService userExperienceService;
|
||||
|
||||
@Autowired
|
||||
private Tracer tracer;
|
||||
|
||||
@Override
|
||||
public DefaultListenerResult execute(MessageReceivedModel model) {
|
||||
Message message = model.getMessage();
|
||||
if(!message.isFromGuild() || message.isWebhookMessage() || message.getType().isSystem() || message.getAuthor().isBot()) {
|
||||
return DefaultListenerResult.IGNORED;
|
||||
}
|
||||
if(userExperienceService.experienceGainEnabledInChannel(message.getChannel())) {
|
||||
userExperienceService.addExperience(message.getMember(), model.getMessage());
|
||||
return DefaultListenerResult.PROCESSED;
|
||||
} else {
|
||||
return DefaultListenerResult.IGNORED;
|
||||
Span newSpan = tracer.nextSpan().name("experience-tracker");
|
||||
try (Tracer.SpanInScope ws = this.tracer.withSpan(newSpan.start())) {
|
||||
Message message = model.getMessage();
|
||||
if(!message.isFromGuild() || message.isWebhookMessage() || message.getType().isSystem() || message.getAuthor().isBot()) {
|
||||
newSpan.end();
|
||||
return DefaultListenerResult.IGNORED;
|
||||
}
|
||||
if(userExperienceService.experienceGainEnabledInChannel(message.getChannel())) {
|
||||
userExperienceService.addExperience(message.getMember(), model.getMessage()).whenComplete((unused, throwable) -> {
|
||||
newSpan.end();
|
||||
});
|
||||
return DefaultListenerResult.PROCESSED;
|
||||
} else {
|
||||
return DefaultListenerResult.IGNORED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.sheldan.abstracto.experience.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.metric.service.MetricUtils;
|
||||
import dev.sheldan.abstracto.core.models.database.*;
|
||||
import dev.sheldan.abstracto.core.models.template.display.MemberDisplay;
|
||||
import dev.sheldan.abstracto.core.models.template.display.RoleDisplay;
|
||||
@@ -25,6 +26,8 @@ import dev.sheldan.abstracto.experience.service.management.DisabledExpRoleManage
|
||||
import dev.sheldan.abstracto.experience.service.management.ExperienceLevelManagementService;
|
||||
import dev.sheldan.abstracto.experience.service.management.ExperienceRoleManagementService;
|
||||
import dev.sheldan.abstracto.experience.service.management.UserExperienceManagementService;
|
||||
import io.micrometer.tracing.Span;
|
||||
import io.micrometer.tracing.Tracer;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
@@ -114,8 +117,11 @@ public class AUserExperienceServiceBean implements AUserExperienceService {
|
||||
@Qualifier("experienceUpdateExecutor")
|
||||
private TaskExecutor experienceUpdateExecutor;
|
||||
|
||||
@Autowired
|
||||
private Tracer tracer;
|
||||
|
||||
@Override
|
||||
public void addExperience(Member member, Message message) {
|
||||
public CompletableFuture<Void> addExperience(Member member, Message message) {
|
||||
runTimeExperienceService.takeLock();
|
||||
try {
|
||||
Map<Long, Map<Long, Instant>> runtimeExperience = runTimeExperienceService.getRuntimeExperience();
|
||||
@@ -141,7 +147,7 @@ public class AUserExperienceServiceBean implements AUserExperienceService {
|
||||
// we store when the user is eligible for experience _again_
|
||||
Long maxSeconds = configService.getLongValueOrConfigDefault(EXP_COOLDOWN_SECONDS_KEY, serverId);
|
||||
serverExperience.put(userId, Instant.now().plus(maxSeconds, ChronoUnit.SECONDS));
|
||||
CompletableFuture.runAsync(() -> self.addExperienceToMember(member, message), experienceUpdateExecutor).exceptionally(throwable -> {
|
||||
return CompletableFuture.runAsync(() -> self.addExperienceToMember(member, message), MetricUtils.wrapExecutor(experienceUpdateExecutor)).exceptionally(throwable -> {
|
||||
log.error("Failed to add experience to member {} in server {}.", message.getAuthor().getId(), message.getGuild().getIdLong(), throwable);
|
||||
return null;
|
||||
});
|
||||
@@ -149,6 +155,7 @@ public class AUserExperienceServiceBean implements AUserExperienceService {
|
||||
} finally {
|
||||
runTimeExperienceService.releaseLock();
|
||||
}
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
|
||||
@@ -297,61 +304,69 @@ public class AUserExperienceServiceBean implements AUserExperienceService {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void addExperienceToMember(Member member, Message message) {
|
||||
long serverId = member.getGuild().getIdLong();
|
||||
AServer server = serverManagementService.loadOrCreate(serverId);
|
||||
List<ADisabledExpRole> disabledExpRoles = disabledExpRoleManagementService.getDisabledRolesForServer(server);
|
||||
List<ARole> disabledRoles = disabledExpRoles
|
||||
public CompletableFuture<Void> addExperienceToMember(Member member, Message message) {
|
||||
CompletableFuture<Void> notificationFuture = CompletableFuture.completedFuture(null);
|
||||
CompletableFuture<Void> levelActionFuture = CompletableFuture.completedFuture(null);
|
||||
CompletableFuture<Void> roleFuture = CompletableFuture.completedFuture(null);
|
||||
Span newSpan = tracer.nextSpan().name("experience-adding");
|
||||
try (Tracer.SpanInScope ws = this.tracer.withSpan(newSpan.start())) {
|
||||
long serverId = member.getGuild().getIdLong();
|
||||
AServer server = serverManagementService.loadOrCreate(serverId);
|
||||
List<ADisabledExpRole> disabledExpRoles = disabledExpRoleManagementService.getDisabledRolesForServer(server);
|
||||
List<ARole> disabledRoles = disabledExpRoles
|
||||
.stream()
|
||||
.map(ADisabledExpRole::getRole)
|
||||
.collect(Collectors.toList());
|
||||
if(roleService.hasAnyOfTheRoles(member, disabledRoles)) {
|
||||
log.debug("User {} has a experience disable role in server {} - not giving any experience.", member.getIdLong(), serverId);
|
||||
return;
|
||||
}
|
||||
AUserInAServer userInAServer = userInServerManagementService.loadOrCreateUser(member);
|
||||
Long userInServerId = userInAServer.getUserInServerId();
|
||||
Optional<AUserExperience> aUserExperienceOptional = userExperienceManagementService.findByUserInServerIdOptional(userInAServer.getUserInServerId());
|
||||
AUserExperience aUserExperience = aUserExperienceOptional.orElseGet(() -> userExperienceManagementService.createUserInServer(userInAServer));
|
||||
if(Boolean.FALSE.equals(aUserExperience.getExperienceGainDisabled())) {
|
||||
List<AExperienceLevel> levels = experienceLevelManagementService.getLevelConfig();
|
||||
levels.sort(Comparator.comparing(AExperienceLevel::getExperienceNeeded));
|
||||
if (roleService.hasAnyOfTheRoles(member, disabledRoles)) {
|
||||
log.debug("User {} has a experience disable role in server {} - not giving any experience.", member.getIdLong(), serverId);
|
||||
newSpan.end();
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
AUserInAServer userInAServer = userInServerManagementService.loadOrCreateUser(member);
|
||||
Long userInServerId = userInAServer.getUserInServerId();
|
||||
Optional<AUserExperience> aUserExperienceOptional = userExperienceManagementService.findByUserInServerIdOptional(userInAServer.getUserInServerId());
|
||||
AUserExperience aUserExperience = aUserExperienceOptional.orElseGet(() -> userExperienceManagementService.createUserInServer(userInAServer));
|
||||
if (Boolean.FALSE.equals(aUserExperience.getExperienceGainDisabled())) {
|
||||
List<AExperienceLevel> levels = experienceLevelManagementService.getLevelConfig();
|
||||
levels.sort(Comparator.comparing(AExperienceLevel::getExperienceNeeded));
|
||||
|
||||
Long minExp = configService.getLongValueOrConfigDefault(ExperienceFeatureConfig.MIN_EXP_KEY, serverId);
|
||||
Long maxExp = configService.getLongValueOrConfigDefault(ExperienceFeatureConfig.MAX_EXP_KEY, serverId);
|
||||
Double multiplier = configService.getDoubleValueOrConfigDefault(ExperienceFeatureConfig.EXP_MULTIPLIER_KEY, serverId);
|
||||
Long experienceRange = maxExp - minExp + 1;
|
||||
Long gainedExperience = (secureRandom.nextInt(experienceRange.intValue()) + minExp);
|
||||
gainedExperience = (long) Math.floor(gainedExperience * multiplier);
|
||||
Long minExp = configService.getLongValueOrConfigDefault(ExperienceFeatureConfig.MIN_EXP_KEY, serverId);
|
||||
Long maxExp = configService.getLongValueOrConfigDefault(ExperienceFeatureConfig.MAX_EXP_KEY, serverId);
|
||||
Double multiplier = configService.getDoubleValueOrConfigDefault(ExperienceFeatureConfig.EXP_MULTIPLIER_KEY, serverId);
|
||||
Long experienceRange = maxExp - minExp + 1;
|
||||
Long gainedExperience = (secureRandom.nextInt(experienceRange.intValue()) + minExp);
|
||||
gainedExperience = (long) Math.floor(gainedExperience * multiplier);
|
||||
|
||||
List<AExperienceRole> roles = experienceRoleManagementService.getExperienceRolesForServer(server);
|
||||
roles.sort(Comparator.comparing(role -> role.getLevel().getLevel()));
|
||||
List<AExperienceRole> roles = experienceRoleManagementService.getExperienceRolesForServer(server);
|
||||
roles.sort(Comparator.comparing(role -> role.getLevel().getLevel()));
|
||||
|
||||
log.debug("Handling {}. The user gains {}.", userInServerId, gainedExperience);
|
||||
log.debug("Handling {}. The user gains {}.", userInServerId, gainedExperience);
|
||||
|
||||
Long oldExperience = aUserExperience.getExperience();
|
||||
Long newExperienceCount = oldExperience + gainedExperience;
|
||||
aUserExperience.setExperience(newExperienceCount);
|
||||
AExperienceLevel newLevel = calculateLevel(levels, newExperienceCount);
|
||||
RoleCalculationResult result = RoleCalculationResult
|
||||
Long oldExperience = aUserExperience.getExperience();
|
||||
Long newExperienceCount = oldExperience + gainedExperience;
|
||||
aUserExperience.setExperience(newExperienceCount);
|
||||
AExperienceLevel newLevel = calculateLevel(levels, newExperienceCount);
|
||||
RoleCalculationResult result = RoleCalculationResult
|
||||
.builder()
|
||||
.build();
|
||||
boolean userChangesLevel = !Objects.equals(newLevel.getLevel(), aUserExperience.getCurrentLevel().getLevel());
|
||||
Integer oldLevel = aUserExperience.getCurrentLevel() != null ? aUserExperience.getCurrentLevel().getLevel() : 0;
|
||||
if(userChangesLevel) {
|
||||
log.info("User {} in server {} changed level. New {}, Old {}.", member.getIdLong(),
|
||||
boolean userChangesLevel = !Objects.equals(newLevel.getLevel(), aUserExperience.getCurrentLevel().getLevel());
|
||||
Integer oldLevel = aUserExperience.getCurrentLevel() != null ? aUserExperience.getCurrentLevel().getLevel() : 0;
|
||||
if (userChangesLevel) {
|
||||
log.info("User {} in server {} changed level. New {}, Old {}.", member.getIdLong(),
|
||||
member.getGuild().getIdLong(), newLevel.getLevel(),
|
||||
oldLevel);
|
||||
aUserExperience.setCurrentLevel(newLevel);
|
||||
AExperienceRole calculatedNewRole = experienceRoleService.calculateRole(roles, newLevel.getLevel());
|
||||
Long oldRoleId = aUserExperience.getCurrentExperienceRole() != null && aUserExperience.getCurrentExperienceRole().getRole() != null ? aUserExperience.getCurrentExperienceRole().getRole().getId() : null;
|
||||
Long newRoleId = calculatedNewRole != null && calculatedNewRole.getRole() != null ? calculatedNewRole.getRole().getId() : null;
|
||||
result.setOldRoleId(oldRoleId);
|
||||
result.setNewRoleId(newRoleId);
|
||||
if(message != null
|
||||
aUserExperience.setCurrentLevel(newLevel);
|
||||
AExperienceRole calculatedNewRole = experienceRoleService.calculateRole(roles, newLevel.getLevel());
|
||||
Long oldRoleId = aUserExperience.getCurrentExperienceRole() != null && aUserExperience.getCurrentExperienceRole().getRole() != null ?
|
||||
aUserExperience.getCurrentExperienceRole().getRole().getId() : null;
|
||||
Long newRoleId = calculatedNewRole != null && calculatedNewRole.getRole() != null ? calculatedNewRole.getRole().getId() : null;
|
||||
result.setOldRoleId(oldRoleId);
|
||||
result.setNewRoleId(newRoleId);
|
||||
if (message != null
|
||||
&& aUserExperience.getLevelUpNotification()
|
||||
&& featureModeService.featureModeActive(ExperienceFeatureDefinition.EXPERIENCE, serverId, ExperienceFeatureMode.LEVEL_UP_NOTIFICATION)) {
|
||||
LevelUpNotificationModel model = LevelUpNotificationModel
|
||||
&&
|
||||
featureModeService.featureModeActive(ExperienceFeatureDefinition.EXPERIENCE, serverId, ExperienceFeatureMode.LEVEL_UP_NOTIFICATION)) {
|
||||
LevelUpNotificationModel model = LevelUpNotificationModel
|
||||
.builder()
|
||||
.memberDisplay(MemberDisplay.fromMember(member))
|
||||
.oldExperience(oldExperience)
|
||||
@@ -361,59 +376,71 @@ public class AUserExperienceServiceBean implements AUserExperienceService {
|
||||
.newRole(oldRoleId != null ? RoleDisplay.fromRole(oldRoleId) : null)
|
||||
.newRole(newRoleId != null ? RoleDisplay.fromRole(newRoleId) : null)
|
||||
.build();
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate("experience_level_up_notification", model, serverId);
|
||||
FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(messageToSend, message.getChannel())).thenAccept(unused -> {
|
||||
log.info("Sent level up notification to user {} in server {} in channel {}.", member.getIdLong(), serverId, message.getChannel().getIdLong());
|
||||
}).exceptionally(throwable -> {
|
||||
log.warn("Failed to send level up notification to user {} in server {} in channel {}.", member.getIdLong(), serverId, message.getChannel().getIdLong());
|
||||
return null;
|
||||
});
|
||||
}
|
||||
aUserExperience.setCurrentExperienceRole(calculatedNewRole);
|
||||
}
|
||||
aUserExperience.setMessageCount(aUserExperience.getMessageCount() + 1L);
|
||||
if(userChangesLevel && featureModeService.featureModeActive(ExperienceFeatureDefinition.EXPERIENCE, server, ExperienceFeatureMode.LEVEL_ACTION)) {
|
||||
levelActionService.applyLevelActionsToUser(aUserExperience, oldLevel)
|
||||
.thenAccept(unused -> {
|
||||
log.info("Executed level actions for user {}.", userInServerId);
|
||||
})
|
||||
.exceptionally(throwable -> {
|
||||
log.warn("Failed to execute level actions for user {}.", userInServerId, throwable);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
if(aUserExperienceOptional.isEmpty()) {
|
||||
userExperienceManagementService.saveUser(aUserExperience);
|
||||
}
|
||||
if(!Objects.equals(result.getOldRoleId(), result.getNewRoleId())) {
|
||||
if(result.getOldRoleId() != null && result.getNewRoleId() != null) {
|
||||
roleService.updateRolesIds(member, Arrays.asList(result.getOldRoleId()), Arrays.asList(result.getNewRoleId())).thenAccept(unused -> {
|
||||
log.debug("Removed role {} from and added role {} to member {} in server {}.", result.getOldRoleId(), result.getNewRoleId(), member.getIdLong(), member.getGuild().getIdLong());
|
||||
}).exceptionally(throwable -> {
|
||||
log.warn("Failed to remove role {} from and add role {} to member {} in server {}.", result.getOldRoleId(), result.getNewRoleId(), member.getIdLong(), member.getGuild().getIdLong(), throwable);
|
||||
return null;
|
||||
});
|
||||
} else {
|
||||
if(result.getOldRoleId() != null) {
|
||||
roleService.removeRoleFromMemberAsync(member, result.getOldRoleId()).thenAccept(unused -> {
|
||||
log.debug("Removed role {} from member {} in server {}.", result.getOldRoleId(), member.getIdLong(), member.getGuild().getIdLong());
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate("experience_level_up_notification", model, serverId);
|
||||
FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(messageToSend, message.getChannel())).thenAccept(unused -> {
|
||||
log.info("Sent level up notification to user {} in server {} in channel {}.", member.getIdLong(), serverId,
|
||||
message.getChannel().getIdLong());
|
||||
}).exceptionally(throwable -> {
|
||||
log.warn("Failed to remove role {} from member {} in server {}.", result.getOldRoleId(), member.getIdLong(), member.getGuild().getIdLong(), throwable);
|
||||
log.warn("Failed to send level up notification to user {} in server {} in channel {}.", member.getIdLong(), serverId,
|
||||
message.getChannel().getIdLong());
|
||||
return null;
|
||||
});
|
||||
}
|
||||
if(result.getNewRoleId() != null) {
|
||||
roleService.addRoleToMemberAsync(member, result.getNewRoleId()).thenAccept(unused -> {
|
||||
log.debug("Added role {} to member {} in server {}.", result.getNewRoleId(), member.getIdLong(), member.getGuild().getIdLong());
|
||||
}).exceptionally(throwable -> {
|
||||
log.warn("Failed to add role {} to member {} in server {}.", result.getOldRoleId(), member.getIdLong(), member.getGuild().getIdLong(), throwable);
|
||||
aUserExperience.setCurrentExperienceRole(calculatedNewRole);
|
||||
}
|
||||
aUserExperience.setMessageCount(aUserExperience.getMessageCount() + 1L);
|
||||
if (userChangesLevel &&
|
||||
featureModeService.featureModeActive(ExperienceFeatureDefinition.EXPERIENCE, server, ExperienceFeatureMode.LEVEL_ACTION)) {
|
||||
levelActionService.applyLevelActionsToUser(aUserExperience, oldLevel)
|
||||
.thenAccept(unused -> {
|
||||
log.info("Executed level actions for user {}.", userInServerId);
|
||||
})
|
||||
.exceptionally(throwable -> {
|
||||
log.warn("Failed to execute level actions for user {}.", userInServerId, throwable);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
if (aUserExperienceOptional.isEmpty()) {
|
||||
userExperienceManagementService.saveUser(aUserExperience);
|
||||
}
|
||||
if (!Objects.equals(result.getOldRoleId(), result.getNewRoleId())) {
|
||||
if (result.getOldRoleId() != null && result.getNewRoleId() != null) {
|
||||
roleService.updateRolesIds(member, Arrays.asList(result.getOldRoleId()), Arrays.asList(result.getNewRoleId())).thenAccept(unused -> {
|
||||
log.debug("Removed role {} from and added role {} to member {} in server {}.", result.getOldRoleId(), result.getNewRoleId(),
|
||||
member.getIdLong(), member.getGuild().getIdLong());
|
||||
}).exceptionally(throwable -> {
|
||||
log.warn("Failed to remove role {} from and add role {} to member {} in server {}.", result.getOldRoleId(), result.getNewRoleId(),
|
||||
member.getIdLong(), member.getGuild().getIdLong(), throwable);
|
||||
return null;
|
||||
});
|
||||
} else {
|
||||
if (result.getOldRoleId() != null) {
|
||||
roleService.removeRoleFromMemberAsync(member, result.getOldRoleId()).thenAccept(unused -> {
|
||||
log.debug("Removed role {} from member {} in server {}.", result.getOldRoleId(), member.getIdLong(),
|
||||
member.getGuild().getIdLong());
|
||||
}).exceptionally(throwable -> {
|
||||
log.warn("Failed to remove role {} from member {} in server {}.", result.getOldRoleId(), member.getIdLong(),
|
||||
member.getGuild().getIdLong(), throwable);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
if (result.getNewRoleId() != null) {
|
||||
roleService.addRoleToMemberAsync(member, result.getNewRoleId()).thenAccept(unused -> {
|
||||
log.debug("Added role {} to member {} in server {}.", result.getNewRoleId(), member.getIdLong(), member.getGuild().getIdLong());
|
||||
}).exceptionally(throwable -> {
|
||||
log.warn("Failed to add role {} to member {} in server {}.", result.getOldRoleId(), member.getIdLong(),
|
||||
member.getGuild().getIdLong(), throwable);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.debug("Experience gain was disabled. User did not gain any experience.");
|
||||
}
|
||||
} else {
|
||||
log.debug("Experience gain was disabled. User did not gain any experience.");
|
||||
return CompletableFuture.allOf(notificationFuture, levelActionFuture, roleFuture).whenComplete((unused, throwable) -> {
|
||||
newSpan.end();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>experience-tracking</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
*/
|
||||
public interface AUserExperienceService {
|
||||
String EXPERIENCE_GAIN_CHANNEL_GROUP_KEY = "experienceGain";
|
||||
void addExperience(Member member, Message message);
|
||||
CompletableFuture<Void> addExperience(Member member, Message message);
|
||||
|
||||
/**
|
||||
* Calculates the appropriate level for the given experience amount according to the given {@link AExperienceLevel levels}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>giveaway</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>giveaway-impl</artifactId>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>giveaway</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>giveaway-int</artifactId>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>giveaway</artifactId>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<artifactId>image-generation</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>image-generation-impl</artifactId>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<artifactId>image-generation</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>image-generation-int</artifactId>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>image-generation</artifactId>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>invite-filter</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ import dev.sheldan.abstracto.core.models.listener.MessageReceivedModel;
|
||||
import dev.sheldan.abstracto.invitefilter.config.InviteFilterFeatureDefinition;
|
||||
import dev.sheldan.abstracto.invitefilter.service.InviteLinkFilterService;
|
||||
import dev.sheldan.abstracto.invitefilter.service.InviteLinkFilterServiceBean;
|
||||
import io.micrometer.tracing.Span;
|
||||
import io.micrometer.tracing.Tracer;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -24,6 +26,9 @@ public class InviteLinkFilterListener implements AsyncMessageReceivedListener {
|
||||
@Autowired
|
||||
private InviteLinkFilterServiceBean filterServiceBean;
|
||||
|
||||
@Autowired
|
||||
private Tracer tracer;
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return InviteFilterFeatureDefinition.INVITE_FILTER;
|
||||
@@ -31,31 +36,40 @@ public class InviteLinkFilterListener implements AsyncMessageReceivedListener {
|
||||
|
||||
@Override
|
||||
public DefaultListenerResult execute(MessageReceivedModel model) {
|
||||
Message message = model.getMessage();
|
||||
Span newSpan = tracer.nextSpan().name("invite-filter");
|
||||
try (Tracer.SpanInScope ws = this.tracer.withSpan(newSpan.start())) {
|
||||
Message message = model.getMessage();
|
||||
|
||||
if(!message.isFromGuild() || message.isWebhookMessage() || message.getType().isSystem()) {
|
||||
return DefaultListenerResult.IGNORED;
|
||||
if (!message.isFromGuild() || message.isWebhookMessage() || message.getType().isSystem()) {
|
||||
newSpan.end();
|
||||
return DefaultListenerResult.IGNORED;
|
||||
}
|
||||
|
||||
List<String> foundInvites = inviteLinkFilterService.findInvitesInMessage(message);
|
||||
|
||||
if (foundInvites.isEmpty()) {
|
||||
newSpan.end();
|
||||
return DefaultListenerResult.IGNORED;
|
||||
}
|
||||
|
||||
if (!inviteLinkFilterService.isInviteFilterActiveInChannel(message.getChannel())) {
|
||||
newSpan.end();
|
||||
return DefaultListenerResult.IGNORED;
|
||||
}
|
||||
|
||||
if (inviteLinkFilterService.isMemberImmuneAgainstInviteFilter(message.getMember())) {
|
||||
log.info("Not checking for invites in message, because author {} in channel {} in guild {} is immune against invite filter.",
|
||||
message.getMember().getIdLong(), message.getGuild().getIdLong(), message.getChannel().getIdLong());
|
||||
newSpan.end();
|
||||
return DefaultListenerResult.IGNORED;
|
||||
}
|
||||
|
||||
// only to reduce code duplication, the interface is too concrete
|
||||
filterServiceBean.resolveAndCheckInvites(message, foundInvites).whenComplete((unused, throwable) -> {
|
||||
newSpan.end();
|
||||
});
|
||||
|
||||
return DefaultListenerResult.PROCESSED;
|
||||
}
|
||||
|
||||
List<String> foundInvites = inviteLinkFilterService.findInvitesInMessage(message);
|
||||
|
||||
if(foundInvites.isEmpty()){
|
||||
return DefaultListenerResult.IGNORED;
|
||||
}
|
||||
|
||||
if(!inviteLinkFilterService.isInviteFilterActiveInChannel(message.getChannel())) {
|
||||
return DefaultListenerResult.IGNORED;
|
||||
}
|
||||
|
||||
if(inviteLinkFilterService.isMemberImmuneAgainstInviteFilter(message.getMember())) {
|
||||
log.info("Not checking for invites in message, because author {} in channel {} in guild {} is immune against invite filter.",
|
||||
message.getMember().getIdLong(), message.getGuild().getIdLong(), message.getChannel().getIdLong());
|
||||
return DefaultListenerResult.IGNORED;
|
||||
}
|
||||
|
||||
// only to reduce code duplication, the interface is too concrete
|
||||
filterServiceBean.resolveAndCheckInvites(message, foundInvites);
|
||||
|
||||
return DefaultListenerResult.PROCESSED;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -303,12 +303,13 @@ public class InviteLinkFilterServiceBean implements InviteLinkFilterService {
|
||||
return foundInvites;
|
||||
}
|
||||
|
||||
public void resolveAndCheckInvites(Message message, List<String> foundInvites) {
|
||||
public CompletableFuture<Void> resolveAndCheckInvites(Message message, List<String> foundInvites) {
|
||||
List<CompletableFuture<Invite>> inviteList = new ArrayList<>();
|
||||
JDA jda = message.getJDA();
|
||||
foundInvites.forEach(s -> inviteList.add(resolveInvite(jda, s)));
|
||||
|
||||
CompletableFutureList<Invite> list = new CompletableFutureList<>(inviteList);
|
||||
CompletableFuture<Void> returningFuture = new CompletableFuture<>();
|
||||
list.getMainFuture().whenComplete((unused, throwable) -> {
|
||||
List<Invite> invites = list.getObjects();
|
||||
Long serverId = message.getGuild().getIdLong();
|
||||
@@ -353,24 +354,31 @@ public class InviteLinkFilterServiceBean implements InviteLinkFilterService {
|
||||
}
|
||||
if(toDelete) {
|
||||
metricService.incrementCounter(MESSAGE_INVITE_FILTERED);
|
||||
messageService.deleteMessage(message);
|
||||
|
||||
CompletableFuture<Void> deletionFuture = messageService.deleteMessage(message);
|
||||
CompletableFuture<Void> notificationFuture = CompletableFuture.completedFuture(null);
|
||||
boolean trackUsages = featureModeService.featureModeActive(InviteFilterFeatureDefinition.INVITE_FILTER, serverId, InviteFilterMode.TRACK_USES);
|
||||
if(trackUsages) {
|
||||
targetServers.forEach((targetServerId, serverName) -> storeFilteredInviteLinkUsage(targetServerId, serverName, author));
|
||||
}
|
||||
boolean sendNotification = featureModeService.featureModeActive(InviteFilterFeatureDefinition.INVITE_FILTER, serverId, InviteFilterMode.FILTER_NOTIFICATIONS);
|
||||
if(sendNotification) {
|
||||
sendDeletionNotification(deletedInvites, message)
|
||||
notificationFuture = sendDeletionNotification(deletedInvites, message)
|
||||
.thenAccept(unused1 -> log.info("Sent invite deletion notification.")).exceptionally(throwable1 -> {
|
||||
log.error("Failed to send invite deletion notification.");
|
||||
return null;
|
||||
});
|
||||
}
|
||||
CompletableFuture.allOf(deletionFuture, notificationFuture).whenComplete((unused1, throwable1) -> {
|
||||
returningFuture.complete(null);
|
||||
});
|
||||
}
|
||||
}).exceptionally(throwable -> {
|
||||
log.error("Invite matching failed.", throwable);
|
||||
returningFuture.complete(null);
|
||||
return null;
|
||||
});
|
||||
return returningFuture;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>invite-filter</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
<dependency>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>moderation-int</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>link-embed</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>link-embed</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>logging</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>logging</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>moderation</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>moderation</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>modmail</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>modmail</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto</groupId>
|
||||
<artifactId>abstracto-application</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>profanity-filter</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ import dev.sheldan.abstracto.core.service.ProfanityService;
|
||||
import dev.sheldan.abstracto.profanityfilter.config.ProfanityFilterFeatureDefinition;
|
||||
import dev.sheldan.abstracto.profanityfilter.service.ProfanityFilterService;
|
||||
import dev.sheldan.abstracto.profanityfilter.service.ProfanityFilterServiceBean;
|
||||
import io.micrometer.tracing.Span;
|
||||
import io.micrometer.tracing.Tracer;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -29,25 +31,35 @@ public class ProfanityMessageReceivedListener implements AsyncMessageReceivedLis
|
||||
@Autowired
|
||||
private ProfanityFilterServiceBean profanityFilterServiceBean;
|
||||
|
||||
@Autowired
|
||||
private Tracer tracer;
|
||||
|
||||
@Override
|
||||
public DefaultListenerResult execute(MessageReceivedModel model) {
|
||||
Message message = model.getMessage();
|
||||
if(message.isWebhookMessage() || message.getType().isSystem() || !message.isFromGuild()) {
|
||||
return DefaultListenerResult.IGNORED;
|
||||
}
|
||||
Span newSpan = tracer.nextSpan().name("profanity-filter");
|
||||
try (Tracer.SpanInScope ws = this.tracer.withSpan(newSpan.start())) {
|
||||
Message message = model.getMessage();
|
||||
if (message.isWebhookMessage() || message.getType().isSystem() || !message.isFromGuild()) {
|
||||
newSpan.end();
|
||||
return DefaultListenerResult.IGNORED;
|
||||
}
|
||||
|
||||
if(profanityFilterService.isImmuneAgainstProfanityFilter(message.getMember())) {
|
||||
log.debug("Not checking for profanities in message, because author {} in channel {} in guild {} is immune against profanity filter.",
|
||||
message.getMember().getIdLong(), message.getGuild().getIdLong(), message.getChannel().getIdLong());
|
||||
return DefaultListenerResult.IGNORED;
|
||||
}
|
||||
if (profanityFilterService.isImmuneAgainstProfanityFilter(message.getMember())) {
|
||||
log.debug("Not checking for profanities in message, because author {} in channel {} in guild {} is immune against profanity filter.",
|
||||
message.getMember().getIdLong(), message.getGuild().getIdLong(), message.getChannel().getIdLong());
|
||||
newSpan.end();
|
||||
return DefaultListenerResult.IGNORED;
|
||||
}
|
||||
|
||||
Long serverId = model.getServerId();
|
||||
Optional<ProfanityRegex> potentialProfanityGroup = profanityService.getProfanityRegex(message.getContentRaw(), serverId);
|
||||
if(potentialProfanityGroup.isPresent()) {
|
||||
ProfanityRegex foundProfanityGroup = potentialProfanityGroup.get();
|
||||
profanityFilterServiceBean.handleProfaneMessage(message, foundProfanityGroup);
|
||||
return DefaultListenerResult.PROCESSED;
|
||||
Long serverId = model.getServerId();
|
||||
Optional<ProfanityRegex> potentialProfanityGroup = profanityService.getProfanityRegex(message.getContentRaw(), serverId);
|
||||
if (potentialProfanityGroup.isPresent()) {
|
||||
ProfanityRegex foundProfanityGroup = potentialProfanityGroup.get();
|
||||
profanityFilterServiceBean.handleProfaneMessage(message, foundProfanityGroup).whenComplete((unused, throwable) -> {
|
||||
newSpan.end();
|
||||
});
|
||||
return DefaultListenerResult.PROCESSED;
|
||||
}
|
||||
}
|
||||
return DefaultListenerResult.IGNORED;
|
||||
}
|
||||
|
||||
@@ -238,22 +238,23 @@ public class ProfanityFilterServiceBean implements ProfanityFilterService {
|
||||
return roleImmunityService.isImmune(member, PROFANITY_FILTER_EFFECT_KEY);
|
||||
}
|
||||
|
||||
public void handleProfaneMessage(Message message, ProfanityRegex foundProfanityGroup) {
|
||||
public CompletableFuture<Void> handleProfaneMessage(Message message, ProfanityRegex foundProfanityGroup) {
|
||||
metricService.incrementCounter(PROFANITIES_DETECTED_METRIC);
|
||||
if(featureModeService.featureModeActive(ProfanityFilterFeatureDefinition.PROFANITY_FILTER, message.getGuild().getIdLong(), ProfanityFilterMode.PROFANITY_REPORT)) {
|
||||
createProfanityReport(message, foundProfanityGroup).exceptionally(throwable -> {
|
||||
return createProfanityReport(message, foundProfanityGroup).exceptionally(throwable -> {
|
||||
log.error("Failed to report or persist profanities in server {} for message {} in channel {}.",
|
||||
message.getGuild().getIdLong(), message.getChannel().getIdLong(), message.getIdLong(), throwable);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
if(featureModeService.featureModeActive(ProfanityFilterFeatureDefinition.PROFANITY_FILTER, message.getGuild().getIdLong(), ProfanityFilterMode.AUTO_DELETE_PROFANITIES)) {
|
||||
messageService.deleteMessage(message).exceptionally(throwable -> {
|
||||
return messageService.deleteMessage(message).exceptionally(throwable -> {
|
||||
log.error("Failed to delete profanity message with id {} in channel {} in server {}.",
|
||||
message.getIdLong(), message.getChannel().getIdLong(), message.getGuild().getIdLong(), throwable);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>profanity-filter</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>remind</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>remind</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>repost-detection</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>repost-detection</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>starboard</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.models.database.PostTarget;
|
||||
import dev.sheldan.abstracto.core.models.property.SystemConfigProperty;
|
||||
import dev.sheldan.abstracto.core.models.template.display.MemberDisplay;
|
||||
import dev.sheldan.abstracto.core.models.template.display.UserDisplay;
|
||||
import dev.sheldan.abstracto.core.service.*;
|
||||
import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
|
||||
import dev.sheldan.abstracto.core.service.management.DefaultConfigManagementService;
|
||||
@@ -148,22 +150,43 @@ public class StarboardServiceBean implements StarboardService {
|
||||
|
||||
|
||||
private CompletableFuture<StarboardPostModel> buildStarboardPostModel(CachedMessage message, Integer starCount) {
|
||||
return userService.retrieveUserForId(message.getAuthor().getAuthorId())
|
||||
.thenApply(user -> createStarboardModel(message, starCount, user))
|
||||
CompletableFuture<User> userFuture = userService.retrieveUserForId(message.getAuthor().getAuthorId());
|
||||
CompletableFuture<Member> memberFuture = memberService.retrieveMemberInServer(message.getAuthorAsServerUser());
|
||||
CompletableFuture<StarboardPostModel> returnedFuture = new CompletableFuture<>();
|
||||
FutureUtils.toSingleFuture(List.of(userFuture, memberFuture))
|
||||
.whenComplete((any, error) -> {
|
||||
User user = null;
|
||||
if(!userFuture.isCompletedExceptionally()) {
|
||||
user = userFuture.join();
|
||||
} else {
|
||||
log.warn("Failed to retrieve user for author {} of starboard post.", message.getAuthor().getAuthorId());
|
||||
}
|
||||
Member member = null;
|
||||
if(!memberFuture.isCompletedExceptionally()) {
|
||||
member = memberFuture.join();
|
||||
} else {
|
||||
log.warn("Failed to retrieve user for author {} of starboard post.", message.getAuthor().getAuthorId());
|
||||
}
|
||||
StarboardPostModel starboardModel = createStarboardModel(message, starCount, user, member);
|
||||
returnedFuture.complete(starboardModel);
|
||||
})
|
||||
.exceptionally(throwable -> {
|
||||
log.warn("Failed to retrieve user for author {} of starboard post.", message.getAuthor().getAuthorId(), throwable);
|
||||
return createStarboardModel(message, starCount, null);
|
||||
log.warn("Complete failure when handling creation starboard post of message {}.", message.getMessageId(), throwable);
|
||||
returnedFuture.completeExceptionally(throwable);
|
||||
return null;
|
||||
});
|
||||
return returnedFuture;
|
||||
}
|
||||
|
||||
private StarboardPostModel createStarboardModel(CachedMessage message, Integer starCount, net.dv8tion.jda.api.entities.User user) {
|
||||
private StarboardPostModel createStarboardModel(CachedMessage message, Integer starCount, net.dv8tion.jda.api.entities.User user, Member member) {
|
||||
Optional<GuildMessageChannel> channel = channelService.getMessageChannelFromServerOptional(message.getServerId(), message.getChannelId());
|
||||
Optional<Guild> guild = guildService.getGuildByIdOptional(message.getServerId());
|
||||
String starLevelEmote = getAppropriateEmote(message.getServerId(), starCount);
|
||||
return StarboardPostModel
|
||||
.builder()
|
||||
.message(message)
|
||||
.author(user)
|
||||
.authorUser(user != null ? UserDisplay.fromUser(user) : null)
|
||||
.authorMember(member != null ? MemberDisplay.fromMember(member) : null)
|
||||
.sourceChannelId(message.getChannelId())
|
||||
.channel(channel.orElse(null))
|
||||
.starCount(starCount)
|
||||
@@ -214,7 +237,7 @@ public class StarboardServiceBean implements StarboardService {
|
||||
int count = 3;
|
||||
List<CompletableFuture<StarStatsUser>> topStarGiverFutures = starboardPostReactorManagementService.retrieveTopStarGiver(serverId, count);
|
||||
List<CompletableFuture<StarStatsUser>> topStarReceiverFutures = starboardPostReactorManagementService.retrieveTopStarReceiver(serverId, count);
|
||||
List<CompletableFuture> allFutures = new ArrayList<>();
|
||||
List<CompletableFuture<?>> allFutures = new ArrayList<>();
|
||||
allFutures.addAll(topStarGiverFutures);
|
||||
allFutures.addAll(topStarReceiverFutures);
|
||||
return FutureUtils.toSingleFuture(allFutures).thenApply(aVoid -> {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>starboard</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -2,17 +2,19 @@ package dev.sheldan.abstracto.starboard.model.template;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.cache.CachedMessage;
|
||||
import dev.sheldan.abstracto.core.models.context.ServerContext;
|
||||
import dev.sheldan.abstracto.core.models.template.display.MemberDisplay;
|
||||
import dev.sheldan.abstracto.core.models.template.display.UserDisplay;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@SuperBuilder
|
||||
public class StarboardPostModel extends ServerContext {
|
||||
private User author;
|
||||
private UserDisplay authorUser;
|
||||
private MemberDisplay authorMember;
|
||||
private GuildMessageChannel channel;
|
||||
private Long sourceChannelId;
|
||||
private CachedMessage message;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>statistic</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ import dev.sheldan.abstracto.core.service.GuildService;
|
||||
import dev.sheldan.abstracto.statistic.config.StatisticFeatureDefinition;
|
||||
import dev.sheldan.abstracto.statistic.emote.model.database.UsedEmoteType;
|
||||
import dev.sheldan.abstracto.statistic.emote.service.TrackedEmoteService;
|
||||
import io.micrometer.tracing.Span;
|
||||
import io.micrometer.tracing.Tracer;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -30,13 +32,13 @@ public class EmoteTrackingListener implements AsyncMessageReceivedListener {
|
||||
@Autowired
|
||||
private GuildService guildService;
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return StatisticFeatureDefinition.EMOTE_TRACKING;
|
||||
}
|
||||
@Autowired
|
||||
private Tracer tracer;
|
||||
|
||||
@Override
|
||||
public DefaultListenerResult execute(MessageReceivedModel model) {
|
||||
Span newSpan = tracer.nextSpan().name("experience-tracker");
|
||||
try (Tracer.SpanInScope ws = this.tracer.withSpan(newSpan.start())) {
|
||||
Message message = model.getMessage();
|
||||
if(!message.isFromGuild() || message.isWebhookMessage() || message.getType().isSystem()) {
|
||||
return DefaultListenerResult.IGNORED;
|
||||
@@ -50,5 +52,15 @@ public class EmoteTrackingListener implements AsyncMessageReceivedListener {
|
||||
trackedEmoteService.addEmoteToRuntimeStorage(groupedEmotes.get(0), guildService.getGuildById(model.getServerId()), (long) groupedEmotes.size(), UsedEmoteType.MESSAGE)
|
||||
);
|
||||
return DefaultListenerResult.PROCESSED;
|
||||
} finally {
|
||||
newSpan.end();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return StatisticFeatureDefinition.EMOTE_TRACKING;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>statistic</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>sticky-roles</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>sticky-roles-impl</artifactId>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>sticky-roles</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>sticky-roles-int</artifactId>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>suggestion</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>suggestion</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>twitch</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>twitch</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>utility</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>utility</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>voice-channel-context</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>voice-channel-context</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>webservices</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>webservices</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto</groupId>
|
||||
<artifactId>abstracto-application</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.core</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<version>1.6.16</version>
|
||||
<version>1.6.17-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
@@ -426,7 +426,7 @@ public class CommandReceivedHandler extends ListenerAdapter {
|
||||
Parameter param = parameters.get(0);
|
||||
CommandParameterIterators iterators = new CommandParameterIterators(channelIterator, emoteIterator, memberIterator, roleIterator);
|
||||
Set<CommandParameterHandler> usedParameterHandler = findNecessaryCommandParameterHandlers(parameters, unParsedCommandParameter);
|
||||
List<CompletableFuture> futures = new ArrayList<>();
|
||||
List<CompletableFuture<?>> futures = new ArrayList<>();
|
||||
// the actual parameters which were handled, might not coincide with the unparsed parameters
|
||||
// because we might ignore some parameters (for example referenced messages) in case the command does not use this as a parameter
|
||||
int parsedParameter = 0;
|
||||
@@ -443,7 +443,7 @@ public class CommandReceivedHandler extends ListenerAdapter {
|
||||
.getDependentFeatures()
|
||||
.stream()
|
||||
.map(s -> featureConfigService.getFeatureEnum(s))
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
boolean parameterActiveForFeatures = false;
|
||||
for (FeatureDefinition featureDefinition : featureDefinitions) {
|
||||
if(featureFlagService.getFeatureFlagValue(featureDefinition, message.getGuild().getIdLong())) {
|
||||
@@ -460,7 +460,7 @@ public class CommandReceivedHandler extends ListenerAdapter {
|
||||
try {
|
||||
if (handler.handles(param.getType(), value)) {
|
||||
if (handler.async()) {
|
||||
CompletableFuture future = handler.handleAsync(value, iterators, param, message, command);
|
||||
CompletableFuture<?> future = handler.handleAsync(value, iterators, param, message, command);
|
||||
futures.add(future);
|
||||
parsedParameters.add(ParseResult.builder().parameter(param).result(future).build());
|
||||
} else {
|
||||
@@ -488,11 +488,11 @@ public class CommandReceivedHandler extends ListenerAdapter {
|
||||
combinedFuture.thenAccept(aVoid -> {
|
||||
List<Object> allParamResults = parsedParameters.stream().map(o -> {
|
||||
if (o.getResult() instanceof CompletableFuture) {
|
||||
return ((CompletableFuture) o.getResult()).join();
|
||||
return ((CompletableFuture<?>) o.getResult()).join();
|
||||
} else {
|
||||
return o.getResult();
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
}).toList();
|
||||
List<ParseResult> parseResults = new ArrayList<>();
|
||||
for (int i = 0; i < allParamResults.size(); i++) {
|
||||
if (allParamResults.get(i) != null) {
|
||||
|
||||
@@ -207,4 +207,9 @@ public class ListenerExecutorConfig {
|
||||
return executorService.setupExecutorFor("voiceChatLeftListener");
|
||||
}
|
||||
|
||||
@Bean(name = "genericExecutor")
|
||||
public TaskExecutor genericExecutor() {
|
||||
return executorService.setupExecutorFor("genericExecutor");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ import dev.sheldan.abstracto.core.templating.model.AttachedFile;
|
||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
||||
import dev.sheldan.abstracto.core.utils.ContextUtils;
|
||||
import io.micrometer.tracing.Span;
|
||||
import io.micrometer.tracing.Tracer;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||
@@ -58,6 +60,9 @@ public class InteractionServiceBean implements InteractionService {
|
||||
@Autowired
|
||||
private TemplateService templateService;
|
||||
|
||||
@Autowired
|
||||
private Tracer tracer;
|
||||
|
||||
public static final CounterMetric EPHEMERAL_MESSAGES_SEND = CounterMetric
|
||||
.builder()
|
||||
.name(DISCORD_API_INTERACTION_METRIC)
|
||||
@@ -259,84 +264,88 @@ public class InteractionServiceBean implements InteractionService {
|
||||
}
|
||||
|
||||
public CompletableFuture<InteractionHook> replyMessageToSend(MessageToSend messageToSend, IReplyCallback callback) {
|
||||
ReplyCallbackAction action = null;
|
||||
if(messageToSend.getUseComponentsV2()) {
|
||||
action = callback.replyComponents(messageToSend.getComponents()).useComponentsV2();
|
||||
} else {
|
||||
if(messageToSend.getMessages() != null && !messageToSend.getMessages().isEmpty()) {
|
||||
metricService.incrementCounter(MESSAGE_SEND_METRIC);
|
||||
action = callback.reply(messageToSend.getMessages().get(0));
|
||||
}
|
||||
if(messageToSend.getEmbeds() != null && !messageToSend.getEmbeds().isEmpty()) {
|
||||
if(action != null) {
|
||||
action = action.addEmbeds(messageToSend.getEmbeds().subList(0, Math.min(10, messageToSend.getEmbeds().size())));
|
||||
} else {
|
||||
action = callback.replyEmbeds(messageToSend.getEmbeds());
|
||||
}
|
||||
}
|
||||
if(messageToSend.hasFilesToSend()) {
|
||||
List<FileUpload> attachedFiles = messageToSend
|
||||
.getAttachedFiles()
|
||||
.stream()
|
||||
.map(AttachedFile::convertToFileUpload)
|
||||
.collect(Collectors.toList());
|
||||
if(action != null) {
|
||||
action.setFiles(attachedFiles);
|
||||
} else {
|
||||
Span newSpan = tracer.nextSpan().name("send-message-to-interaction");
|
||||
try (Tracer.SpanInScope ws = this.tracer.withSpan(newSpan.start())) {
|
||||
ReplyCallbackAction action = null;
|
||||
if (messageToSend.getUseComponentsV2()) {
|
||||
action = callback.replyComponents(messageToSend.getComponents()).useComponentsV2();
|
||||
} else {
|
||||
if (messageToSend.getMessages() != null && !messageToSend.getMessages().isEmpty()) {
|
||||
metricService.incrementCounter(MESSAGE_SEND_METRIC);
|
||||
action = callback.replyFiles(attachedFiles);
|
||||
action = callback.reply(messageToSend.getMessages().get(0));
|
||||
}
|
||||
}
|
||||
// this should be last, because we are "faking" a message, by inserting a ., in case there has not been a reply yet
|
||||
// we could also throw an exception, but we are allowing this to go through
|
||||
List<ActionRow> actionRows = messageToSend.getActionRows();
|
||||
if(actionRows != null && !actionRows.isEmpty()) {
|
||||
if(action == null) {
|
||||
action = callback.reply(".");
|
||||
}
|
||||
action = action.setComponents(actionRows);
|
||||
AServer server;
|
||||
if(ContextUtils.isGuildKnown(callback)) {
|
||||
server = serverManagementService.loadServer(callback.getGuild().getIdLong());
|
||||
} else {
|
||||
server = null;
|
||||
}
|
||||
actionRows.forEach(components -> components.forEach(component -> {
|
||||
if(component instanceof ActionComponent) {
|
||||
String id = ((ActionComponent)component).getId();
|
||||
MessageToSend.ComponentConfig payload = messageToSend.getComponentPayloads().get(id);
|
||||
if(payload != null && payload.getPersistCallback()) {
|
||||
componentPayloadManagementService.createPayload(id, payload.getPayload(), payload.getPayloadType(), payload.getComponentOrigin(), server, payload.getComponentType());
|
||||
}
|
||||
if (messageToSend.getEmbeds() != null && !messageToSend.getEmbeds().isEmpty()) {
|
||||
if (action != null) {
|
||||
action = action.addEmbeds(messageToSend.getEmbeds().subList(0, Math.min(10, messageToSend.getEmbeds().size())));
|
||||
} else {
|
||||
action = callback.replyEmbeds(messageToSend.getEmbeds());
|
||||
}
|
||||
}));
|
||||
}
|
||||
if (messageToSend.hasFilesToSend()) {
|
||||
List<FileUpload> attachedFiles = messageToSend
|
||||
.getAttachedFiles()
|
||||
.stream()
|
||||
.map(AttachedFile::convertToFileUpload)
|
||||
.collect(Collectors.toList());
|
||||
if (action != null) {
|
||||
action.setFiles(attachedFiles);
|
||||
} else {
|
||||
metricService.incrementCounter(MESSAGE_SEND_METRIC);
|
||||
action = callback.replyFiles(attachedFiles);
|
||||
}
|
||||
}
|
||||
// this should be last, because we are "faking" a message, by inserting a ., in case there has not been a reply yet
|
||||
// we could also throw an exception, but we are allowing this to go through
|
||||
List<ActionRow> actionRows = messageToSend.getActionRows();
|
||||
if (actionRows != null && !actionRows.isEmpty()) {
|
||||
if (action == null) {
|
||||
action = callback.reply(".");
|
||||
}
|
||||
action = action.setComponents(actionRows);
|
||||
AServer server;
|
||||
if (ContextUtils.isGuildKnown(callback)) {
|
||||
server = serverManagementService.loadServer(callback.getGuild().getIdLong());
|
||||
} else {
|
||||
server = null;
|
||||
}
|
||||
actionRows.forEach(components -> components.forEach(component -> {
|
||||
if (component instanceof ActionComponent) {
|
||||
String id = ((ActionComponent) component).getId();
|
||||
MessageToSend.ComponentConfig payload = messageToSend.getComponentPayloads().get(id);
|
||||
if (payload != null && payload.getPersistCallback()) {
|
||||
componentPayloadManagementService.createPayload(id, payload.getPayload(), payload.getPayloadType(),
|
||||
payload.getComponentOrigin(), server, payload.getComponentType());
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(messageToSend.getEphemeral()) {
|
||||
if(ContextUtils.hasGuild(callback)) {
|
||||
log.info("Sending ephemeral message to interaction in guild {} in channel {} for user {}.",
|
||||
if (messageToSend.getEphemeral()) {
|
||||
if (ContextUtils.hasGuild(callback)) {
|
||||
log.info("Sending ephemeral message to interaction in guild {} in channel {} for user {}.",
|
||||
callback.getGuild().getIdLong(), callback.getChannel().getId(),
|
||||
callback.getUser().getIdLong());
|
||||
} else {
|
||||
log.info("Sending ephemeral message to user {}.", callback.getUser().getIdLong());
|
||||
} else {
|
||||
log.info("Sending ephemeral message to user {}.", callback.getUser().getIdLong());
|
||||
}
|
||||
metricService.incrementCounter(EPHEMERAL_MESSAGES_SEND);
|
||||
if (action != null) {
|
||||
action = action.setEphemeral(messageToSend.getEphemeral());
|
||||
}
|
||||
}
|
||||
metricService.incrementCounter(EPHEMERAL_MESSAGES_SEND);
|
||||
if(action != null) {
|
||||
action = action.setEphemeral(messageToSend.getEphemeral());
|
||||
if (ContextUtils.isGuildKnown(callback)) {
|
||||
Set<Message.MentionType> allowedMentions = allowedMentionService.getAllowedMentionsFor(callback.getMessageChannel(), messageToSend);
|
||||
if (action != null) {
|
||||
action = action.setAllowedMentions(allowedMentions);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(ContextUtils.isGuildKnown(callback)) {
|
||||
Set<Message.MentionType> allowedMentions = allowedMentionService.getAllowedMentionsFor(callback.getMessageChannel(), messageToSend);
|
||||
if (action != null) {
|
||||
action = action.setAllowedMentions(allowedMentions);
|
||||
}
|
||||
}
|
||||
|
||||
if(action == null) {
|
||||
throw new AbstractoRunTimeException("The callback did not result in any message.");
|
||||
if (action == null) {
|
||||
throw new AbstractoRunTimeException("The callback did not result in any message.");
|
||||
}
|
||||
return action.submit();
|
||||
}
|
||||
return action.submit();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.google.gson.Gson;
|
||||
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
||||
import dev.sheldan.abstracto.core.interaction.InteractionResult;
|
||||
import dev.sheldan.abstracto.core.interaction.button.ButtonPostInteractionExecution;
|
||||
import dev.sheldan.abstracto.core.metric.service.MetricUtils;
|
||||
import dev.sheldan.abstracto.core.models.database.ComponentPayload;
|
||||
import dev.sheldan.abstracto.core.interaction.button.ButtonPayload;
|
||||
import dev.sheldan.abstracto.core.service.FeatureConfigService;
|
||||
@@ -63,7 +64,7 @@ public class SyncButtonClickedListenerBean extends ListenerAdapter {
|
||||
@Override
|
||||
public void onButtonInteraction(@Nonnull ButtonInteractionEvent event) {
|
||||
if(listenerList == null) return;
|
||||
CompletableFuture.runAsync(() -> self.executeListenerLogic(event), buttonClickedExecutor).exceptionally(throwable -> {
|
||||
CompletableFuture.runAsync(() -> self.executeListenerLogic(event), MetricUtils.wrapExecutor(buttonClickedExecutor)).exceptionally(throwable -> {
|
||||
log.error("Failed to execute listener logic in async button event.", throwable);
|
||||
return null;
|
||||
});
|
||||
|
||||
@@ -7,6 +7,7 @@ import dev.sheldan.abstracto.core.interaction.context.message.listener.MessageCo
|
||||
import dev.sheldan.abstracto.core.metric.service.CounterMetric;
|
||||
import dev.sheldan.abstracto.core.metric.service.MetricService;
|
||||
import dev.sheldan.abstracto.core.metric.service.MetricTag;
|
||||
import dev.sheldan.abstracto.core.metric.service.MetricUtils;
|
||||
import dev.sheldan.abstracto.core.models.listener.interaction.MessageContextInteractionModel;
|
||||
import dev.sheldan.abstracto.core.service.FeatureConfigService;
|
||||
import dev.sheldan.abstracto.core.service.FeatureFlagService;
|
||||
@@ -65,7 +66,7 @@ public class MessageContextCommandListenerBean extends ListenerAdapter {
|
||||
@Override
|
||||
public void onMessageContextInteraction(MessageContextInteractionEvent event) {
|
||||
if(listenerList == null) return;
|
||||
CompletableFuture.runAsync(() -> self.executeListenerLogic(event), messageContextCommandExecutor).exceptionally(throwable -> {
|
||||
CompletableFuture.runAsync(() -> self.executeListenerLogic(event), MetricUtils.wrapExecutor(messageContextCommandExecutor)).exceptionally(throwable -> {
|
||||
log.error("Failed to execute listener logic in async message context event.", throwable);
|
||||
return null;
|
||||
});
|
||||
|
||||
@@ -3,9 +3,9 @@ package dev.sheldan.abstracto.core.interaction.menu;
|
||||
import com.google.gson.Gson;
|
||||
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
||||
import dev.sheldan.abstracto.core.interaction.ComponentPayloadManagementService;
|
||||
import dev.sheldan.abstracto.core.interaction.InteractionResult;
|
||||
import dev.sheldan.abstracto.core.interaction.menu.listener.StringSelectMenuListener;
|
||||
import dev.sheldan.abstracto.core.interaction.menu.listener.StringSelectMenuListenerModel;
|
||||
import dev.sheldan.abstracto.core.metric.service.MetricUtils;
|
||||
import dev.sheldan.abstracto.core.models.database.ComponentPayload;
|
||||
import dev.sheldan.abstracto.core.service.FeatureConfigService;
|
||||
import dev.sheldan.abstracto.core.service.FeatureFlagService;
|
||||
@@ -60,7 +60,7 @@ public class StringSelectMenuListenerBean extends ListenerAdapter {
|
||||
public void onStringSelectInteraction(@Nonnull StringSelectInteractionEvent event) {
|
||||
if(listenerList == null) return;
|
||||
event.deferEdit().queue();
|
||||
CompletableFuture.runAsync(() -> self.executeListenerLogic(event), buttonClickedExecutor).exceptionally(throwable -> {
|
||||
CompletableFuture.runAsync(() -> self.executeListenerLogic(event), MetricUtils.wrapExecutor(buttonClickedExecutor)).exceptionally(throwable -> {
|
||||
log.error("Failed to execute listener logic in async button event.", throwable);
|
||||
return null;
|
||||
});
|
||||
|
||||
@@ -6,6 +6,7 @@ import dev.sheldan.abstracto.core.interaction.ComponentPayloadManagementService;
|
||||
import dev.sheldan.abstracto.core.interaction.InteractionResult;
|
||||
import dev.sheldan.abstracto.core.interaction.modal.ModalPayload;
|
||||
import dev.sheldan.abstracto.core.interaction.modal.ModalPostInteractionExecution;
|
||||
import dev.sheldan.abstracto.core.metric.service.MetricUtils;
|
||||
import dev.sheldan.abstracto.core.models.database.ComponentPayload;
|
||||
import dev.sheldan.abstracto.core.service.FeatureConfigService;
|
||||
import dev.sheldan.abstracto.core.service.FeatureFlagService;
|
||||
@@ -62,7 +63,7 @@ public class ModalInteractionListenerBean extends ListenerAdapter {
|
||||
@Override
|
||||
public void onModalInteraction(@Nonnull ModalInteractionEvent event) {
|
||||
if(listenerList == null) return;
|
||||
CompletableFuture.runAsync(() -> self.executeListenerLogic(event), modalInteractionExecutor).exceptionally(throwable -> {
|
||||
CompletableFuture.runAsync(() -> self.executeListenerLogic(event), MetricUtils.wrapExecutor(modalInteractionExecutor)).exceptionally(throwable -> {
|
||||
log.error("Failed to execute listener logic in modal interaction event.", throwable);
|
||||
return null;
|
||||
});
|
||||
|
||||
@@ -19,18 +19,31 @@ import dev.sheldan.abstracto.core.interaction.slash.payload.SlashCommandConfirma
|
||||
import dev.sheldan.abstracto.core.metric.service.CounterMetric;
|
||||
import dev.sheldan.abstracto.core.metric.service.MetricService;
|
||||
import dev.sheldan.abstracto.core.metric.service.MetricTag;
|
||||
import dev.sheldan.abstracto.core.metric.service.MetricUtils;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.ConfigService;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import dev.sheldan.abstracto.core.utils.ContextUtils;
|
||||
import dev.sheldan.abstracto.scheduling.model.JobParameters;
|
||||
import dev.sheldan.abstracto.scheduling.service.SchedulerService;
|
||||
import io.micrometer.observation.Observation;
|
||||
import io.micrometer.observation.ObservationRegistry;
|
||||
import io.micrometer.tracing.Span;
|
||||
import io.micrometer.tracing.Tracer;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import dev.sheldan.abstracto.core.utils.ContextUtils;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.PostConstruct;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||
@@ -45,15 +58,6 @@ import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class SlashCommandListenerBean extends ListenerAdapter {
|
||||
@@ -100,6 +104,12 @@ public class SlashCommandListenerBean extends ListenerAdapter {
|
||||
@Autowired
|
||||
private SchedulerService schedulerService;
|
||||
|
||||
@Autowired
|
||||
private ObservationRegistry observationRegistry;
|
||||
|
||||
@Autowired
|
||||
private Tracer tracer;
|
||||
|
||||
@Autowired
|
||||
private ComponentPayloadManagementService componentPayloadManagementService;
|
||||
|
||||
@@ -107,48 +117,66 @@ public class SlashCommandListenerBean extends ListenerAdapter {
|
||||
public static final String SLASH_COMMAND_CONFIRMATION_ORIGIN = "SLASH_COMMAND_CONFIRMATION";
|
||||
|
||||
public static final CounterMetric SLASH_COMMANDS_PROCESSED_COUNTER = CounterMetric
|
||||
.builder()
|
||||
.name(CommandReceivedHandler.COMMAND_PROCESSED)
|
||||
.tagList(Arrays.asList(MetricTag.getTag(CommandReceivedHandler.STATUS_TAG, "processed"), MetricTag.getTag(CommandReceivedHandler.TYPE_TAG, "slash")))
|
||||
.build();
|
||||
.builder()
|
||||
.name(CommandReceivedHandler.COMMAND_PROCESSED)
|
||||
.tagList(Arrays.asList(MetricTag.getTag(CommandReceivedHandler.STATUS_TAG, "processed"), MetricTag.getTag(CommandReceivedHandler.TYPE_TAG, "slash")))
|
||||
.build();
|
||||
|
||||
public List<Command> getSlashCommands() {
|
||||
if(commands == null || commands.isEmpty()) {
|
||||
if (commands == null || commands.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return commands.stream()
|
||||
.filter(command -> command.getConfiguration()
|
||||
.getSlashCommandConfig().isEnabled())
|
||||
.collect(Collectors.toList());
|
||||
.filter(command -> command.getConfiguration()
|
||||
.getSlashCommandConfig().isEnabled())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlashCommandInteraction(SlashCommandInteractionEvent event) {
|
||||
try {
|
||||
if(commands == null || commands.isEmpty()) return;
|
||||
if(ContextUtils.hasGuild(event.getInteraction())) {
|
||||
log.debug("Executing slash command in guild {} from user {}.", event.getGuild().getIdLong(), event.getUser().getIdLong());
|
||||
} else {
|
||||
log.debug("Executing slash command by user {}", event.getUser().getIdLong());
|
||||
Observation observation = Observation.createNotStarted("slash-command-received", this.observationRegistry);
|
||||
observation.observe(() -> {
|
||||
try {
|
||||
if (commands == null || commands.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (ContextUtils.hasGuild(event.getInteraction())) {
|
||||
log.debug("Executing slash command in guild {} from user {}.", event.getGuild().getIdLong(), event.getUser().getIdLong());
|
||||
} else {
|
||||
log.debug("Executing slash command by user {}", event.getUser().getIdLong());
|
||||
}
|
||||
Span span = tracer.currentSpan();
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try (Tracer.SpanInScope ws = tracer.withSpan(span)) {
|
||||
self.executeListenerLogic(event).whenComplete((unused, throwable) -> {
|
||||
span.end();
|
||||
});
|
||||
}
|
||||
|
||||
}, slashCommandExecutor).exceptionally(throwable -> {
|
||||
log.error("Failed to execute listener logic in async slash command event.", throwable);
|
||||
return null;
|
||||
});
|
||||
} catch (Exception exception) {
|
||||
log.error("Failed to process slash command interaction event.", exception);
|
||||
}
|
||||
CompletableFuture.runAsync(() -> self.executeListenerLogic(event), slashCommandExecutor).exceptionally(throwable -> {
|
||||
log.error("Failed to execute listener logic in async slash command event.", throwable);
|
||||
return null;
|
||||
});
|
||||
} catch (Exception exception) {
|
||||
log.error("Failed to process slash command interaction event.", exception);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
public void executeListenerLogic(SlashCommandInteractionEvent event) {
|
||||
public CompletableFuture<Void> executeListenerLogic(SlashCommandInteractionEvent event) {
|
||||
Optional<Command> potentialCommand = findCommand(event);
|
||||
potentialCommand.ifPresent(command -> {
|
||||
if (potentialCommand.isPresent()) {
|
||||
Command command = potentialCommand.get();
|
||||
metricService.incrementCounter(SLASH_COMMANDS_PROCESSED_COUNTER);
|
||||
try {
|
||||
commandService.isCommandExecutable(command, event).thenAccept(conditionResult -> {
|
||||
self.executeCommand(event, command, conditionResult);
|
||||
Span span = tracer.currentSpan();
|
||||
span.tag("command-name", command.getConfiguration().getName());
|
||||
return commandService.isCommandExecutable(command, event).thenCompose(conditionResult -> {
|
||||
try (Tracer.SpanInScope ws = tracer.withSpan(span)) {
|
||||
return self.executeCommand(event, command, conditionResult);
|
||||
}
|
||||
}).exceptionally(throwable -> {
|
||||
log.error("Error while executing command {}", command.getConfiguration().getName(), throwable);
|
||||
CommandResult commandResult = CommandResult.fromError(throwable.getMessage(), throwable);
|
||||
@@ -159,18 +187,24 @@ public class SlashCommandListenerBean extends ListenerAdapter {
|
||||
log.error("Error while checking if command {} is executable.", command.getConfiguration().getName(), exception);
|
||||
CommandResult commandResult = CommandResult.fromError(exception.getMessage(), exception);
|
||||
self.executePostCommandListener(command, event, commandResult);
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommandAutoCompleteInteraction(@Nonnull CommandAutoCompleteInteractionEvent event) {
|
||||
try {
|
||||
if(commands == null || commands.isEmpty()) return;
|
||||
CompletableFuture.runAsync(() -> self.executeAutCompleteListenerLogic(event), slashCommandAutoCompleteExecutor).exceptionally(throwable -> {
|
||||
log.error("Failed to execute listener logic in async auto complete interaction event.", throwable);
|
||||
return null;
|
||||
});
|
||||
if (commands == null || commands.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
CompletableFuture.runAsync(() -> self.executeAutCompleteListenerLogic(event), MetricUtils.wrapExecutor(slashCommandAutoCompleteExecutor))
|
||||
.exceptionally(throwable -> {
|
||||
log.error("Failed to execute listener logic in async auto complete interaction event.", throwable);
|
||||
return null;
|
||||
});
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to process slash command auto complete interaction.", e);
|
||||
}
|
||||
@@ -183,15 +217,17 @@ public class SlashCommandListenerBean extends ListenerAdapter {
|
||||
try {
|
||||
List<String> fullRepliesList = command.performAutoComplete(event);
|
||||
List<String> replies = fullRepliesList.subList(0, Math.min(fullRepliesList.size(), OptionData.MAX_CHOICES));
|
||||
event.replyChoiceStrings(replies).queue(unused -> {},
|
||||
throwable -> {
|
||||
if(ContextUtils.hasGuild(event)) {
|
||||
log.error("Failed to respond to complete of command {} in guild {} by user {}.",
|
||||
command.getConfiguration().getName(), event.getGuild().getIdLong(), event.getUser().getIdLong());
|
||||
} else {
|
||||
log.error("Failed to resp ond to complete of command {} for user {}.", command.getConfiguration().getName(), event.getUser().getIdLong());
|
||||
}
|
||||
});
|
||||
event.replyChoiceStrings(replies).queue(unused -> {
|
||||
},
|
||||
throwable -> {
|
||||
if (ContextUtils.hasGuild(event)) {
|
||||
log.error("Failed to respond to complete of command {} in guild {} by user {}.",
|
||||
command.getConfiguration().getName(), event.getGuild().getIdLong(), event.getUser().getIdLong());
|
||||
} else {
|
||||
log.error("Failed to resp ond to complete of command {} for user {}.", command.getConfiguration().getName(),
|
||||
event.getUser().getIdLong());
|
||||
}
|
||||
});
|
||||
} catch (Exception exception) {
|
||||
log.error("Error while executing autocomplete of command {}.", command.getConfiguration().getName(), exception);
|
||||
}
|
||||
@@ -199,8 +235,9 @@ public class SlashCommandListenerBean extends ListenerAdapter {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void continueSlashCommand(Long interactionId, ButtonInteractionEvent buttonInteractionEvent, SlashCommandConfirmationPayload slashCommandConfirmationPayload) {
|
||||
if(COMMANDS_WAITING_FOR_CONFIRMATION.containsKey(interactionId)) {
|
||||
public void continueSlashCommand(Long interactionId, ButtonInteractionEvent buttonInteractionEvent,
|
||||
SlashCommandConfirmationPayload slashCommandConfirmationPayload) {
|
||||
if (COMMANDS_WAITING_FOR_CONFIRMATION.containsKey(interactionId)) {
|
||||
DriedSlashCommand driedSlashCommand = COMMANDS_WAITING_FOR_CONFIRMATION.get(interactionId);
|
||||
Command commandInstance = driedSlashCommand.getCommand();
|
||||
String commandName = commandInstance.getConfiguration().getName();
|
||||
@@ -221,23 +258,28 @@ public class SlashCommandListenerBean extends ListenerAdapter {
|
||||
return null;
|
||||
});
|
||||
} else {
|
||||
log.warn("Interaction was not found in internal map - not continuing interaction from user {} in server {}.", buttonInteractionEvent.getUser().getIdLong(), buttonInteractionEvent.getGuild().getIdLong());
|
||||
log.warn("Interaction was not found in internal map - not continuing interaction from user {} in server {}.",
|
||||
buttonInteractionEvent.getUser().getIdLong(), buttonInteractionEvent.getGuild().getIdLong());
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void cleanupSlashCommandConfirmation(SlashCommandConfirmationPayload slashCommandConfirmationPayload, ButtonInteractionEvent buttonInteractionEvent) {
|
||||
log.debug("Cleaning up component {} and {}.", slashCommandConfirmationPayload.getConfirmationPayloadId(), slashCommandConfirmationPayload.getAbortPayloadId());
|
||||
componentPayloadManagementService.deletePayloads(Arrays.asList(slashCommandConfirmationPayload.getAbortPayloadId(), slashCommandConfirmationPayload.getConfirmationPayloadId()));
|
||||
public void cleanupSlashCommandConfirmation(SlashCommandConfirmationPayload slashCommandConfirmationPayload,
|
||||
ButtonInteractionEvent buttonInteractionEvent) {
|
||||
log.debug("Cleaning up component {} and {}.", slashCommandConfirmationPayload.getConfirmationPayloadId(),
|
||||
slashCommandConfirmationPayload.getAbortPayloadId());
|
||||
componentPayloadManagementService.deletePayloads(
|
||||
Arrays.asList(slashCommandConfirmationPayload.getAbortPayloadId(), slashCommandConfirmationPayload.getConfirmationPayloadId()));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void removeSlashCommandConfirmationInteraction(Long interactionId, String confirmationPayload, String abortPayload) {
|
||||
if(COMMANDS_WAITING_FOR_CONFIRMATION.containsKey(interactionId)) {
|
||||
if (COMMANDS_WAITING_FOR_CONFIRMATION.containsKey(interactionId)) {
|
||||
DriedSlashCommand removedSlashCommand = COMMANDS_WAITING_FOR_CONFIRMATION.remove(interactionId);
|
||||
SlashCommandInteractionEvent event = removedSlashCommand.getEvent();
|
||||
event.getInteraction().getHook().deleteOriginal().queue();
|
||||
log.info("Remove interaction for command {} in server {} from user {}.", removedSlashCommand.getCommand().getConfiguration().getName(), event.getGuild().getIdLong(), event.getUser().getIdLong());
|
||||
log.info("Remove interaction for command {} in server {} from user {}.", removedSlashCommand.getCommand().getConfiguration().getName(),
|
||||
event.getGuild().getIdLong(), event.getUser().getIdLong());
|
||||
} else {
|
||||
log.info("Did not find interaction to clean up.");
|
||||
}
|
||||
@@ -245,9 +287,9 @@ public class SlashCommandListenerBean extends ListenerAdapter {
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = AbstractoRunTimeException.class)
|
||||
public void executeCommand(SlashCommandInteractionEvent event, Command command, ConditionResult conditionResult) {
|
||||
public CompletableFuture<Void> executeCommand(SlashCommandInteractionEvent event, Command command, ConditionResult conditionResult) {
|
||||
String commandName = command.getConfiguration().getName();
|
||||
if(command.getConfiguration().isRequiresConfirmation() && conditionResult.isResult()) {
|
||||
if (command.getConfiguration().isRequiresConfirmation() && conditionResult.isResult()) {
|
||||
DriedSlashCommand slashCommand = DriedSlashCommand
|
||||
.builder()
|
||||
.command(command)
|
||||
@@ -281,19 +323,22 @@ public class SlashCommandListenerBean extends ListenerAdapter {
|
||||
.commandName(commandName)
|
||||
.build();
|
||||
Long userId = event.getUser().getIdLong();
|
||||
interactionService.replyEmbed(COMMAND_CONFIRMATION_MESSAGE_TEMPLATE_KEY, model, event).thenAccept(interactionHook -> {
|
||||
log.info("Sent confirmation for command {} in server {} for user {}.", commandName, serverId, userId);
|
||||
}).exceptionally(throwable -> {
|
||||
log.warn("Failed to send confirmation for command {} in server {} for user {}.", commandName, serverId, userId);
|
||||
return null;
|
||||
});
|
||||
CompletableFuture<Void> replyFuture =
|
||||
interactionService.replyEmbed(COMMAND_CONFIRMATION_MESSAGE_TEMPLATE_KEY, model, event).thenAccept(interactionHook -> {
|
||||
log.info("Sent confirmation for command {} in server {} for user {}.", commandName, serverId, userId);
|
||||
}).exceptionally(throwable -> {
|
||||
log.warn("Failed to send confirmation for command {} in server {} for user {}.", commandName, serverId, userId);
|
||||
return null;
|
||||
});
|
||||
scheduleConfirmationDeletion(event.getIdLong(), confirmationId, abortId, serverId);
|
||||
return replyFuture;
|
||||
} else {
|
||||
CompletableFuture<CommandResult> commandOutput;
|
||||
if(conditionResult.isResult()) {
|
||||
if (conditionResult.isResult()) {
|
||||
commandOutput = command.executeSlash(event).thenApply(commandResult -> {
|
||||
if(ContextUtils.hasGuild(event)) {
|
||||
log.info("Command {} in server {} was executed by user {}.", command.getConfiguration().getName(), event.getGuild().getIdLong(), event.getUser().getIdLong());
|
||||
if (ContextUtils.hasGuild(event)) {
|
||||
log.info("Command {} in server {} was executed by user {}.", command.getConfiguration().getName(), event.getGuild().getIdLong(),
|
||||
event.getUser().getIdLong());
|
||||
} else {
|
||||
log.info("Command {} was executed by user {}.", command.getConfiguration().getName(), event.getUser().getId());
|
||||
}
|
||||
@@ -302,7 +347,7 @@ public class SlashCommandListenerBean extends ListenerAdapter {
|
||||
} else {
|
||||
commandOutput = CompletableFuture.completedFuture(CommandResult.fromCondition(conditionResult));
|
||||
}
|
||||
commandOutput.thenAccept(commandResult -> {
|
||||
return commandOutput.thenAccept(commandResult -> {
|
||||
self.executePostCommandListener(command, event, commandResult);
|
||||
}).exceptionally(throwable -> {
|
||||
log.error("Error while handling post execution of command {}", commandName, throwable);
|
||||
@@ -337,26 +382,26 @@ public class SlashCommandListenerBean extends ListenerAdapter {
|
||||
|
||||
private Optional<Command> findCommand(SlashCommandInteractionEvent event) {
|
||||
return commands
|
||||
.stream()
|
||||
.filter(command -> command.getConfiguration().getSlashCommandConfig().isEnabled())
|
||||
.filter(command -> command.getConfiguration().getSlashCommandConfig().matchesInteraction(event.getInteraction()))
|
||||
.findAny();
|
||||
.stream()
|
||||
.filter(command -> command.getConfiguration().getSlashCommandConfig().isEnabled())
|
||||
.filter(command -> command.getConfiguration().getSlashCommandConfig().matchesInteraction(event.getInteraction()))
|
||||
.findAny();
|
||||
}
|
||||
|
||||
private Optional<Command> findCommand(CommandAutoCompleteInteractionEvent event) {
|
||||
return commands
|
||||
.stream()
|
||||
.filter(command -> command.getConfiguration().getSlashCommandConfig().isEnabled())
|
||||
.filter(command -> command.getConfiguration().getSlashCommandConfig().matchesInteraction(event.getInteraction()))
|
||||
.findAny();
|
||||
.stream()
|
||||
.filter(command -> command.getConfiguration().getSlashCommandConfig().isEnabled())
|
||||
.filter(command -> command.getConfiguration().getSlashCommandConfig().matchesInteraction(event.getInteraction()))
|
||||
.findAny();
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void filterPostProcessors() {
|
||||
metricService.registerCounter(SLASH_COMMANDS_PROCESSED_COUNTER, "Slash Commands processed");
|
||||
executions = executions
|
||||
.stream()
|
||||
.filter(PostCommandExecution::supportsSlash)
|
||||
.collect(Collectors.toList());
|
||||
.stream()
|
||||
.filter(PostCommandExecution::supportsSlash)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,9 @@ import dev.sheldan.abstracto.core.interactive.setup.callback.MessageInteractionC
|
||||
import dev.sheldan.abstracto.core.listener.DefaultListenerResult;
|
||||
import dev.sheldan.abstracto.core.listener.async.jda.AsyncMessageReceivedListener;
|
||||
import dev.sheldan.abstracto.core.models.listener.MessageReceivedModel;
|
||||
import io.micrometer.tracing.Span;
|
||||
import io.micrometer.tracing.Tracer;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -20,6 +23,9 @@ public class InteractiveMessageReceivedListener implements AsyncMessageReceivedL
|
||||
// TODO timeout
|
||||
private Map<Long, Map<Long, Map<Long, MessageInteractionCallback>>> callbacks = new HashMap<>();
|
||||
|
||||
@Autowired
|
||||
private Tracer tracer;
|
||||
|
||||
private static final Lock runTimeLock = new ReentrantLock();
|
||||
|
||||
@Override
|
||||
@@ -40,7 +46,8 @@ public class InteractiveMessageReceivedListener implements AsyncMessageReceivedL
|
||||
|
||||
public boolean executeCallback(MessageReceivedModel model) {
|
||||
runTimeLock.lock();
|
||||
try {
|
||||
Span newSpan = tracer.nextSpan().name("interactive-message-tracker");
|
||||
try (Tracer.SpanInScope ws = this.tracer.withSpan(newSpan.start())){
|
||||
if(callbacks.containsKey(model.getServerId())) {
|
||||
Map<Long, Map<Long, MessageInteractionCallback>> channelMap = callbacks.get(model.getServerId());
|
||||
if(channelMap.containsKey(model.getMessage().getChannel().getIdLong())) {
|
||||
@@ -56,6 +63,7 @@ public class InteractiveMessageReceivedListener implements AsyncMessageReceivedL
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
newSpan.end();
|
||||
runTimeLock.unlock();
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package dev.sheldan.abstracto.core.listener.async.jda;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.service.ExceptionService;
|
||||
import dev.sheldan.abstracto.core.listener.ListenerService;
|
||||
import dev.sheldan.abstracto.core.models.listener.MessageReceivedModel;
|
||||
import dev.sheldan.abstracto.core.service.BotService;
|
||||
import dev.sheldan.abstracto.core.service.FeatureConfigService;
|
||||
import dev.sheldan.abstracto.core.service.FeatureFlagService;
|
||||
import dev.sheldan.abstracto.core.service.MessageCache;
|
||||
import io.micrometer.observation.Observation;
|
||||
import io.micrometer.observation.ObservationRegistry;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
@@ -28,18 +26,6 @@ public class AsyncMessageReceivedListenerBean extends ListenerAdapter {
|
||||
@Autowired(required = false)
|
||||
private List<AsyncMessageReceivedListener> listenerList;
|
||||
|
||||
@Autowired
|
||||
private FeatureConfigService featureConfigService;
|
||||
|
||||
@Autowired
|
||||
private FeatureFlagService featureFlagService;
|
||||
|
||||
@Autowired
|
||||
private BotService botService;
|
||||
|
||||
@Autowired
|
||||
private ExceptionService exceptionService;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("messageReceivedExecutor")
|
||||
private TaskExecutor messageReceivedExecutor;
|
||||
@@ -47,14 +33,21 @@ public class AsyncMessageReceivedListenerBean extends ListenerAdapter {
|
||||
@Autowired
|
||||
private ListenerService listenerService;
|
||||
|
||||
@Autowired
|
||||
private ObservationRegistry observationRegistry;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void onMessageReceived(@Nonnull MessageReceivedEvent event) {
|
||||
if(listenerList == null) return;
|
||||
if(!event.isFromGuild()) return;
|
||||
messageCache.putMessageInCache(event.getMessage());
|
||||
MessageReceivedModel model = getModel(event);
|
||||
listenerList.forEach(leaveListener -> listenerService.executeFeatureAwareListener(leaveListener, model, messageReceivedExecutor));
|
||||
Observation observation = Observation.createNotStarted("async-message-received", this.observationRegistry);
|
||||
observation.lowCardinalityKeyValue("some-tag", "some-value");
|
||||
observation.observe(() -> {
|
||||
messageCache.putMessageInCache(event.getMessage());
|
||||
MessageReceivedModel model = getModel(event);
|
||||
listenerList.forEach(leaveListener -> listenerService.executeFeatureAwareListener(leaveListener, model, messageReceivedExecutor));
|
||||
});
|
||||
}
|
||||
|
||||
private MessageReceivedModel getModel(MessageReceivedEvent event) {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user