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