fixed some code smells

This commit is contained in:
Sheldan
2020-04-27 20:23:02 +02:00
parent e08086b6a9
commit 8e7bc7d98f
91 changed files with 251 additions and 268 deletions

View File

@@ -50,7 +50,7 @@ public class LeaderBoardCommand extends AbstractConditionableCommand {
public CommandResult execute(CommandContext commandContext) {
List<Object> parameters = commandContext.getParameters().getParameters();
// parameter is optional, in case its not present, we default to the 0th page
Integer page = parameters.size() > 0 ? (Integer) parameters.get(0) : 0;
Integer page = !parameters.isEmpty() ? (Integer) parameters.get(0) : 0;
LeaderBoard leaderBoard = userExperienceService.findLeaderBoardData(commandContext.getUserInitiatedContext().getServer(), page);
LeaderBoardModel leaderBoardModel = (LeaderBoardModel) ContextConverter.fromCommandContext(commandContext, LeaderBoardModel.class);
leaderBoardModel.setUserExperiences(converter.fromLeaderBoard(leaderBoard));

View File

@@ -8,6 +8,7 @@ import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.command.execution.ContextConverter;
import dev.sheldan.abstracto.core.config.FeatureEnum;
import dev.sheldan.abstracto.core.service.ChannelService;
import dev.sheldan.abstracto.experience.config.features.ExperienceFeature;
import dev.sheldan.abstracto.experience.converter.LeaderBoardModelConverter;
import dev.sheldan.abstracto.experience.models.LeaderBoardEntry;
@@ -39,6 +40,10 @@ public class Rank extends AbstractConditionableCommand {
@Autowired
private ExperienceLevelService experienceLevelService;
@Autowired
protected ChannelService channelService;
@Override
public CommandResult execute(CommandContext commandContext) {
RankModel rankModel = (RankModel) ContextConverter.fromCommandContext(commandContext, RankModel.class);

View File

@@ -176,25 +176,19 @@ public class AUserExperienceServiceBean implements AUserExperienceService {
Member member = botService.getMemberInServer(user.getServerReference(), user.getUserReference());
boolean currentlyHasNoExperienceRole = userExperience.getCurrentExperienceRole() == null;
if(role == null) {
if(!currentlyHasNoExperienceRole){
if(botService.isUserInGuild(userExperience.getUser())) {
roleService.removeRoleFromUser(user, userExperience.getCurrentExperienceRole().getRole());
}
if(!currentlyHasNoExperienceRole && botService.isUserInGuild(userExperience.getUser())){
roleService.removeRoleFromUser(user, userExperience.getCurrentExperienceRole().getRole());
}
userExperience.setCurrentExperienceRole(null);
return;
}
boolean userHasRoleAlready = roleService.memberHasRole(member, role.getRole());
if(!userHasRoleAlready) {
if(currentlyHasNoExperienceRole || !role.getRole().getId().equals(userExperience.getCurrentExperienceRole().getRole().getId())) {
log.info("User {} in server {} gets a new role {}", user.getUserReference().getId(), user.getServerReference().getId(), role.getRole().getId());
if(!currentlyHasNoExperienceRole) {
if(botService.isUserInGuild(userExperience.getUser())) {
roleService.removeRoleFromUser(user, userExperience.getCurrentExperienceRole().getRole());
}
}
roleService.addRoleToUser(user, role.getRole());
if(!userHasRoleAlready && (currentlyHasNoExperienceRole || !role.getRole().getId().equals(userExperience.getCurrentExperienceRole().getRole().getId()))) {
log.info("User {} in server {} gets a new role {}", user.getUserReference().getId(), user.getServerReference().getId(), role.getRole().getId());
if(!currentlyHasNoExperienceRole && botService.isUserInGuild(userExperience.getUser())) {
roleService.removeRoleFromUser(user, userExperience.getCurrentExperienceRole().getRole());
}
roleService.addRoleToUser(user, role.getRole());
}
userExperience.setCurrentExperienceRole(role);
}
@@ -226,9 +220,7 @@ public class AUserExperienceServiceBean implements AUserExperienceService {
List<AUserExperience> aUserExperiences = userExperienceManagementService.loadAllUsers(server);
log.info("Found {} users to synchronize", aUserExperiences.size());
List<AExperienceRole> roles = experienceRoleManagementService.getExperienceRolesForServer(server);
executeActionOnUserExperiencesWithFeedBack(aUserExperiences, channel, (AUserExperience experience) -> {
updateUserRole(experience, roles);
});
executeActionOnUserExperiencesWithFeedBack(aUserExperiences, channel, (AUserExperience experience) -> updateUserRole(experience, roles));
}
@Override

View File

@@ -55,14 +55,13 @@ public class ExperienceRoleServiceBean implements ExperienceRoleService {
public void unsetRole(ARole role, AServer server, AChannel feedbackChannel) {
AExperienceRole roleInServer = experienceRoleManagementService.getRoleInServer(role, server);
if(roleInServer != null) {
if(roleInServer.getUsers().size() > 0) {
if(!roleInServer.getUsers().isEmpty()) {
log.info("Recalculating the roles for {} users, because their current role was removed from experience tracking.", roleInServer.getUsers().size());
List<AExperienceRole> roles = experienceRoleManagementService.getExperienceRolesForServer(server);
roles.removeIf(role1 -> role1.getId().equals(roleInServer.getId()));
userExperienceService.executeActionOnUserExperiencesWithFeedBack(roleInServer.getUsers(), feedbackChannel, (AUserExperience ex) -> {
userExperienceService.updateUserRole(ex, roles);
});
userExperienceService.executeActionOnUserExperiencesWithFeedBack(roleInServer.getUsers(), feedbackChannel,
(AUserExperience ex) -> userExperienceService.updateUserRole(ex, roles));
}
experienceRoleManagementService.unsetRole(roleInServer);
}
@@ -76,7 +75,7 @@ public class ExperienceRoleServiceBean implements ExperienceRoleService {
*/
@Override
public AExperienceRole calculateRole(AUserExperience userExperience, List<AExperienceRole> roles) {
if(roles.size() == 0) {
if(roles.isEmpty()) {
return null;
}
AExperienceRole lastRole = null;

View File

@@ -27,9 +27,7 @@ public class ExperienceRoleManagementServiceBean implements ExperienceRoleManage
public void removeAllRoleAssignmentsForLevelInServer(AExperienceLevel level, AServer server) {
log.trace("Removing all role assignments for level {}.", level.getLevel());
List<AExperienceRole> existingExperienceRoles = experienceRoleRepository.findByLevelAndRoleServer(level, server);
existingExperienceRoles.forEach(existingRole -> {
experienceRoleRepository.delete(existingRole);
});
existingExperienceRoles.forEach(existingRole -> experienceRoleRepository.delete(existingRole));
}
@Override

View File

@@ -6,8 +6,6 @@ import org.springframework.stereotype.Component;
@Component
public class ExperienceFeatureDisplay implements FeatureDisplay {
public static String EXPERIENCE = "experience";
@Override
public FeatureEnum getFeature() {
return ExperienceFeature.EXPERIENCE;

View File

@@ -5,6 +5,7 @@ import lombok.*;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
/**
* Represents an existing level to reach and the total necessary experience needed to reach that level.
@@ -16,7 +17,7 @@ import javax.persistence.Table;
@Table(name = "experience_level")
@Getter
@Setter
public class AExperienceLevel {
public class AExperienceLevel implements Serializable {
/**
* The unique level from 0 to as defined in the configuration. Will be created on startup.
*/

View File

@@ -5,6 +5,7 @@ import dev.sheldan.abstracto.core.models.database.AServer;
import lombok.*;
import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@@ -19,7 +20,7 @@ import java.util.List;
@Table(name = "experience_role")
@Getter
@Setter
public class AExperienceRole {
public class AExperienceRole implements Serializable {
/**
* The abstracto unique id of this experience role.

View File

@@ -7,7 +7,7 @@ import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
import dev.sheldan.abstracto.core.command.config.Parameter;
import dev.sheldan.abstracto.core.command.execution.*;
import dev.sheldan.abstracto.core.config.FeatureEnum;
import dev.sheldan.abstracto.moderation.config.Moderation;
import dev.sheldan.abstracto.moderation.config.ModerationModule;
import dev.sheldan.abstracto.moderation.config.features.ModerationFeatures;
import dev.sheldan.abstracto.moderation.models.template.commands.BanLog;
import dev.sheldan.abstracto.moderation.service.BanService;
@@ -53,7 +53,7 @@ public class Ban extends AbstractConditionableCommand {
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
return CommandConfiguration.builder()
.name("ban")
.module(Moderation.MODERATION)
.module(ModerationModule.MODERATION)
.templated(true)
.causesReaction(true)
.parameters(parameters)

View File

@@ -6,7 +6,7 @@ import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
import dev.sheldan.abstracto.core.command.config.Parameter;
import dev.sheldan.abstracto.core.command.execution.*;
import dev.sheldan.abstracto.core.config.FeatureEnum;
import dev.sheldan.abstracto.moderation.config.Moderation;
import dev.sheldan.abstracto.moderation.config.ModerationModule;
import dev.sheldan.abstracto.moderation.config.features.ModerationFeatures;
import dev.sheldan.abstracto.moderation.models.template.commands.BanIdLog;
import dev.sheldan.abstracto.moderation.service.BanService;
@@ -49,7 +49,7 @@ public class BanId extends AbstractConditionableCommand {
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
return CommandConfiguration.builder()
.name("banid")
.module(Moderation.MODERATION)
.module(ModerationModule.MODERATION)
.templated(true)
.causesReaction(true)
.parameters(parameters)

View File

@@ -7,7 +7,7 @@ import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
import dev.sheldan.abstracto.core.command.config.Parameter;
import dev.sheldan.abstracto.core.command.execution.*;
import dev.sheldan.abstracto.core.config.FeatureEnum;
import dev.sheldan.abstracto.moderation.config.Moderation;
import dev.sheldan.abstracto.moderation.config.ModerationModule;
import dev.sheldan.abstracto.moderation.config.features.ModerationFeatures;
import dev.sheldan.abstracto.moderation.models.template.commands.KickLogModel;
import dev.sheldan.abstracto.moderation.service.KickServiceBean;
@@ -52,7 +52,7 @@ public class Kick extends AbstractConditionableCommand {
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
return CommandConfiguration.builder()
.name("kick")
.module(Moderation.MODERATION)
.module(ModerationModule.MODERATION)
.templated(true)
.causesReaction(true)
.parameters(parameters)

View File

@@ -8,7 +8,7 @@ import dev.sheldan.abstracto.core.command.config.Parameter;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureEnum;
import dev.sheldan.abstracto.core.utils.ParseUtils;
import dev.sheldan.abstracto.moderation.config.Moderation;
import dev.sheldan.abstracto.moderation.config.ModerationModule;
import dev.sheldan.abstracto.moderation.config.features.ModerationFeatures;
import dev.sheldan.abstracto.moderation.service.SlowModeService;
import net.dv8tion.jda.api.entities.TextChannel;
@@ -52,7 +52,7 @@ public class SlowMode extends AbstractConditionableCommand {
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
return CommandConfiguration.builder()
.name("slowmode")
.module(Moderation.MODERATION)
.module(ModerationModule.MODERATION)
.templated(true)
.causesReaction(true)
.parameters(parameters)

View File

@@ -7,7 +7,7 @@ import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
import dev.sheldan.abstracto.core.command.config.Parameter;
import dev.sheldan.abstracto.core.command.execution.*;
import dev.sheldan.abstracto.core.config.FeatureEnum;
import dev.sheldan.abstracto.moderation.config.Moderation;
import dev.sheldan.abstracto.moderation.config.ModerationModule;
import dev.sheldan.abstracto.moderation.config.features.ModerationFeatures;
import dev.sheldan.abstracto.moderation.models.template.commands.WarnLog;
import dev.sheldan.abstracto.moderation.service.WarnService;
@@ -53,7 +53,7 @@ public class Warn extends AbstractConditionableCommand {
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
return CommandConfiguration.builder()
.name("warn")
.module(Moderation.MODERATION)
.module(ModerationModule.MODERATION)
.templated(true)
.causesReaction(true)
.parameters(parameters)

View File

@@ -9,7 +9,7 @@ import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.command.execution.ContextConverter;
import dev.sheldan.abstracto.core.config.FeatureEnum;
import dev.sheldan.abstracto.moderation.config.Moderation;
import dev.sheldan.abstracto.moderation.config.ModerationModule;
import dev.sheldan.abstracto.moderation.config.features.ModerationFeatures;
import dev.sheldan.abstracto.moderation.models.template.commands.MuteLog;
import dev.sheldan.abstracto.moderation.service.MuteService;
@@ -51,7 +51,7 @@ public class Mute extends AbstractConditionableCommand {
HelpInfo helpInfo = HelpInfo.builder().templated(false).build();
return CommandConfiguration.builder()
.name("mute")
.module(Moderation.MODERATION)
.module(ModerationModule.MODERATION)
.templated(false)
.causesReaction(true)
.parameters(parameters)

View File

@@ -8,7 +8,7 @@ import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureEnum;
import dev.sheldan.abstracto.core.models.database.ARole;
import dev.sheldan.abstracto.moderation.config.Moderation;
import dev.sheldan.abstracto.moderation.config.ModerationModule;
import dev.sheldan.abstracto.moderation.config.features.ModerationFeatures;
import dev.sheldan.abstracto.moderation.service.management.MuteRoleManagementService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -37,7 +37,7 @@ public class SetMuteRole extends AbstractConditionableCommand {
HelpInfo helpInfo = HelpInfo.builder().templated(false).build();
return CommandConfiguration.builder()
.name("setMuteRole")
.module(Moderation.MODERATION)
.module(ModerationModule.MODERATION)
.templated(false)
.causesReaction(true)
.parameters(parameters)

View File

@@ -7,7 +7,7 @@ import dev.sheldan.abstracto.core.command.config.Parameter;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureEnum;
import dev.sheldan.abstracto.moderation.config.Moderation;
import dev.sheldan.abstracto.moderation.config.ModerationModule;
import dev.sheldan.abstracto.moderation.config.features.ModerationFeatures;
import dev.sheldan.abstracto.moderation.exception.MuteException;
import dev.sheldan.abstracto.moderation.models.database.Mute;
@@ -50,7 +50,7 @@ public class UnMute extends AbstractConditionableCommand {
HelpInfo helpInfo = HelpInfo.builder().templated(false).build();
return CommandConfiguration.builder()
.name("unMute")
.module(Moderation.MODERATION)
.module(ModerationModule.MODERATION)
.templated(false)
.causesReaction(true)
.parameters(parameters)

View File

@@ -42,7 +42,7 @@ public class JoinLogger implements JoinListener {
public void execute(Member member, Guild guild, AUserInAServer aUserInAServer) {
log.info("User {} joined server {}.", aUserInAServer.getUserReference().getId(), aUserInAServer.getServerReference().getId());
HashMap<String, Object> parameters = getUserParameter(member.getUser());
String text = templateService.renderTemplateWithMap(USER_JOIN_TEMPLATE, parameters);;
String text = templateService.renderTemplateWithMap(USER_JOIN_TEMPLATE, parameters);
postTargetService.sendTextInPostTarget(text, JOIN_LOG_TARGET, guild.getIdLong());
}

View File

@@ -19,8 +19,8 @@ import org.springframework.stereotype.Component;
public class MessageDeleteLogListener implements MessageDeletedListener {
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";
private static final String MESSAGE_DELETED_TEMPLATE = "message_deleted";
private static final String MESSAGE_DELETED_ATTACHMENT_TEMPLATE = "message_deleted_attachment";
@Autowired
private ContextUtils contextUtils;

View File

@@ -225,7 +225,7 @@ public class MuteServiceBean implements MuteService {
log.info("Unmuting {} in server {}", mutingServer.getId(), mute.getMutedUser().getUserReference().getId());
MuteRole muteRole = muteRoleManagementService.retrieveMuteRoleForServer(mutingServer);
log.trace("Using the mute role {} mapping to role {}", muteRole.getId(), muteRole.getRole().getId());
Guild guild = botService.getGuildById(mute.getMutingServer().getId()).orElseGet(null);
Guild guild = botService.getGuildByIdNullable(mute.getMutingServer().getId());
if(botService.isUserInGuild(guild, mute.getMutedUser())) {
roleService.removeRoleFromUser(mute.getMutedUser(), muteRole.getRole());
} else {

View File

@@ -5,7 +5,7 @@ import dev.sheldan.abstracto.core.command.config.ModuleInfo;
import org.springframework.stereotype.Component;
@Component
public class Moderation implements ModuleInterface {
public class ModerationModule implements ModuleInterface {
public static final String MODERATION = "moderation";

View File

@@ -1,5 +1,6 @@
package dev.sheldan.abstracto.utility.commands;
import dev.sheldan.abstracto.core.command.UtilityModuleInterface;
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
import dev.sheldan.abstracto.core.command.config.HelpInfo;
@@ -7,7 +8,6 @@ import dev.sheldan.abstracto.core.command.config.Parameter;
import dev.sheldan.abstracto.core.command.execution.*;
import dev.sheldan.abstracto.core.config.FeatureEnum;
import dev.sheldan.abstracto.templating.service.TemplateService;
import dev.sheldan.abstracto.utility.config.Utility;
import dev.sheldan.abstracto.utility.config.features.UtilityFeature;
import dev.sheldan.abstracto.utility.models.template.commands.ShowEmoteLog;
import net.dv8tion.jda.api.entities.Emote;
@@ -47,7 +47,7 @@ public class ShowEmote extends AbstractConditionableCommand {
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
return CommandConfiguration.builder()
.name("showEmote")
.module(Utility.UTILITY)
.module(UtilityModuleInterface.UTILITY)
.templated(true)
.causesReaction(false)
.parameters(parameters)

View File

@@ -1,5 +1,6 @@
package dev.sheldan.abstracto.utility.commands;
import dev.sheldan.abstracto.core.command.UtilityModuleInterface;
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
import dev.sheldan.abstracto.core.command.config.HelpInfo;
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
@@ -10,7 +11,6 @@ import dev.sheldan.abstracto.core.config.FeatureEnum;
import dev.sheldan.abstracto.templating.model.MessageToSend;
import dev.sheldan.abstracto.core.service.ChannelService;
import dev.sheldan.abstracto.templating.service.TemplateService;
import dev.sheldan.abstracto.utility.config.Utility;
import dev.sheldan.abstracto.utility.config.features.UtilityFeature;
import dev.sheldan.abstracto.utility.models.template.commands.starboard.StarStatsModel;
import dev.sheldan.abstracto.utility.service.StarboardService;
@@ -48,7 +48,7 @@ public class StarStats extends AbstractConditionableCommand {
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
return CommandConfiguration.builder()
.name("starStats")
.module(Utility.UTILITY)
.module(UtilityModuleInterface.UTILITY)
.templated(true)
.causesReaction(false)
.parameters(parameters)

View File

@@ -1,5 +1,6 @@
package dev.sheldan.abstracto.utility.commands.remind;
import dev.sheldan.abstracto.core.command.UtilityModuleInterface;
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
import dev.sheldan.abstracto.core.command.config.HelpInfo;
@@ -8,7 +9,6 @@ import dev.sheldan.abstracto.core.command.execution.*;
import dev.sheldan.abstracto.core.config.FeatureEnum;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import dev.sheldan.abstracto.utility.config.features.UtilityFeature;
import dev.sheldan.abstracto.utility.config.Utility;
import dev.sheldan.abstracto.utility.models.template.commands.reminder.ReminderModel;
import dev.sheldan.abstracto.utility.service.ReminderService;
import net.dv8tion.jda.api.entities.MessageEmbed;
@@ -46,7 +46,7 @@ public class Remind extends AbstractConditionableCommand {
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
return CommandConfiguration.builder()
.name("remind")
.module(Utility.UTILITY)
.module(UtilityModuleInterface.UTILITY)
.templated(true)
.causesReaction(true)
.parameters(parameters)

View File

@@ -1,5 +1,6 @@
package dev.sheldan.abstracto.utility.commands.remind;
import dev.sheldan.abstracto.core.command.UtilityModuleInterface;
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
import dev.sheldan.abstracto.core.command.config.HelpInfo;
@@ -10,7 +11,6 @@ import dev.sheldan.abstracto.core.config.FeatureEnum;
import dev.sheldan.abstracto.core.service.ChannelService;
import dev.sheldan.abstracto.templating.model.MessageToSend;
import dev.sheldan.abstracto.templating.service.TemplateService;
import dev.sheldan.abstracto.utility.config.Utility;
import dev.sheldan.abstracto.utility.config.features.UtilityFeature;
import dev.sheldan.abstracto.utility.models.database.Reminder;
import dev.sheldan.abstracto.utility.models.template.commands.reminder.RemindersModel;
@@ -47,7 +47,7 @@ public class Reminders extends AbstractConditionableCommand {
HelpInfo helpInfo = HelpInfo.builder().longHelp("Shows the current active reminders").usage("reminders").build();
return CommandConfiguration.builder()
.name("reminders")
.module(Utility.UTILITY)
.module(UtilityModuleInterface.UTILITY)
.description("Shows the current active reminders")
.causesReaction(true)
.help(helpInfo)

View File

@@ -1,12 +1,12 @@
package dev.sheldan.abstracto.utility.commands.suggest;
import dev.sheldan.abstracto.core.command.UtilityModuleInterface;
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
import dev.sheldan.abstracto.core.command.config.HelpInfo;
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
import dev.sheldan.abstracto.core.command.config.Parameter;
import dev.sheldan.abstracto.core.command.execution.*;
import dev.sheldan.abstracto.core.config.FeatureEnum;
import dev.sheldan.abstracto.utility.config.Utility;
import dev.sheldan.abstracto.utility.config.features.UtilityFeature;
import dev.sheldan.abstracto.utility.models.template.commands.SuggestionLog;
import dev.sheldan.abstracto.utility.service.SuggestionService;
@@ -41,7 +41,7 @@ public class Accept extends AbstractConditionableCommand {
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
return CommandConfiguration.builder()
.name("accept")
.module(Utility.UTILITY)
.module(UtilityModuleInterface.UTILITY)
.templated(true)
.causesReaction(true)
.parameters(parameters)

View File

@@ -1,12 +1,12 @@
package dev.sheldan.abstracto.utility.commands.suggest;
import dev.sheldan.abstracto.core.command.UtilityModuleInterface;
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
import dev.sheldan.abstracto.core.command.config.HelpInfo;
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
import dev.sheldan.abstracto.core.command.config.Parameter;
import dev.sheldan.abstracto.core.command.execution.*;
import dev.sheldan.abstracto.core.config.FeatureEnum;
import dev.sheldan.abstracto.utility.config.Utility;
import dev.sheldan.abstracto.utility.config.features.UtilityFeature;
import dev.sheldan.abstracto.utility.models.template.commands.SuggestionLog;
import dev.sheldan.abstracto.utility.service.SuggestionService;
@@ -41,7 +41,7 @@ public class Reject extends AbstractConditionableCommand {
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
return CommandConfiguration.builder()
.name("reject")
.module(Utility.UTILITY)
.module(UtilityModuleInterface.UTILITY)
.templated(true)
.causesReaction(true)
.parameters(parameters)

View File

@@ -1,12 +1,12 @@
package dev.sheldan.abstracto.utility.commands.suggest;
import dev.sheldan.abstracto.core.command.UtilityModuleInterface;
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
import dev.sheldan.abstracto.core.command.config.HelpInfo;
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
import dev.sheldan.abstracto.core.command.config.Parameter;
import dev.sheldan.abstracto.core.command.execution.*;
import dev.sheldan.abstracto.core.config.FeatureEnum;
import dev.sheldan.abstracto.utility.config.Utility;
import dev.sheldan.abstracto.utility.config.features.UtilityFeature;
import dev.sheldan.abstracto.utility.models.template.commands.SuggestionLog;
import dev.sheldan.abstracto.utility.service.SuggestionService;
@@ -40,7 +40,7 @@ public class Suggest extends AbstractConditionableCommand {
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
return CommandConfiguration.builder()
.name("suggest")
.module(Utility.UTILITY)
.module(UtilityModuleInterface.UTILITY)
.templated(true)
.causesReaction(true)
.parameters(parameters)

View File

@@ -2,6 +2,7 @@ package dev.sheldan.abstracto.utility.listener.embed;
import dev.sheldan.abstracto.core.config.FeatureEnum;
import dev.sheldan.abstracto.core.listener.MessageReceivedListener;
import dev.sheldan.abstracto.core.models.cache.CachedMessage;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import dev.sheldan.abstracto.core.service.MessageCache;
import dev.sheldan.abstracto.core.service.management.UserManagementService;
@@ -15,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.function.Consumer;
@Component
@Slf4j
@@ -38,11 +40,10 @@ public class MessageEmbedListener implements MessageReceivedListener {
for (MessageEmbedLink messageEmbedLink : links) {
messageRaw = messageRaw.replace(messageEmbedLink.getWholeUrl(), "");
AUserInAServer cause = userManagementService.loadUser(message.getMember());
messageCache.getMessageFromCache(messageEmbedLink.getServerId(), messageEmbedLink.getChannelId(), messageEmbedLink.getMessageId()).thenAccept(cachedMessage -> {
messageEmbedService.embedLink(cachedMessage, message.getTextChannel(), cause, message);
});
Consumer<CachedMessage> cachedMessageConsumer = cachedMessage -> messageEmbedService.embedLink(cachedMessage, message.getTextChannel(), cause, message);
messageCache.getMessageFromCache(messageEmbedLink.getServerId(), messageEmbedLink.getChannelId(), messageEmbedLink.getMessageId()).thenAccept(cachedMessageConsumer);
}
if(StringUtils.isBlank(messageRaw) && links.size() > 0) {
if(StringUtils.isBlank(messageRaw) && !links.isEmpty()) {
message.delete().queue();
}
}

View File

@@ -55,9 +55,9 @@ public class MessageEmbedRemovalReactionListener implements ReactedAddedListener
if(embeddedMessage.getEmbeddedUser().getUserReference().getId().equals(userReacting.getId())
|| embeddedMessage.getEmbeddingUser().getUserReference().getId().equals(userReacting.getId())
) {
messageService.deleteMessageInChannelInServer(message.getServerId(), message.getChannelId(), message.getMessageId()).thenAccept(aVoid -> {
messageEmbedPostManagementService.deleteEmbeddedMessageTransactional(embeddedMessage);
});
messageService.deleteMessageInChannelInServer(message.getServerId(), message.getChannelId(), message.getMessageId()).thenAccept(aVoid ->
messageEmbedPostManagementService.deleteEmbeddedMessageTransactional(embeddedMessage)
);
}
}

View File

@@ -26,6 +26,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.regex.Matcher;
@@ -37,7 +38,7 @@ public class MessageEmbedServiceBean implements MessageEmbedService {
private Pattern messageRegex = Pattern.compile("(?<whole>https://discordapp.com/channels/(?<server>\\d+)/(?<channel>\\d+)/(?<message>\\d+)(?:.*?))+");
public static final String MESSAGE_EMBED_TEMPLATE = "message";
public static final String MESSAGE_EMBED_TEMPLATE = "message_embed";
public static final String REMOVAL_EMOTE = "removeEmbed";
@Autowired
@@ -96,12 +97,12 @@ public class MessageEmbedServiceBean implements MessageEmbedService {
@Override
public void embedLinks(List<MessageEmbedLink> linksToEmbed, TextChannel target, AUserInAServer reason, Message embeddingMessage) {
linksToEmbed.forEach(messageEmbedLink -> {
linksToEmbed.forEach(messageEmbedLink ->
messageCache.getMessageFromCache(messageEmbedLink.getServerId(), messageEmbedLink.getChannelId(), messageEmbedLink.getMessageId())
.thenAccept(cachedMessage -> {
self.embedLink(cachedMessage, target, reason, embeddingMessage);
});
});
.thenAccept(cachedMessage ->
self.embedLink(cachedMessage, target, reason, embeddingMessage)
)
);
}
@Override
@@ -129,7 +130,11 @@ public class MessageEmbedServiceBean implements MessageEmbedService {
AServer server = serverManagementService.loadOrCreate(message.getGuild().getIdLong());
AUserInAServer user = userManagementService.loadUser(message.getMember());
Member author = botService.getMemberInServer(embeddedMessage.getServerId(), embeddedMessage.getAuthorId());
TextChannel sourceChannel = botService.getTextChannelFromServer(embeddedMessage.getServerId(), embeddedMessage.getChannelId()).get();
Optional<TextChannel> textChannelFromServer = botService.getTextChannelFromServer(embeddedMessage.getServerId(), embeddedMessage.getChannelId());
TextChannel sourceChannel = null;
if(textChannelFromServer.isPresent()) {
sourceChannel = textChannelFromServer.get();
}
return MessageEmbeddedModel
.builder()
.channel(channel)

View File

@@ -81,10 +81,9 @@ public class StarboardServiceBean implements StarboardService {
.server(userReacting.getServerReference())
.build();
StarboardPost starboardPost = starboardPostManagementService.createStarboardPost(message, starredUser, userReacting, aServerAChannelMessage);
// TODO maybe in bulk, but numbers should be small enough
userExceptAuthor.forEach(user -> {
starboardPostReactorManagementService.addReactor(starboardPost, user);
});
userExceptAuthor.forEach(user ->
starboardPostReactorManagementService.addReactor(starboardPost, user)
);
} catch (InterruptedException | ExecutionException e) {
log.error("Failed to post messages.", e);
}
@@ -117,9 +116,9 @@ public class StarboardServiceBean implements StarboardService {
@Override
public void updateStarboardPost(StarboardPost post, CachedMessage message, List<AUser> userExceptAuthor) {
StarboardPostModel starboardPostModel = buildStarboardPostModel(message, userExceptAuthor.size());
MessageToSend messageToSend = templateService.renderEmbedTemplate("starboard_post", starboardPostModel);
MessageToSend messageToSend = templateService.renderEmbedTemplate(STARBOARD_POST_TEMPLATE, starboardPostModel);
List<CompletableFuture<Message>> futures = new ArrayList<>();
postTargetService.editOrCreatedInPostTarget(post.getStarboardMessageId(), messageToSend, "starboard", message.getServerId(), futures);
postTargetService.editOrCreatedInPostTarget(post.getStarboardMessageId(), messageToSend, STARBOARD_POSTTARGET, message.getServerId(), futures);
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).thenAccept(aVoid -> {
try {
starboardPostManagementService.setStarboardPostMessageId(post, futures.get(0).get().getIdLong());

View File

@@ -102,9 +102,9 @@ public class SuggestionServiceBean implements SuggestionService {
suggestionLog.setSuggestion(suggestion);
TextChannel textChannelById = guildById.getTextChannelById(channelId);
if(textChannelById != null) {
textChannelById.retrieveMessageById(originalMessageId).queue(message -> {
self.updateSuggestionMessageText(text, suggestionLog, message);
});
textChannelById.retrieveMessageById(originalMessageId).queue(message ->
self.updateSuggestionMessageText(text, suggestionLog, message)
);
}
}
}

View File

@@ -1,21 +0,0 @@
package dev.sheldan.abstracto.utility.config;
import dev.sheldan.abstracto.core.command.config.ModuleInterface;
import dev.sheldan.abstracto.core.command.config.ModuleInfo;
import org.springframework.stereotype.Component;
@Component
public class Utility implements ModuleInterface {
public static final String UTILITY = "utility";
@Override
public ModuleInfo getInfo() {
return ModuleInfo.builder().name(UTILITY).description("General utilities").build();
}
@Override
public String getParentModule() {
return "default";
}
}

View File

@@ -12,7 +12,6 @@ import dev.sheldan.abstracto.core.command.service.PostCommandExecution;
import dev.sheldan.abstracto.core.command.execution.*;
import dev.sheldan.abstracto.core.command.execution.UnParsedCommandParameter;
import dev.sheldan.abstracto.core.Constants;
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
import dev.sheldan.abstracto.core.models.database.ARole;
import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
import dev.sheldan.abstracto.core.service.management.RoleManagementService;
@@ -152,7 +151,7 @@ public class CommandReceivedHandler extends ListenerAdapter {
public Parameters getParsedParameters(UnParsedCommandParameter unParsedCommandParameter, Command command, Message message){
List<Object> parsedParameters = new ArrayList<>();
if(command.getConfiguration().getParameters() == null || command.getConfiguration().getParameters().size() == 0) {
if(command.getConfiguration().getParameters() == null || command.getConfiguration().getParameters().isEmpty()) {
return Parameters.builder().parameters(parsedParameters).build();
}
Iterator<TextChannel> channelIterator = message.getMentionedChannels().iterator();
@@ -199,7 +198,7 @@ public class CommandReceivedHandler extends ListenerAdapter {
if(!reminderActive) {
parsedParameters.add(value);
} else {
if(parsedParameters.size() == 0) {
if(parsedParameters.isEmpty()) {
parsedParameters.add(value);
} else {
int lastIndex = parsedParameters.size() - 1;

View File

@@ -25,10 +25,8 @@ public class ReactionPostExecution implements PostCommandExecution {
if(commandResult.getMessage() != null && commandResult.getThrowable() == null){
commandContext.getChannel().sendMessage(commandResult.getMessage()).queue();
}
} else if(result.equals(ResultState.SUCCESSFUL)) {
if(command.getConfiguration().isCausesReaction()){
messageService.addReactionToMessage(SUCCESS_REACTION_EMOTE, commandContext.getGuild().getIdLong(), commandContext.getMessage());
}
} else if(result.equals(ResultState.SUCCESSFUL) && command.getConfiguration().isCausesReaction()) {
messageService.addReactionToMessage(SUCCESS_REACTION_EMOTE, commandContext.getGuild().getIdLong(), commandContext.getMessage());
}
}

View File

@@ -22,15 +22,10 @@ public class ChannelGroupCommandServiceBean implements ChannelGroupCommandServic
for (AChannelGroupCommand aChannelGroupCommand : allChannelGroupsOfCommand) {
Optional<AChannel> channelInGroup = aChannelGroupCommand.getGroup()
.getChannels().stream().filter(channel1 -> channel1.getId().equals(channel.getId())).findAny();
if (channelInGroup.isPresent()) {
if (aChannelGroupCommand.getEnabled()) {
return true;
}
if (channelInGroup.isPresent() && aChannelGroupCommand.getEnabled()) {
return true;
}
}
if(allChannelGroupsOfCommand.size() == 0) {
return true;
}
return false;
return allChannelGroupsOfCommand.isEmpty();
}
}

View File

@@ -46,7 +46,7 @@ public class CommandManager implements CommandRegistry {
}
parameterFit = paramCountFits || hasRemainderParameter;
} else {
parameterFit = unParsedCommandParameter.getParameters().size() == 0;
parameterFit = unParsedCommandParameter.getParameters().isEmpty();
}
return parameterFit;
}).findFirst();
@@ -86,13 +86,13 @@ public class CommandManager implements CommandRegistry {
@Override
public List<Command> getAllCommandsFromModule(ModuleInterface moduleInterface) {
List<Command> commands = new ArrayList<>();
List<Command> commandsFromModule = new ArrayList<>();
this.getAllCommands().forEach(command -> {
if(command.getConfiguration().getModule().equals(moduleInterface.getInfo().getName())){
commands.add(command);
commandsFromModule.add(command);
}
});
return commands;
return commandsFromModule;
}
@Override

View File

@@ -4,8 +4,6 @@ import dev.sheldan.abstracto.core.command.Command;
import dev.sheldan.abstracto.core.command.config.CommandHierarchy;
import dev.sheldan.abstracto.core.command.config.ModuleInterface;
import dev.sheldan.abstracto.core.command.config.PackedModule;
import dev.sheldan.abstracto.core.command.service.CommandRegistry;
import dev.sheldan.abstracto.core.command.service.ModuleRegistry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

View File

@@ -40,9 +40,9 @@ public class Allow extends AbstractConditionableCommand {
String name = (String) commandContext.getParameters().getParameters().get(0);
if(featureManagementService.featureExists(name)) {
AFeature feature = featureManagementService.getFeature(name);
feature.getCommands().forEach(command -> {
commandService.unRestrictCommand(command, commandContext.getUserInitiatedContext().getServer());
});
feature.getCommands().forEach(command ->
commandService.unRestrictCommand(command, commandContext.getUserInitiatedContext().getServer())
);
} else if(commandManagementService.doesCommandExist(name)) {
ACommand command = commandManagementService.findCommandByName(name);
commandService.unRestrictCommand(command, commandContext.getUserInitiatedContext().getServer());

View File

@@ -43,9 +43,9 @@ public class AllowRole extends AbstractConditionableCommand {
ARole role = roleManagementService.findRole(roleId);
if(featureManagementService.featureExists(name)) {
AFeature feature = featureManagementService.getFeature(name);
feature.getCommands().forEach(command -> {
commandService.allowCommandForRole(command, role);
});
feature.getCommands().forEach(command ->
commandService.allowCommandForRole(command, role)
);
} else if(commandManagementService.doesCommandExist(name)) {
ACommand command = commandManagementService.findCommandByName(name);
commandService.allowCommandForRole(command, role);

View File

@@ -43,9 +43,9 @@ public class DisAllowRole extends AbstractConditionableCommand {
ARole role = roleManagementService.findRole(roleId);
if(featureManagementService.featureExists(name)) {
AFeature feature = featureManagementService.getFeature(name);
feature.getCommands().forEach(command -> {
commandService.disAllowCommandForRole(command, role);
});
feature.getCommands().forEach(command ->
commandService.disAllowCommandForRole(command, role)
);
} else if(commandManagementService.doesCommandExist(name)) {
ACommand command = commandManagementService.findCommandByName(name);
commandService.disAllowCommandForRole(command, role);

View File

@@ -35,7 +35,7 @@ public class Disable extends AbstractConditionableCommand {
@Override
public CommandResult execute(CommandContext commandContext) {
if(commandContext.getParameters().getParameters().size() == 0) {
if(commandContext.getParameters().getParameters().isEmpty()) {
EnableModel model = (EnableModel) ContextConverter.fromCommandContext(commandContext, EnableModel.class);
model.setFeatures(featureFlagService.getAllFeatures());
String response = templateService.renderTemplate("disable_features_response", model);

View File

@@ -34,7 +34,7 @@ public class Enable extends AbstractConditionableCommand {
@Override
public CommandResult execute(CommandContext commandContext) {
if(commandContext.getParameters().getParameters().size() == 0) {
if(commandContext.getParameters().getParameters().isEmpty()) {
EnableModel model = (EnableModel) ContextConverter.fromCommandContext(commandContext, EnableModel.class);
model.setFeatures(featureFlagService.getAllFeatures());
String response = templateService.renderTemplate("enable_features_response", model);

View File

@@ -43,9 +43,9 @@ public class MakeAffected extends AbstractConditionableCommand {
ARole role = roleManagementService.findRole(roleId);
if(featureManagementService.featureExists(name)) {
AFeature feature = featureManagementService.getFeature(name);
feature.getCommands().forEach(command -> {
commandService.makeRoleAffectedByCommand(command, role);
});
feature.getCommands().forEach(command ->
commandService.makeRoleAffectedByCommand(command, role)
);
} else if(commandManagementService.doesCommandExist(name)) {
ACommand command = commandManagementService.findCommandByName(name);
commandService.makeRoleAffectedByCommand(command, role);

View File

@@ -43,9 +43,9 @@ public class MakeImmune extends AbstractConditionableCommand {
ARole role = roleManagementService.findRole(roleId);
if(featureManagementService.featureExists(name)) {
AFeature feature = featureManagementService.getFeature(name);
feature.getCommands().forEach(command -> {
commandService.makeRoleImmuneForCommand(command, role);
});
feature.getCommands().forEach(command ->
commandService.makeRoleImmuneForCommand(command, role)
);
} else if(commandManagementService.doesCommandExist(name)) {
ACommand command = commandManagementService.findCommandByName(name);
commandService.makeRoleImmuneForCommand(command, role);

View File

@@ -40,9 +40,9 @@ public class Restrict extends AbstractConditionableCommand {
String name = (String) commandContext.getParameters().getParameters().get(0);
if(featureManagementService.featureExists(name)) {
AFeature feature = featureManagementService.getFeature(name);
feature.getCommands().forEach(command -> {
commandService.restrictCommand(command, commandContext.getUserInitiatedContext().getServer());
});
feature.getCommands().forEach(command ->
commandService.restrictCommand(command, commandContext.getUserInitiatedContext().getServer())
);
} else if(commandManagementService.doesCommandExist(name)) {
ACommand command = commandManagementService.findCommandByName(name);
commandService.restrictCommand(command, commandContext.getUserInitiatedContext().getServer());

View File

@@ -42,9 +42,9 @@ public class Help implements Command {
if(module != null){
sb.append("Help | Module overview \n");
sb.append(getModule(module, 0, false));
module.getCommands().forEach(command -> {
sb.append(getCommand(command));
});
module.getCommands().forEach(command ->
sb.append(getCommand(command))
);
} else {
Command command = commandStructure.getCommandWithName(parameterValue);
if(command != null) {
@@ -109,9 +109,9 @@ public class Help implements Command {
sb.append(String.format(intentation +"**%s** \n", info.getName()));
sb.append(String.format(intentation + "%s \n", info.getDescription()));
if(recursive) {
module.getSubModules().forEach(subModule -> {
sb.append(getModule(subModule, depth + 1, true));
});
module.getSubModules().forEach(subModule ->
sb.append(getModule(subModule, depth + 1, true))
);
}
sb.append("\n");
return sb.toString();

View File

@@ -27,9 +27,9 @@ public class Echo extends AbstractConditionableCommand {
@Override
public CommandResult execute(CommandContext commandContext) {
StringBuilder sb = new StringBuilder();
commandContext.getParameters().getParameters().forEach(o -> {
sb.append(o.toString());
});
commandContext.getParameters().getParameters().forEach(o ->
sb.append(o.toString())
);
EchoModel model = EchoModel.builder().text(sb.toString()).build();
commandContext.getChannel().sendMessage(templateService.renderTemplate(TEMPLATE_NAME, model)).queue();
return CommandResult.fromSuccess();

View File

@@ -1,5 +1,6 @@
package dev.sheldan.abstracto.core.commands.utility;
import dev.sheldan.abstracto.core.command.UtilityModuleInterface;
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
import dev.sheldan.abstracto.core.command.execution.CommandContext;

View File

@@ -1,6 +1,5 @@
package dev.sheldan.abstracto.core.listener;
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import dev.sheldan.abstracto.core.service.FeatureFlagService;
import dev.sheldan.abstracto.core.service.management.UserManagementService;

View File

@@ -13,6 +13,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Nonnull;
import java.util.List;
import java.util.function.Consumer;
@Component
@Slf4j
@@ -32,9 +33,8 @@ public class MessageDeletedListenerBean extends ListenerAdapter {
@Override
@Transactional
public void onGuildMessageDelete(@Nonnull GuildMessageDeleteEvent event) {
messageCache.getMessageFromCache(event.getGuild().getIdLong(), event.getChannel().getIdLong(), event.getMessageIdLong()).thenAccept(cachedMessage -> {
self.executeListener(cachedMessage);
});
Consumer<CachedMessage> cachedMessageConsumer = cachedMessage -> self.executeListener(cachedMessage);
messageCache.getMessageFromCache(event.getGuild().getIdLong(), event.getChannel().getIdLong(), event.getMessageIdLong()).thenAccept(cachedMessageConsumer);
}
@Transactional

View File

@@ -67,9 +67,9 @@ public class ReactionUpdatedListener extends ListenerAdapter {
}
private void addReactionIfNotThere(CachedMessage message, CachedReaction reaction, AUser userReacting) {
Optional<CachedReaction> existingReaction = message.getReactions().stream().filter(reaction1 -> {
return EmoteUtils.compareAEmote(reaction1.getEmote(), reaction.getEmote());
}).findAny();
Optional<CachedReaction> existingReaction = message.getReactions().stream().filter(reaction1 ->
EmoteUtils.compareAEmote(reaction1.getEmote(), reaction.getEmote())
).findAny();
if(!existingReaction.isPresent()) {
message.getReactions().add(reaction);
} else {
@@ -82,9 +82,9 @@ public class ReactionUpdatedListener extends ListenerAdapter {
}
private void removeReactionIfThere(CachedMessage message, CachedReaction reaction, AUser userReacting) {
Optional<CachedReaction> existingReaction = message.getReactions().stream().filter(reaction1 -> {
return EmoteUtils.compareAEmote(reaction1.getEmote(), reaction.getEmote());
}).findAny();
Optional<CachedReaction> existingReaction = message.getReactions().stream().filter(reaction1 ->
EmoteUtils.compareAEmote(reaction1.getEmote(), reaction.getEmote())
).findAny();
if(existingReaction.isPresent()) {
CachedReaction cachedReaction = existingReaction.get();
cachedReaction.getUsers().removeIf(user -> user.getId().equals(userReacting.getId()));
@@ -118,9 +118,9 @@ public class ReactionUpdatedListener extends ListenerAdapter {
asyncMessageFromCache.thenAccept(cachedMessage -> {
CompletableFuture<CachedReaction> future = new CompletableFuture<>();
messageCache.getCachedReactionFromReaction(future, event.getReaction());
future.thenAccept(reaction -> {
self.callRemoveListeners(event, cachedMessage, reaction);
});
future.thenAccept(reaction ->
self.callRemoveListeners(event, cachedMessage, reaction)
);
messageCache.putMessageInCache(cachedMessage);
});

View File

@@ -26,6 +26,7 @@ import java.util.concurrent.CompletableFuture;
@Slf4j
public class BotServiceBean implements BotService {
public static final String GUILD_NOT_FOUND = "Guild %s not found.";
private JDA instance;
@Override
@@ -58,7 +59,7 @@ public class BotServiceBean implements BotService {
}
}
else {
throw new GuildException(String.format("Guild %s not found.", serverId));
throw new GuildException(String.format(GUILD_NOT_FOUND, serverId));
}
}
@@ -68,7 +69,7 @@ public class BotServiceBean implements BotService {
if(guildById != null) {
return guildById.getMemberById(memberId);
} else {
throw new RuntimeException(String.format("Guild %s not found.", serverId));
throw new GuildException(String.format(GUILD_NOT_FOUND, serverId));
}
}
@@ -78,7 +79,7 @@ public class BotServiceBean implements BotService {
if(guildById != null) {
return isUserInGuild(guildById, aUserInAServer);
} else {
throw new RuntimeException(String.format("Guild %s not found.", aUserInAServer.getServerReference().getId()));
throw new GuildException(String.format(GUILD_NOT_FOUND, aUserInAServer.getServerReference().getId()));
}
}
@@ -120,7 +121,7 @@ public class BotServiceBean implements BotService {
Emote emoteById = guild.getEmoteById(emote.getEmoteId());
return Optional.ofNullable(emoteById);
}
throw new GuildException(String.format("Not able to find server %s", serverId));
throw new GuildException(String.format(GUILD_NOT_FOUND, serverId));
}
@Override
@@ -135,7 +136,7 @@ public class BotServiceBean implements BotService {
Guild guild = guildOptional.get();
return Optional.ofNullable(guild.getTextChannelById(textChannelId));
}
throw new GuildException(String.format("Not able to find guild %s", serverId));
throw new GuildException(String.format(GUILD_NOT_FOUND, serverId));
}
@Override
@@ -143,6 +144,11 @@ public class BotServiceBean implements BotService {
return Optional.ofNullable(instance.getGuildById(serverId));
}
@Override
public Guild getGuildByIdNullable(Long serverId) {
return instance.getGuildById(serverId);
}
@Override
public void shutdown() {

View File

@@ -18,6 +18,9 @@ import org.springframework.stereotype.Component;
@Component
public class ChannelGroupServiceBean implements ChannelGroupService {
private static final String CHANNEL_GROUP_NOT_FOUND = "Channel group %s was not found.";
private static final String COMMAND_NOT_FOUND = "Command %s not found.";
@Autowired
private ChannelGroupManagementService channelGroupManagementService;
@@ -61,7 +64,7 @@ public class ChannelGroupServiceBean implements ChannelGroupService {
AServer server = serverManagementService.loadOrCreate(channel.getServer().getId());
AChannelGroup channelGroup = channelGroupManagementService.findByNameAndServer(channelGroupName, server);
if(channelGroup == null) {
throw new ChannelGroupException(String.format("Channel group %s was not found.", channelGroupName));
throw new ChannelGroupException(String.format(CHANNEL_GROUP_NOT_FOUND, channelGroupName));
}
channelGroupManagementService.addChannelToChannelGroup(channelGroup, channel);
}
@@ -82,7 +85,7 @@ public class ChannelGroupServiceBean implements ChannelGroupService {
AServer server = serverManagementService.loadOrCreate(channel.getServer().getId());
AChannelGroup channelGroup = channelGroupManagementService.findByNameAndServer(channelGroupName, server);
if(channelGroup == null) {
throw new ChannelGroupException(String.format("Channel group %s was not found", channelGroupName));
throw new ChannelGroupException(String.format(CHANNEL_GROUP_NOT_FOUND, channelGroupName));
}
channelGroupManagementService.removeChannelFromChannelGroup(channelGroup, channel);
}
@@ -92,11 +95,11 @@ public class ChannelGroupServiceBean implements ChannelGroupService {
AServer server = serverManagementService.loadOrCreate(serverId);
AChannelGroup channelGroup = channelGroupManagementService.findByNameAndServer(channelGroupName, server);
if(channelGroup == null) {
throw new ChannelGroupException(String.format("Channel group %s was not found", channelGroupName));
throw new ChannelGroupException(String.format(CHANNEL_GROUP_NOT_FOUND, channelGroupName));
}
ACommand command = commandManagementService.findCommandByName(commandName);
if(command == null) {
throw new CommandException(String.format("Command %s not found.", commandName));
throw new CommandException(String.format(COMMAND_NOT_FOUND, commandName));
}
channelGroupCommandManagementService.setCommandInGroupTo(command, channelGroup, false);
}
@@ -106,11 +109,11 @@ public class ChannelGroupServiceBean implements ChannelGroupService {
AServer server = serverManagementService.loadOrCreate(serverId);
AChannelGroup channelGroup = channelGroupManagementService.findByNameAndServer(channelGroupName, server);
if(channelGroup == null) {
throw new ChannelGroupException(String.format("Channel group %s was not found", channelGroupName));
throw new ChannelGroupException(String.format(CHANNEL_GROUP_NOT_FOUND, channelGroupName));
}
ACommand command = commandManagementService.findCommandByName(commandName);
if(command == null) {
throw new CommandException(String.format("Command %s not found.", commandName));
throw new CommandException(String.format(COMMAND_NOT_FOUND, commandName));
}
channelGroupCommandManagementService.setCommandInGroupTo(command, channelGroup, true);
}

View File

@@ -95,17 +95,17 @@ public class ChannelServiceBean implements ChannelService {
String messageText = messageToSend.getMessage();
List<CompletableFuture<Message>> futures = new ArrayList<>();
if(StringUtils.isBlank(messageText)) {
messageToSend.getEmbeds().forEach(embed -> {
futures.add(sendEmbedInAChannelFuture(embed, textChannel));
});
messageToSend.getEmbeds().forEach(embed ->
futures.add(sendEmbedInAChannelFuture(embed, textChannel))
);
} else {
MessageAction messageAction = textChannel.sendMessage(messageText);
if(messageToSend.getEmbeds() != null && messageToSend.getEmbeds().size() > 0) {
if(messageToSend.getEmbeds() != null && !messageToSend.getEmbeds().isEmpty()) {
CompletableFuture<Message> messageFuture = messageAction.embed(messageToSend.getEmbeds().get(0)).submit();
futures.add(messageFuture);
messageToSend.getEmbeds().stream().skip(1).forEach(embed -> {
futures.add(sendEmbedInAChannelFuture(embed, textChannel));
});
messageToSend.getEmbeds().stream().skip(1).forEach(embed ->
futures.add(sendEmbedInAChannelFuture(embed, textChannel))
);
} else {
futures.add(messageAction.submit());
}
@@ -134,11 +134,11 @@ public class ChannelServiceBean implements ChannelService {
MessageAction messageAction;
if(!StringUtils.isBlank(messageToSend.getMessage())) {
messageAction = channel.editMessageById(messageId, messageToSend.getMessage());
if(messageToSend.getEmbeds() != null && messageToSend.getEmbeds().size() > 0) {
if(messageToSend.getEmbeds() != null && !messageToSend.getEmbeds().isEmpty()) {
messageAction = messageAction.embed(messageToSend.getEmbeds().get(0));
}
} else {
if(messageToSend.getEmbeds() != null && messageToSend.getEmbeds().size() > 0) {
if(messageToSend.getEmbeds() != null && !messageToSend.getEmbeds().isEmpty()) {
messageAction = channel.editMessageById(messageId, messageToSend.getEmbeds().get(0));
} else {
throw new AbstractoRunTimeException("Message to send did not contain anything to send.");

View File

@@ -80,9 +80,9 @@ public class MessageCacheBean implements MessageCache {
Optional<TextChannel> textChannelByIdOptional = botService.getTextChannelFromServer(guildOptional.get(), textChannelId);
if(textChannelByIdOptional.isPresent()) {
TextChannel textChannel = textChannelByIdOptional.get();
textChannel.retrieveMessageById(messageId).queue(message -> {
buildCachedMessageFromMessage(future, message);
});
textChannel.retrieveMessageById(messageId).queue(message ->
buildCachedMessageFromMessage(future, message)
);
} else {
log.error("Not able to load message {} in channel {} in guild {}. Text channel not found.", messageId, textChannelId, guildId);
future.completeExceptionally(new ChannelException(String.format("Not able to load message %s. Text channel %s not found in guild %s", messageId, textChannelId, guildId)));
@@ -98,13 +98,13 @@ public class MessageCacheBean implements MessageCache {
@Async
public void buildCachedMessageFromMessage(CompletableFuture<CachedMessage> future, Message message) {
List<String> attachmentUrls = new ArrayList<>();
message.getAttachments().forEach(attachment -> {
attachmentUrls.add(attachment.getProxyUrl());
});
message.getAttachments().forEach(attachment ->
attachmentUrls.add(attachment.getProxyUrl())
);
List<CachedEmbed> embeds = new ArrayList<>();
message.getEmbeds().forEach(embed -> {
embeds.add(getCachedEmbedFromEmbed(embed));
});
message.getEmbeds().forEach(embed ->
embeds.add(getCachedEmbedFromEmbed(embed))
);
List<CompletableFuture<CachedReaction>> futures = new ArrayList<>();
message.getReactions().forEach(messageReaction -> {
@@ -113,7 +113,7 @@ public class MessageCacheBean implements MessageCache {
futures.add(future1);
});
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).thenAccept(aVoid -> {
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).thenAccept(aVoid ->
future.complete(CachedMessage.builder()
.authorId(message.getAuthor().getIdLong())
.serverId(message.getGuild().getIdLong())
@@ -124,8 +124,8 @@ public class MessageCacheBean implements MessageCache {
.reactions(getFutures(futures))
.timeCreated(Instant.from(message.getTimeCreated()))
.attachmentUrls(attachmentUrls)
.build());
});
.build())
);
}
private List<CachedReaction> getFutures(List<CompletableFuture<CachedReaction>> futures) {

View File

@@ -88,9 +88,9 @@ public class MessageServiceBean implements MessageService {
public void sendMessageToUser(User user, String text, TextChannel feedbackChannel) {
CompletableFuture<Message> messageFuture = new CompletableFuture<>();
user.openPrivateChannel().queue(privateChannel -> {
privateChannel.sendMessage(text).queue(messageFuture::complete, messageFuture::completeExceptionally);
});
user.openPrivateChannel().queue(privateChannel ->
privateChannel.sendMessage(text).queue(messageFuture::complete, messageFuture::completeExceptionally)
);
messageFuture.exceptionally(e -> {
log.warn("Failed to send message. ", e);

View File

@@ -119,10 +119,10 @@ public class PostTargetServiceBean implements PostTargetService {
existingMessage -> existingMessage
.editMessage(messageToSend.getEmbeds().get(0))
.submit().thenAccept(message -> future.get(0).complete(message)),
throwable -> {
throwable ->
sendEmbedInPostTarget(messageToSend, target).get(0)
.thenAccept(message -> future.get(0).complete(message));
});
.thenAccept(message -> future.get(0).complete(message))
);
} else {
textChannelForPostTarget
.retrieveMessageById(messageId)
@@ -131,10 +131,10 @@ public class PostTargetServiceBean implements PostTargetService {
.editMessage(messageToSend.getMessage())
.embed(messageToSend.getEmbeds().get(0))
.submit().thenAccept(message -> future.get(0).complete(message)),
throwable -> {
throwable ->
sendEmbedInPostTarget(messageToSend, target).get(0)
.thenAccept(message -> future.get(0).complete(message));
});
.thenAccept(message -> future.get(0).complete(message))
);
}
}
@@ -145,7 +145,7 @@ public class PostTargetServiceBean implements PostTargetService {
}
@Override
public void throwIfPostTargetIsNotDefined(String name, Long serverId) throws ChannelException {
public void throwIfPostTargetIsNotDefined(String name, Long serverId) {
PostTarget postTarget = postTargetManagement.getPostTarget(name, serverId);
if(postTarget == null) {
throw new ChannelException(String.format("Post target %s is not defined.", name));

View File

@@ -73,9 +73,9 @@ public class StartupServiceBean implements Startup {
if(newGuild != null){
synchronizeRolesOf(newGuild, newAServer);
synchronizeChannelsOf(newGuild, newAServer);
configListeners.forEach(serverConfigListener -> {
serverConfigListener.updateServerConfig(newAServer);
});
configListeners.forEach(serverConfigListener ->
serverConfigListener.updateServerConfig(newAServer)
);
}
});
@@ -108,8 +108,8 @@ public class StartupServiceBean implements Startup {
});
Set<Long> noLongAvailable = SetUtils.difference(knownChannelsIds, existingChannelsIds);
noLongAvailable.forEach(aLong -> {
channelManagementService.markAsDeleted(aLong);
});
noLongAvailable.forEach(aLong ->
channelManagementService.markAsDeleted(aLong)
);
}
}

View File

@@ -8,6 +8,10 @@ import java.util.Set;
import java.util.stream.Collectors;
public class SnowflakeUtils {
private SnowflakeUtils() {
}
public static Set<Long> getOwnItemsIds(List<? extends SnowFlake> elements){
return elements.stream().map(SnowFlake::getId).collect(Collectors.toSet());
}

View File

@@ -4,6 +4,10 @@ import org.springframework.beans.factory.annotation.Value;
public class Constants {
private Constants() {
}
@Value("${abstracto.parameter.lowerBound}")
public static int PARAMETER_LIMIT = 0;
public static final int PARAMETER_LIMIT = 0;
}

View File

@@ -5,6 +5,8 @@ import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.listener.FeatureAware;
import java.io.Serializable;
public interface Command extends FeatureAware {
CommandResult execute(CommandContext commandContext);

View File

@@ -1,4 +1,4 @@
package dev.sheldan.abstracto.core.commands.utility;
package dev.sheldan.abstracto.core.command;
import dev.sheldan.abstracto.core.command.config.ModuleInterface;
import dev.sheldan.abstracto.core.command.config.ModuleInfo;

View File

@@ -17,9 +17,6 @@ public abstract class AbstractConditionableCommand implements ConditionalCommand
@Autowired
protected CommandDisabledCondition commandDisabledCondition;
@Autowired
protected ChannelService channelService;
@Autowired
protected CommandDisallowedCondition commandDisallowedCondition;

View File

@@ -5,19 +5,14 @@ import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.models.InsufficientPermissionMessage;
import dev.sheldan.abstracto.core.command.models.database.ACommand;
import dev.sheldan.abstracto.core.command.models.database.ACommandInAServer;
import dev.sheldan.abstracto.core.command.service.ChannelGroupCommandService;
import dev.sheldan.abstracto.core.command.service.CommandService;
import dev.sheldan.abstracto.core.command.service.management.CommandInServerManagementService;
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
import dev.sheldan.abstracto.core.models.database.ARole;
import dev.sheldan.abstracto.core.service.BotService;
import dev.sheldan.abstracto.core.service.RoleService;
import dev.sheldan.abstracto.templating.service.TemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.concurrent.locks.Condition;
@Component
public class CommandDisallowedCondition implements CommandCondition {

View File

@@ -1,8 +1,6 @@
package dev.sheldan.abstracto.core.command.config;
import dev.sheldan.abstracto.core.command.config.ModuleInfo;
public interface ModuleInterface {
ModuleInfo getInfo();
String getParentModule();

View File

@@ -8,9 +8,9 @@ import java.util.HashMap;
public class IncorrectParameter extends AbstractoRunTimeException implements Templatable {
private Command command;
private String parameterName;
private Class clazz;
private final Command command;
private final String parameterName;
private final Class clazz;
public IncorrectParameter(String s, Command command, Class expected, String parameterName) {
super(s);

View File

@@ -10,8 +10,8 @@ import java.util.HashMap;
@Getter
public class InsufficientParameters extends AbstractoRunTimeException implements Templatable {
private Command command;
private String parameterName;
private final Command command;
private final String parameterName;
public InsufficientParameters(String s, Command command, String parameterName) {
super(s);

View File

@@ -9,10 +9,10 @@ import java.util.HashMap;
public class ParameterTooLong extends AbstractoRunTimeException implements Templatable {
private Command command;
private String parameterName;
private Integer actualLength;
private Integer maximumLength;
private final Command command;
private final String parameterName;
private final Integer actualLength;
private final Integer maximumLength;
public ParameterTooLong(String s, Command command, String parameterName, Integer actualLength, Integer maximumLength) {
super(s);

View File

@@ -9,6 +9,10 @@ import java.lang.reflect.Method;
@Slf4j
public class ContextConverter {
private ContextConverter() {
}
public static <T extends UserInitiatedServerContext> UserInitiatedServerContext fromCommandContext(CommandContext commandContext, Class<T> clazz) {
Method m = null;
try {

View File

@@ -4,7 +4,6 @@ import dev.sheldan.abstracto.core.models.database.AFeature;
import lombok.*;
import javax.persistence.*;
import java.util.List;
@Entity
@Table(name = "command")

View File

@@ -7,8 +7,8 @@ import java.util.List;
public class FeatureNotFoundException extends AbstractoRunTimeException implements Templatable {
private String feature;
private List<String> availableFeatures;
private final String feature;
private final List<String> availableFeatures;
public FeatureNotFoundException(String message, String feature, List<String> availableFeatures) {
super(message);

View File

@@ -4,7 +4,6 @@ import lombok.*;
import javax.persistence.*;
import java.util.List;
import java.util.Set;
@Entity
@Table(name="channelGroup")

View File

@@ -1,6 +1,5 @@
package dev.sheldan.abstracto.core.models.database;
import dev.sheldan.abstracto.core.models.SnowFlake;
import lombok.*;
import javax.persistence.*;

View File

@@ -4,13 +4,14 @@ import dev.sheldan.abstracto.core.models.SnowFlake;
import lombok.*;
import javax.persistence.*;
import java.io.Serializable;
@Entity
@Table(name="role")
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ARole implements SnowFlake {
public class ARole implements SnowFlake, Serializable {
@Id
@Getter

View File

@@ -4,6 +4,7 @@ import dev.sheldan.abstracto.core.models.SnowFlake;
import lombok.*;
import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@@ -13,7 +14,7 @@ import java.util.List;
@NoArgsConstructor
@AllArgsConstructor
@Getter
public class AServer implements SnowFlake {
public class AServer implements SnowFlake, Serializable {
@Id
@Column(name = "id")

View File

@@ -3,6 +3,7 @@ package dev.sheldan.abstracto.core.models.database;
import lombok.*;
import javax.persistence.*;
import java.io.Serializable;
@Entity
@Getter
@@ -10,7 +11,7 @@ import javax.persistence.*;
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class AUserInAServer {
public class AUserInAServer implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)

View File

@@ -3,8 +3,6 @@ package dev.sheldan.abstracto.core.models.database;
import lombok.*;
import javax.persistence.*;
import java.util.Arrays;
import java.util.List;
@Entity
@Table(name="posttarget")

View File

@@ -1,7 +1,6 @@
package dev.sheldan.abstracto.core.models.template.commands;
import dev.sheldan.abstracto.core.models.context.UserInitiatedServerContext;
import dev.sheldan.abstracto.core.models.database.AFeatureFlag;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.SuperBuilder;

View File

@@ -28,5 +28,6 @@ public interface BotService {
Optional<TextChannel> getTextChannelFromServer(Guild serverId, Long textChannelId);
Optional<TextChannel> getTextChannelFromServer(Long serverId, Long textChannelId);
Optional<Guild> getGuildById(Long serverId);
Guild getGuildByIdNullable(Long serverId);
void shutdown();
}

View File

@@ -7,7 +7,6 @@ import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.User;
import java.util.List;
import java.util.concurrent.CompletableFuture;
public interface MessageService {

View File

@@ -1,7 +1,5 @@
package dev.sheldan.abstracto.core.service.management;
import dev.sheldan.abstracto.core.exception.ConfigurationException;
import dev.sheldan.abstracto.core.exception.PostTargetException;
import dev.sheldan.abstracto.core.models.database.AChannel;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.models.database.PostTarget;

View File

@@ -10,6 +10,10 @@ import java.util.Optional;
public class EmoteUtils {
private EmoteUtils() {
}
public static boolean isReactionEmoteAEmote(MessageReaction.ReactionEmote reaction, AEmote emote, Emote emoteInGuild) {
if(reaction.isEmote() && emote.getCustom()) {
if(emoteInGuild != null) {

View File

@@ -1,6 +1,11 @@
package dev.sheldan.abstracto.core.utils;
public class MessageUtils {
private MessageUtils() {
}
public static String buildMessageUrl(Long serverId, Long channelId, Long messageId) {
return String.format("https://discordapp.com/channels/%s/%s/%s", serverId, channelId, messageId);
}

View File

@@ -8,6 +8,10 @@ import java.util.regex.Pattern;
public class ParseUtils {
private ParseUtils() {
}
private static Pattern messageRegex = Pattern.compile("(?<number>\\d+)(?<unit>[ywdhms]+)");
public static Duration parseDuration(String textToParseFrom) {

View File

@@ -53,11 +53,11 @@ public class ContextUtilsTest {
@Test
public void testFromMessage() {
PingModel pingModel = (PingModel) classToTest.fromMessage(buildCachedMessage(), PingModel.class);
assertEquals(pingModel.getUser().getId(), AUTHOR_ID);
assertEquals(pingModel.getAUserInAServer().getUserReference().getId(), AUTHOR_ID);
assertEquals(pingModel.getAUserInAServer().getServerReference().getId(), SERVER_ID);
assertEquals(pingModel.getServer().getId(), SERVER_ID);
assertEquals(pingModel.getChannel().getId(), CHANNEL_ID);
assertEquals(AUTHOR_ID, pingModel.getUser().getId());
assertEquals(AUTHOR_ID, pingModel.getAUserInAServer().getUserReference().getId());
assertEquals(SERVER_ID, pingModel.getAUserInAServer().getServerReference().getId());
assertEquals(SERVER_ID, pingModel.getServer().getId());
assertEquals(CHANNEL_ID, pingModel.getChannel().getId());
}
private CachedMessage buildCachedMessage() {

View File

@@ -44,7 +44,7 @@ public class QuartzConfigFactory {
.build();
}
public Trigger createSimpleOnceOnlyTrigger(String triggerName, Date startTime) {
public Trigger createSimpleOnceOnlyTrigger(Date startTime) {
return newTrigger()
.startAt(startTime)
.withSchedule(simpleSchedule())

View File

@@ -84,7 +84,7 @@ public class SchedulerServiceBean implements SchedulerService {
if (job.getCronExpression() != null) {
newTrigger = scheduleCreator.createBasicCronTrigger(startDate, job.getCronExpression());
} else {
newTrigger = scheduleCreator.createSimpleOnceOnlyTrigger(job.getName(), startDate);
newTrigger = scheduleCreator.createSimpleOnceOnlyTrigger(startDate);
}
try {
schedulerFactoryBean.getScheduler().rescheduleJob(TriggerKey.triggerKey(job.getName()), newTrigger);

View File

@@ -36,7 +36,7 @@ public class TemplateSeedDataLoader {
log.trace("Creating template {}", templateKey);
service.createTemplate(templateKey, templateContent);
} catch (IOException e) {
e.printStackTrace();
log.error("Failed to upload template", e);
}
});
}

View File

@@ -36,10 +36,4 @@ public class InstantMethod implements TemplateMethodModelEx {
.withZone(ZoneId.systemDefault());
return formatter.format(duration);
}
private HashMap<String, Object> getParam(Long value) {
HashMap<String, Object> params = new HashMap<>();
params.put("amount", value);
return params;
}
}