mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-21 04:48:44 +00:00
[AB-xxx] minor logging updates
This commit is contained in:
@@ -13,6 +13,7 @@ import dev.sheldan.abstracto.entertainment.config.EntertainmentFeatureDefinition
|
||||
import dev.sheldan.abstracto.entertainment.config.EntertainmentModuleDefinition;
|
||||
import dev.sheldan.abstracto.entertainment.exception.ReactTooManyReactionsException;
|
||||
import dev.sheldan.abstracto.entertainment.service.EntertainmentService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -21,6 +22,7 @@ import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class React extends AbstractConditionableCommand {
|
||||
|
||||
@Autowired
|
||||
@@ -38,6 +40,7 @@ public class React extends AbstractConditionableCommand {
|
||||
List<String> reactionChars = entertainmentService.convertTextToEmojis(text);
|
||||
int existingReactions = message.getReactions().size();
|
||||
if(reactionChars.size() + existingReactions > Message.MAX_REACTIONS) {
|
||||
log.error("Message has already {} reactions, {} would be added.", existingReactions, reactionChars.size());
|
||||
throw new ReactTooManyReactionsException();
|
||||
}
|
||||
List<CompletableFuture<Void>> futures = new ArrayList<>();
|
||||
|
||||
@@ -128,6 +128,7 @@ public class EntertainmentServiceBean implements EntertainmentService {
|
||||
}
|
||||
}
|
||||
}
|
||||
log.debug("Replaced {} combos.", replacedCombos.size());
|
||||
Set<String> usedReplacements = new HashSet<>();
|
||||
char[] split = text.toCharArray();
|
||||
|
||||
@@ -152,6 +153,7 @@ public class EntertainmentServiceBean implements EntertainmentService {
|
||||
}
|
||||
// reject any other character, as the ones we can deal with
|
||||
if (!this.reactMapping.getSingle().containsKey(charAsString)) {
|
||||
log.info("Cannot find mapping. Not replacing with emote.");
|
||||
continue;
|
||||
}
|
||||
List<String> listToUse = this.reactMapping.getSingle().get(charAsString);
|
||||
@@ -168,6 +170,7 @@ public class EntertainmentServiceBean implements EntertainmentService {
|
||||
throw new ReactDuplicateCharacterException();
|
||||
}
|
||||
}
|
||||
log.debug("We used {} replacements for a string of length {}.", usedReplacements.size(), text.length());
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -182,6 +185,8 @@ public class EntertainmentServiceBean implements EntertainmentService {
|
||||
JsonReader reader = new JsonReader(new InputStreamReader(reactMappingSource.getInputStream()));
|
||||
this.reactMapping = gson.fromJson(reader, ReactMapping.class);
|
||||
this.reactMapping.populateKeys();
|
||||
log.info("Loaded {} single replacement mappings.", this.reactMapping.getSingle().size());
|
||||
log.info("Loaded {} combo replacements.", this.reactMapping.getCombination().size());
|
||||
} catch (IOException e) {
|
||||
log.error("Failed to load react bindings.", e);
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ public class JoinLogger implements AsyncJoinListener {
|
||||
.builder()
|
||||
.member(listenerModel.getMember())
|
||||
.build();
|
||||
log.debug("Logging join event for user {} in server {}.", listenerModel.getMember().getIdLong(), listenerModel.getServerId());
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate(USER_JOIN_TEMPLATE, model, listenerModel.getServerId());
|
||||
postTargetService.sendEmbedInPostTarget(messageToSend, LoggingPostTarget.JOIN_LOG, listenerModel.getServerId());
|
||||
return DefaultListenerResult.PROCESSED;
|
||||
|
||||
@@ -44,6 +44,7 @@ public class LeaveLogger implements AsyncLeaveListener {
|
||||
.builder()
|
||||
.user(listenerModel.getUser())
|
||||
.build();
|
||||
log.debug("Logging leave event for user {} in server {}.", listenerModel.getUser().getIdLong(), listenerModel.getServerId());
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate(USER_LEAVE_TEMPLATE, model, listenerModel.getServerId());
|
||||
postTargetService.sendEmbedInPostTarget(messageToSend, LoggingPostTarget.LEAVE_LOG, listenerModel.getServerId());
|
||||
return DefaultListenerResult.PROCESSED;
|
||||
|
||||
@@ -73,7 +73,7 @@ public class MessageEditedListener implements AsyncMessageUpdatedListener {
|
||||
List<CachedAttachment> removedAttachments = messageBefore.getAttachments().stream().filter(cachedAttachment ->
|
||||
messageAfter.getAttachments().stream().noneMatch(attachment -> attachment.getIdLong() == cachedAttachment.getId())
|
||||
).collect(Collectors.toList());
|
||||
log.info("Logging deletion of {} attachments.", removedAttachments.size());
|
||||
log.debug("Logging deletion of {} attachments.", removedAttachments.size());
|
||||
for (int i = 0; i < removedAttachments.size(); i++) {
|
||||
MessageDeletedAttachmentLog log = MessageDeletedAttachmentLog
|
||||
.builder()
|
||||
|
||||
@@ -123,11 +123,14 @@ public class CommandCoolDownServiceBean implements CommandCoolDownService {
|
||||
Long channelSeconds = channelCooldown != null ? channelCooldown.getSeconds() : 0L;
|
||||
Long memberSeconds = memberCooldown != null ? memberCooldown.getSeconds() : 0L;
|
||||
if(serverSeconds > channelSeconds && serverSeconds > memberSeconds) {
|
||||
log.info("Rejecting command {}, because of server cooldown in server {}. Can be executed in {} seconds.", commandName, serverId, serverSeconds);
|
||||
return CoolDownCheckResult.getServerCoolDown(serverCooldown);
|
||||
}
|
||||
if(channelSeconds > serverSeconds && channelSeconds > memberSeconds) {
|
||||
log.info("Rejecting command {}, because of channel cooldown in server {}. Can be executed in {} seconds.", commandName, serverId, channelCooldown);
|
||||
return CoolDownCheckResult.getChannelGroupCoolDown(channelCooldown);
|
||||
}
|
||||
log.info("Rejecting command {}, because of member cooldown in server {}. Can be executed in {} seconds.", commandName, serverId, memberCooldown);
|
||||
return CoolDownCheckResult.getMemberCoolDown(memberCooldown);
|
||||
}
|
||||
return CoolDownCheckResult.noCoolDown();
|
||||
@@ -240,6 +243,7 @@ public class CommandCoolDownServiceBean implements CommandCoolDownService {
|
||||
if(coolDown.equals(Duration.ZERO)) {
|
||||
return;
|
||||
}
|
||||
log.info("Updating cooldowns for command {} in server {}.", command.getConfiguration().getName(), serverId);
|
||||
Instant newExecutionPoint = Instant.now().plus(coolDown);
|
||||
String commandName = command.getConfiguration().getName();
|
||||
Map<Long, CommandReUseMap> serverCoolDowns = storage.getServerCoolDowns();
|
||||
@@ -266,6 +270,8 @@ public class CommandCoolDownServiceBean implements CommandCoolDownService {
|
||||
if(coolDown.equals(Duration.ZERO)) {
|
||||
return;
|
||||
}
|
||||
log.info("Updating cooldowns for command {} in server {} in channel {}.",
|
||||
command.getConfiguration().getName(), serverIdChannelId.getServerId(), serverIdChannelId.getChannelId());
|
||||
Instant newExecutionPoint = Instant.now().plus(coolDown);
|
||||
String commandName = command.getConfiguration().getName();
|
||||
Long serverId = serverIdChannelId.getServerId();
|
||||
@@ -334,6 +340,9 @@ public class CommandCoolDownServiceBean implements CommandCoolDownService {
|
||||
if(coolDown.equals(Duration.ZERO)) {
|
||||
return;
|
||||
}
|
||||
log.info("Updating cooldowns for command {} in server {} in channel {} for user {}.",
|
||||
command.getConfiguration().getName(), serverChannelUserId.getGuildId(), serverChannelUserId.getChannelId(),
|
||||
serverChannelUserId.getUserId());
|
||||
Long serverId = serverChannelUserId.getGuildId();
|
||||
Instant newExecutionPoint = Instant.now().plus(coolDown);
|
||||
String commandName = command.getConfiguration().getName();
|
||||
@@ -388,6 +397,7 @@ public class CommandCoolDownServiceBean implements CommandCoolDownService {
|
||||
public void clearCoolDownsForServer(Long serverId) {
|
||||
takeLock();
|
||||
try {
|
||||
log.info("Clearing coldowns for server {}.", serverId);
|
||||
storage.getServerCoolDowns().remove(serverId);
|
||||
storage.getChannelGroupCoolDowns().remove(serverId);
|
||||
storage.getMemberCoolDowns().remove(serverId);
|
||||
@@ -414,6 +424,7 @@ public class CommandCoolDownServiceBean implements CommandCoolDownService {
|
||||
public void cleanUpCooldownStorage() {
|
||||
takeLock();
|
||||
try {
|
||||
log.info("Cleaning up old cooldowns in storage.");
|
||||
cleanUpLongReUseMap(storage.getServerCoolDowns());
|
||||
cleanUpLongLongReUseMap(storage.getMemberCoolDowns());
|
||||
cleanUpLongLongReUseMap(storage.getChannelGroupCoolDowns());
|
||||
|
||||
Reference in New Issue
Block a user