mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-03 00:20:12 +00:00
upgraded spring boot starter version
added gson dependency added logging the exception in the exception post executor added configuration exception in case the configuration for posttargets is not correct added support to send embeds to posttargets changed interface to be a warnlog instead of a server context for warning users, because the template changed freemarker Incompatible Improvements to support default methods in interfaces added ability to define embed configurations to be used, in order for a template to only be configurable as a template changed template content size to 4000 characters
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
package dev.sheldan.abstracto.core.exception;
|
||||
|
||||
public class ConfigurationException extends RuntimeException {
|
||||
public ConfigurationException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
package dev.sheldan.abstracto.core.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.exception.ConfigurationException;
|
||||
import dev.sheldan.abstracto.core.management.PostTargetManagement;
|
||||
import dev.sheldan.abstracto.core.management.ServerManagementService;
|
||||
import dev.sheldan.abstracto.core.models.database.PostTarget;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -25,11 +27,22 @@ public class PostTargetServiceBean implements PostTargetService {
|
||||
|
||||
@Override
|
||||
public void sendTextInPostTarget(String text, PostTarget target) {
|
||||
TextChannel textChannelForPostTarget = getTextChannelForPostTarget(target);
|
||||
textChannelForPostTarget.sendMessage(text).queue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendEmbedInPostTarget(MessageEmbed embed, PostTarget target) {
|
||||
TextChannel textChannelForPostTarget = getTextChannelForPostTarget(target);
|
||||
textChannelForPostTarget.sendMessage(embed).queue();
|
||||
}
|
||||
|
||||
private TextChannel getTextChannelForPostTarget(PostTarget target) {
|
||||
Guild guild = botService.getInstance().getGuildById(target.getServerReference().getId());
|
||||
if(guild != null) {
|
||||
TextChannel textChannelById = guild.getTextChannelById(target.getChannelReference().getId());
|
||||
if(textChannelById != null) {
|
||||
textChannelById.sendMessage(text).queue();
|
||||
return textChannelById;
|
||||
} else {
|
||||
log.warn("Incorrect post target configuration: {} points to {} on server {}", target.getName(),
|
||||
target.getChannelReference().getId(), target.getServerReference().getId());
|
||||
@@ -37,15 +50,28 @@ public class PostTargetServiceBean implements PostTargetService {
|
||||
} else {
|
||||
log.warn("Incorrect post target configuration: Guild id {} was not found.", target.getServerReference().getId());
|
||||
}
|
||||
throw new ConfigurationException("Incorrect post target configuration.");
|
||||
}
|
||||
|
||||
private PostTarget getPostTarget(String postTargetName, Long serverId) {
|
||||
PostTarget postTarget = postTargetManagement.getPostTarget(postTargetName, serverId);
|
||||
if(postTarget != null) {
|
||||
return postTarget;
|
||||
} else {
|
||||
log.warn("PostTarget {} in server {} was not found!", postTargetName, serverId);
|
||||
throw new ConfigurationException(String.format("Incorrect post target configuration: Post target %s was not found.", postTargetName));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTextInPostTarget(String text, String postTargetName, Long serverId) {
|
||||
PostTarget postTarget = postTargetManagement.getPostTarget(postTargetName, serverId);
|
||||
if(postTarget != null) {
|
||||
this.sendTextInPostTarget(text, postTarget);
|
||||
} else {
|
||||
log.warn("PostTarget {} in server {} was not found!", postTargetName, serverId);
|
||||
}
|
||||
PostTarget postTarget = this.getPostTarget(postTargetName, serverId);
|
||||
this.sendTextInPostTarget(text, postTarget);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendEmbedInPostTarget(MessageEmbed embed, String postTargetName, Long serverId) {
|
||||
PostTarget postTarget = this.getPostTarget(postTargetName, serverId);
|
||||
this.sendEmbedInPostTarget(embed, postTarget);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user