mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-01-01 15:28:35 +00:00
[AB-xxx] more instrumenting changes
This commit is contained in:
@@ -357,13 +357,15 @@ public class AUserExperienceServiceBean implements AUserExperienceService {
|
||||
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 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)) {
|
||||
&&
|
||||
featureModeService.featureModeActive(ExperienceFeatureDefinition.EXPERIENCE, serverId, ExperienceFeatureMode.LEVEL_UP_NOTIFICATION)) {
|
||||
LevelUpNotificationModel model = LevelUpNotificationModel
|
||||
.builder()
|
||||
.memberDisplay(MemberDisplay.fromMember(member))
|
||||
@@ -376,16 +378,19 @@ public class AUserExperienceServiceBean implements AUserExperienceService {
|
||||
.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());
|
||||
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());
|
||||
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)) {
|
||||
if (userChangesLevel &&
|
||||
featureModeService.featureModeActive(ExperienceFeatureDefinition.EXPERIENCE, server, ExperienceFeatureMode.LEVEL_ACTION)) {
|
||||
levelActionService.applyLevelActionsToUser(aUserExperience, oldLevel)
|
||||
.thenAccept(unused -> {
|
||||
log.info("Executed level actions for user {}.", userInServerId);
|
||||
@@ -401,17 +406,21 @@ public class AUserExperienceServiceBean implements AUserExperienceService {
|
||||
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());
|
||||
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);
|
||||
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());
|
||||
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);
|
||||
log.warn("Failed to remove role {} from member {} in server {}.", result.getOldRoleId(), member.getIdLong(),
|
||||
member.getGuild().getIdLong(), throwable);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
@@ -419,7 +428,8 @@ public class AUserExperienceServiceBean implements AUserExperienceService {
|
||||
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);
|
||||
log.warn("Failed to add role {} to member {} in server {}.", result.getOldRoleId(), member.getIdLong(),
|
||||
member.getGuild().getIdLong(), throwable);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
@@ -432,6 +442,7 @@ public class AUserExperienceServiceBean implements AUserExperienceService {
|
||||
newSpan.end();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean experienceGainEnabledInChannel(MessageChannel messageChannel) {
|
||||
|
||||
@@ -313,7 +313,8 @@ public class InteractionServiceBean implements InteractionService {
|
||||
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());
|
||||
componentPayloadManagementService.createPayload(id, payload.getPayload(), payload.getPayloadType(),
|
||||
payload.getComponentOrigin(), server, payload.getComponentType());
|
||||
}
|
||||
}
|
||||
}));
|
||||
@@ -346,7 +347,6 @@ public class InteractionServiceBean implements InteractionService {
|
||||
return action.submit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<InteractionHook> replyMessage(String templateKey, Object model, IReplyCallback callback) {
|
||||
|
||||
@@ -19,23 +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 java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import dev.sheldan.abstracto.core.utils.ContextUtils;
|
||||
import dev.sheldan.abstracto.core.metric.service.MetricUtils;
|
||||
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 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;
|
||||
@@ -50,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 {
|
||||
@@ -138,7 +137,9 @@ public class SlashCommandListenerBean extends ListenerAdapter {
|
||||
Observation observation = Observation.createNotStarted("slash-command-received", this.observationRegistry);
|
||||
observation.observe(() -> {
|
||||
try {
|
||||
if(commands == null || commands.isEmpty()) return;
|
||||
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 {
|
||||
@@ -158,6 +159,7 @@ public class SlashCommandListenerBean extends ListenerAdapter {
|
||||
});
|
||||
} catch (Exception exception) {
|
||||
log.error("Failed to process slash command interaction event.", exception);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -195,8 +197,11 @@ public class SlashCommandListenerBean extends ListenerAdapter {
|
||||
@Override
|
||||
public void onCommandAutoCompleteInteraction(@Nonnull CommandAutoCompleteInteractionEvent event) {
|
||||
try {
|
||||
if(commands == null || commands.isEmpty()) return;
|
||||
CompletableFuture.runAsync(() -> self.executeAutCompleteListenerLogic(event), MetricUtils.wrapExecutor(slashCommandAutoCompleteExecutor)).exceptionally(throwable -> {
|
||||
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;
|
||||
});
|
||||
@@ -212,13 +217,15 @@ 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 -> {},
|
||||
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());
|
||||
log.error("Failed to resp ond to complete of command {} for user {}.", command.getConfiguration().getName(),
|
||||
event.getUser().getIdLong());
|
||||
}
|
||||
});
|
||||
} catch (Exception exception) {
|
||||
@@ -228,7 +235,8 @@ public class SlashCommandListenerBean extends ListenerAdapter {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void continueSlashCommand(Long interactionId, ButtonInteractionEvent buttonInteractionEvent, SlashCommandConfirmationPayload slashCommandConfirmationPayload) {
|
||||
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();
|
||||
@@ -250,14 +258,18 @@ 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
|
||||
@@ -266,7 +278,8 @@ public class SlashCommandListenerBean extends ListenerAdapter {
|
||||
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.");
|
||||
}
|
||||
@@ -274,7 +287,7 @@ 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()) {
|
||||
DriedSlashCommand slashCommand = DriedSlashCommand
|
||||
@@ -310,6 +323,7 @@ public class SlashCommandListenerBean extends ListenerAdapter {
|
||||
.commandName(commandName)
|
||||
.build();
|
||||
Long userId = event.getUser().getIdLong();
|
||||
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 -> {
|
||||
@@ -317,12 +331,14 @@ public class SlashCommandListenerBean extends ListenerAdapter {
|
||||
return null;
|
||||
});
|
||||
scheduleConfirmationDeletion(event.getIdLong(), confirmationId, abortId, serverId);
|
||||
return replyFuture;
|
||||
} else {
|
||||
CompletableFuture<CommandResult> commandOutput;
|
||||
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());
|
||||
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());
|
||||
}
|
||||
@@ -331,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);
|
||||
|
||||
@@ -293,7 +293,8 @@ public class ChannelServiceBean implements ChannelService {
|
||||
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());
|
||||
componentPayloadManagementService.createPayload(id, payload.getPayload(), payload.getPayloadType(),
|
||||
payload.getComponentOrigin(), server, payload.getComponentType());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -314,7 +315,6 @@ public class ChannelServiceBean implements ChannelService {
|
||||
allMessageActions.add(textChannel.sendFiles(attachedFiles));
|
||||
}
|
||||
}
|
||||
}
|
||||
Set<Message.MentionType> allowedMentions = allowedMentionService.getAllowedMentionsFor(textChannel, messageToSend);
|
||||
allMessageActions.forEach(messageAction -> {
|
||||
if (messageToSend.getReferencedMessageId() != null) {
|
||||
@@ -325,8 +325,10 @@ public class ChannelServiceBean implements ChannelService {
|
||||
}
|
||||
futures.add(messageAction.setAllowedMentions(allowedMentions).submit());
|
||||
});
|
||||
}
|
||||
return futures;
|
||||
}
|
||||
}
|
||||
|
||||
private Integer currentEmbedLength(List<MessageEmbed> messageEmbeds) {
|
||||
return messageEmbeds.stream().mapToInt(MessageEmbed::getLength).sum();
|
||||
|
||||
Reference in New Issue
Block a user