mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-22 22:06:43 +00:00
added mechanism to dynamically load properties defining postTargets and valid emoteNames
changed the output of the exception message refactored emote management service added service to define whether or not an emote is usable by the bot
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
package dev.sheldan.abstracto.moderation.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
@Configuration
|
||||
@PropertySource("classpath:moderation.properties")
|
||||
public class ModerationConfig {
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package dev.sheldan.abstracto.moderation.listener;
|
||||
|
||||
import dev.sheldan.abstracto.core.utils.ContextUtils;
|
||||
import dev.sheldan.abstracto.core.models.database.PostTarget;
|
||||
import dev.sheldan.abstracto.core.service.MessageCache;
|
||||
import dev.sheldan.abstracto.core.service.PostTargetService;
|
||||
import dev.sheldan.abstracto.moderation.models.template.listener.MessageDeletedAttachmentLog;
|
||||
@@ -20,6 +19,7 @@ import javax.annotation.Nonnull;
|
||||
@Component
|
||||
public class MessageDeletedListener extends ListenerAdapter {
|
||||
|
||||
private static final String DELETE_LOG_TARGET = "deleteLog";
|
||||
private static String MESSAGE_DELETED_TEMPLATE = "message_deleted";
|
||||
private static String MESSAGE_DELETED_ATTACHMENT_TEMPLATE = "message_deleted_attachment";
|
||||
|
||||
@@ -43,16 +43,16 @@ public class MessageDeletedListener extends ListenerAdapter {
|
||||
MessageDeletedLog logModel = (MessageDeletedLog) contextUtils.fromMessage(messageFromCache, MessageDeletedLog.class);
|
||||
logModel.setMessage(messageFromCache);
|
||||
String simpleMessageUpdatedMessage = templateService.renderTemplate(MESSAGE_DELETED_TEMPLATE, logModel);
|
||||
postTargetService.sendTextInPostTarget(simpleMessageUpdatedMessage, PostTarget.EDIT_LOG, event.getGuild().getIdLong());
|
||||
postTargetService.sendTextInPostTarget(simpleMessageUpdatedMessage, DELETE_LOG_TARGET, event.getGuild().getIdLong());
|
||||
MessageEmbed embed = templateService.renderEmbedTemplate(MESSAGE_DELETED_TEMPLATE, logModel);
|
||||
postTargetService.sendEmbedInPostTarget(embed, PostTarget.DELETE_LOG, event.getGuild().getIdLong());
|
||||
postTargetService.sendEmbedInPostTarget(embed, DELETE_LOG_TARGET, event.getGuild().getIdLong());
|
||||
for (int i = 0; i < messageFromCache.getAttachments().size(); i++) {
|
||||
Message.Attachment attachment = messageFromCache.getAttachments().get(i);
|
||||
MessageDeletedAttachmentLog log = (MessageDeletedAttachmentLog) contextUtils.fromMessage(messageFromCache, MessageDeletedAttachmentLog.class);
|
||||
log.setImageUrl(attachment.getProxyUrl());
|
||||
log.setCounter(i + 1);
|
||||
MessageEmbed attachmentEmbed = templateService.renderEmbedTemplate(MESSAGE_DELETED_ATTACHMENT_TEMPLATE, log);
|
||||
postTargetService.sendEmbedInPostTarget(attachmentEmbed, PostTarget.DELETE_LOG, event.getGuild().getIdLong());
|
||||
postTargetService.sendEmbedInPostTarget(attachmentEmbed, DELETE_LOG_TARGET, event.getGuild().getIdLong());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package dev.sheldan.abstracto.moderation.listener;
|
||||
|
||||
import dev.sheldan.abstracto.core.MessageTextUpdatedListener;
|
||||
import dev.sheldan.abstracto.core.models.database.PostTarget;
|
||||
import dev.sheldan.abstracto.core.service.MessageCache;
|
||||
import dev.sheldan.abstracto.core.service.PostTargetService;
|
||||
import dev.sheldan.abstracto.moderation.models.template.listener.MessageEditedLog;
|
||||
@@ -18,6 +17,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
public class MessageEditedListener implements MessageTextUpdatedListener {
|
||||
|
||||
private static final String MESSAGE_EDITED_TEMPLATE = "message_edited";
|
||||
private static final String EDIT_LOG_TARGET = "editLog";
|
||||
|
||||
@Autowired
|
||||
private TemplateService templateService;
|
||||
@@ -43,9 +43,9 @@ public class MessageEditedListener implements MessageTextUpdatedListener {
|
||||
.guild(messageAfter.getGuild())
|
||||
.member(messageAfter.getMember()).build();
|
||||
String simpleMessageUpdatedMessage = templateService.renderTemplate(MESSAGE_EDITED_TEMPLATE, log);
|
||||
postTargetService.sendTextInPostTarget(simpleMessageUpdatedMessage, PostTarget.EDIT_LOG, messageAfter.getGuild().getIdLong());
|
||||
postTargetService.sendTextInPostTarget(simpleMessageUpdatedMessage, EDIT_LOG_TARGET, messageAfter.getGuild().getIdLong());
|
||||
MessageEmbed embed = templateService.renderEmbedTemplate(MESSAGE_EDITED_TEMPLATE, log);
|
||||
postTargetService.sendEmbedInPostTarget(embed, PostTarget.DELETE_LOG, messageBefore.getGuild().getIdLong());
|
||||
postTargetService.sendEmbedInPostTarget(embed, EDIT_LOG_TARGET, messageBefore.getGuild().getIdLong());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
package dev.sheldan.abstracto.moderation.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.ServerContext;
|
||||
import dev.sheldan.abstracto.core.models.database.PostTarget;
|
||||
import dev.sheldan.abstracto.core.service.Bot;
|
||||
import dev.sheldan.abstracto.core.service.PostTargetService;
|
||||
import dev.sheldan.abstracto.moderation.models.template.BanIdLog;
|
||||
import dev.sheldan.abstracto.moderation.models.template.BanLog;
|
||||
import dev.sheldan.abstracto.templating.TemplateService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
@@ -17,8 +14,9 @@ import org.springframework.stereotype.Component;
|
||||
@Slf4j
|
||||
public class BanServiceBean implements BanService {
|
||||
|
||||
public static final String BAN_LOG_TEMPLATE = "ban_log";
|
||||
public static final String BAN_ID_LOG_TEMPLATE = "banid_log";
|
||||
private static final String BAN_LOG_TEMPLATE = "ban_log";
|
||||
private static final String BAN_ID_LOG_TEMPLATE = "banid_log";
|
||||
private static final String BAN_LOG_TARGET = "banLog";
|
||||
@Autowired
|
||||
private Bot bot;
|
||||
|
||||
@@ -32,14 +30,14 @@ public class BanServiceBean implements BanService {
|
||||
public void banMember(Member member, String reason, ServerContext banLog) {
|
||||
this.banUser(member.getGuild().getIdLong(), member.getIdLong(), reason);
|
||||
String warnLogMessage = templateService.renderContextAwareTemplate(BAN_LOG_TEMPLATE, banLog);
|
||||
postTargetService.sendTextInPostTarget(warnLogMessage, PostTarget.BAN_LOG, banLog.getServer().getId());
|
||||
postTargetService.sendTextInPostTarget(warnLogMessage, BAN_LOG_TARGET, banLog.getServer().getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void banMember(Long guildId, Long userId, String reason, ServerContext banIdLog) {
|
||||
banUser(guildId, userId, reason);
|
||||
String warnLogMessage = templateService.renderContextAwareTemplate(BAN_ID_LOG_TEMPLATE, banIdLog);
|
||||
postTargetService.sendTextInPostTarget(warnLogMessage, PostTarget.BAN_LOG, guildId);
|
||||
postTargetService.sendTextInPostTarget(warnLogMessage, BAN_LOG_TARGET, guildId);
|
||||
}
|
||||
|
||||
private void banUser(Long guildId, Long userId, String reason) {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package dev.sheldan.abstracto.moderation.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.PostTarget;
|
||||
import dev.sheldan.abstracto.core.service.Bot;
|
||||
import dev.sheldan.abstracto.core.service.PostTargetService;
|
||||
import dev.sheldan.abstracto.moderation.models.template.KickLogModel;
|
||||
@@ -15,7 +14,8 @@ import org.springframework.stereotype.Component;
|
||||
@Slf4j
|
||||
public class KickServiceBean implements KickService {
|
||||
|
||||
public static final String KICK_LOG_TEMPLATE = "kick_log";
|
||||
private static final String KICK_LOG_TEMPLATE = "kick_log";
|
||||
private static final String WARN_LOG_TARGET = "warnLog";
|
||||
@Autowired
|
||||
private Bot bot;
|
||||
|
||||
@@ -38,6 +38,6 @@ public class KickServiceBean implements KickService {
|
||||
|
||||
private void sendKickLog(KickLogModel kickLogModel) {
|
||||
String warnLogMessage = templateService.renderContextAwareTemplate(KICK_LOG_TEMPLATE, kickLogModel);
|
||||
postTargetService.sendTextInPostTarget(warnLogMessage, PostTarget.WARN_LOG, kickLogModel.getServer().getId());
|
||||
postTargetService.sendTextInPostTarget(warnLogMessage, WARN_LOG_TARGET, kickLogModel.getServer().getId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package dev.sheldan.abstracto.moderation.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.ServerContext;
|
||||
import dev.sheldan.abstracto.core.models.UserInitiatedServerContext;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.models.database.AUser;
|
||||
import dev.sheldan.abstracto.moderation.models.template.WarnLog;
|
||||
@@ -11,7 +10,6 @@ import dev.sheldan.abstracto.moderation.service.management.WarnManagementService
|
||||
import dev.sheldan.abstracto.core.management.ServerManagementService;
|
||||
import dev.sheldan.abstracto.core.management.UserManagementService;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.models.database.PostTarget;
|
||||
import dev.sheldan.abstracto.core.service.Bot;
|
||||
import dev.sheldan.abstracto.core.service.PostTargetService;
|
||||
import dev.sheldan.abstracto.templating.TemplateService;
|
||||
@@ -28,6 +26,7 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
public class WarnServiceBean implements WarnService {
|
||||
|
||||
public static final String WARN_LOG_TARGET = "warnLog";
|
||||
@Autowired
|
||||
private UserManagementService userManagementService;
|
||||
|
||||
@@ -86,8 +85,8 @@ public class WarnServiceBean implements WarnService {
|
||||
|
||||
private void sendWarnLog(ServerContext warnLogModel) {
|
||||
String warnLogMessage = templateService.renderContextAwareTemplate(WARN_LOG_TEMPLATE, warnLogModel);
|
||||
postTargetService.sendTextInPostTarget(warnLogMessage, PostTarget.WARN_LOG, warnLogModel.getServer().getId());
|
||||
postTargetService.sendTextInPostTarget(warnLogMessage, WARN_LOG_TARGET, warnLogModel.getServer().getId());
|
||||
MessageEmbed embed = templateService.renderEmbedTemplate("warn_log", warnLogModel);
|
||||
postTargetService.sendEmbedInPostTarget(embed, PostTarget.WARN_LOG, warnLogModel.getServer().getId());
|
||||
postTargetService.sendEmbedInPostTarget(embed, WARN_LOG_TARGET, warnLogModel.getServer().getId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package dev.sheldan.abstracto.utility.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
@Configuration
|
||||
@PropertySource("classpath:utility.properties")
|
||||
public class UtilityConfig {
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package dev.sheldan.abstracto.utility.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.management.EmoteManagementService;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.models.database.PostTarget;
|
||||
import dev.sheldan.abstracto.core.service.Bot;
|
||||
import dev.sheldan.abstracto.core.service.MessageService;
|
||||
import dev.sheldan.abstracto.core.service.PostTargetService;
|
||||
@@ -24,8 +23,9 @@ import org.springframework.stereotype.Component;
|
||||
public class SuggestionServiceBean implements SuggestionService {
|
||||
|
||||
public static final String SUGGESTION_LOG_TEMPLATE = "suggest_log";
|
||||
public static final String SUGGESTION_YES_EMOTE = "SUGGESTION_YES";
|
||||
public static final String SUGGESTION_NO_EMOTE = "SUGGESTION_NO";
|
||||
private static final String SUGGESTION_YES_EMOTE = "SUGGESTION_YES";
|
||||
private static final String SUGGESTION_NO_EMOTE = "SUGGESTION_NO";
|
||||
public static final String SUGGESTIONS_TARGET = "suggestions";
|
||||
@Autowired
|
||||
private SuggestionManagementService suggestionManagementService;
|
||||
|
||||
@@ -57,7 +57,7 @@ public class SuggestionServiceBean implements SuggestionService {
|
||||
JDA instance = botService.getInstance();
|
||||
Guild guildById = instance.getGuildById(guildId);
|
||||
if(guildById != null) {
|
||||
postTargetService.sendEmbedInPostTarget(embed, PostTarget.SUGGESTIONS, guildId).thenAccept(message -> {
|
||||
postTargetService.sendEmbedInPostTarget(embed, SUGGESTIONS_TARGET, guildId).thenAccept(message -> {
|
||||
messageService.addReactionToMessage(SUGGESTION_YES_EMOTE, guildId, message);
|
||||
messageService.addReactionToMessage(SUGGESTION_NO_EMOTE, guildId, message);
|
||||
suggestionManagementService.setPostedMessage(suggestion, message);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package dev.sheldan.abstracto.utility.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.PostTarget;
|
||||
import dev.sheldan.abstracto.core.service.PostTargetService;
|
||||
import dev.sheldan.abstracto.templating.TemplateService;
|
||||
import dev.sheldan.abstracto.utility.models.template.SuggestionLog;
|
||||
@@ -15,6 +14,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import java.util.Optional;
|
||||
|
||||
import static dev.sheldan.abstracto.utility.service.SuggestionServiceBean.SUGGESTION_LOG_TEMPLATE;
|
||||
import static dev.sheldan.abstracto.utility.service.SuggestionServiceBean.SUGGESTIONS_TARGET;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
@@ -34,7 +34,7 @@ public class AsyncSuggestionServiceBean {
|
||||
suggestionLog.setReason(text);
|
||||
suggestionLog.setText(suggestionEmbed.getDescription());
|
||||
MessageEmbed embed = templateService.renderEmbedTemplate(SUGGESTION_LOG_TEMPLATE, suggestionLog);
|
||||
postTargetService.sendEmbedInPostTarget(embed, PostTarget.SUGGESTIONS, suggestionLog.getServer().getId());
|
||||
postTargetService.sendEmbedInPostTarget(embed, SUGGESTIONS_TARGET, suggestionLog.getServer().getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
abstracto.postTargets.utility=suggestions
|
||||
@@ -0,0 +1,2 @@
|
||||
abstracto.postTargets.utility=suggestions
|
||||
abstracto.emoteNames.suggestion=SUGGESTION_YES,SUGGESTION_NO
|
||||
Reference in New Issue
Block a user