mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-06 08:25:31 +00:00
addressed sonar code smells
This commit is contained in:
@@ -3,7 +3,6 @@ package dev.sheldan.abstracto.templating.service;
|
||||
import com.google.gson.Gson;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
import dev.sheldan.abstracto.templating.model.*;
|
||||
import dev.sheldan.abstracto.templating.model.database.Template;
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.TemplateException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -61,8 +60,8 @@ public class TemplateServiceBean implements TemplateService {
|
||||
String embedConfig = this.renderTemplate(key + "_embed", model);
|
||||
List<EmbedBuilder> embedBuilders = new ArrayList<>();
|
||||
embedBuilders.add(new EmbedBuilder());
|
||||
EmbedConfiguration configuration = gson.fromJson(embedConfig, EmbedConfiguration.class);
|
||||
String description = configuration.getDescription();
|
||||
EmbedConfiguration embedConfiguration = gson.fromJson(embedConfig, EmbedConfiguration.class);
|
||||
String description = embedConfiguration.getDescription();
|
||||
if(description != null) {
|
||||
double neededIndices = Math.ceil(description.length() / (double) MessageEmbed.TEXT_MAX_LENGTH) - 1;
|
||||
extendIfNecessary(embedBuilders, neededIndices);
|
||||
@@ -71,32 +70,32 @@ public class TemplateServiceBean implements TemplateService {
|
||||
embedBuilders.get(i).setDescription(descriptionText);
|
||||
}
|
||||
}
|
||||
EmbedAuthor author = configuration.getAuthor();
|
||||
EmbedAuthor author = embedConfiguration.getAuthor();
|
||||
EmbedBuilder firstBuilder = embedBuilders.get(0);
|
||||
if(author != null) {
|
||||
firstBuilder.setAuthor(author.getName(), author.getUrl(), author.getAvatar());
|
||||
}
|
||||
|
||||
String thumbnail = configuration.getThumbnail();
|
||||
String thumbnail = embedConfiguration.getThumbnail();
|
||||
if(thumbnail != null) {
|
||||
firstBuilder.setThumbnail(thumbnail);
|
||||
}
|
||||
EmbedTitle title = configuration.getTitle();
|
||||
EmbedTitle title = embedConfiguration.getTitle();
|
||||
if(title != null) {
|
||||
firstBuilder.setTitle(title.getTitle(), title.getUrl());
|
||||
}
|
||||
EmbedFooter footer = configuration.getFooter();
|
||||
EmbedFooter footer = embedConfiguration.getFooter();
|
||||
if(footer != null) {
|
||||
firstBuilder.setFooter(footer.getText(), footer.getIcon());
|
||||
}
|
||||
if(configuration.getFields() != null) {
|
||||
createFieldsForEmbed(key, embedBuilders, configuration);
|
||||
if(embedConfiguration.getFields() != null) {
|
||||
createFieldsForEmbed(key, embedBuilders, embedConfiguration);
|
||||
}
|
||||
firstBuilder.setTimestamp(configuration.getTimeStamp());
|
||||
firstBuilder.setTimestamp(embedConfiguration.getTimeStamp());
|
||||
|
||||
firstBuilder.setImage(configuration.getImageUrl());
|
||||
firstBuilder.setImage(embedConfiguration.getImageUrl());
|
||||
|
||||
EmbedColor color = configuration.getColor();
|
||||
EmbedColor color = embedConfiguration.getColor();
|
||||
if(color != null) {
|
||||
int colorToSet = new Color(color.getR(), color.getG(), color.getB()).getRGB();
|
||||
embedBuilders.forEach(embedBuilder -> embedBuilder.setColor(colorToSet));
|
||||
@@ -109,7 +108,7 @@ public class TemplateServiceBean implements TemplateService {
|
||||
|
||||
return MessageToSend.builder()
|
||||
.embeds(embeds)
|
||||
.message(configuration.getAdditionalMessage())
|
||||
.message(embedConfiguration.getAdditionalMessage())
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -132,7 +131,7 @@ public class TemplateServiceBean implements TemplateService {
|
||||
for (int i = 0; i < configuration.getFields().size(); i++) {
|
||||
double currentPart = Math.floor(i / 25D);
|
||||
EmbedField embedField = configuration.getFields().get(i);
|
||||
Boolean inline = embedField.getInline() != null ? embedField.getInline() : Boolean.FALSE;
|
||||
boolean inline = embedField.getInline() != null ? embedField.getInline() : Boolean.FALSE;
|
||||
embedBuilders.get((int) currentPart).addField(embedField.getName(), embedField.getValue(), inline);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user