mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-01-11 11:44:32 +00:00
Compare commits
35 Commits
abstracto-
...
abstracto-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
99e72245f3 | ||
|
|
9d184ff560 | ||
|
|
97895f5c56 | ||
|
|
f091559c49 | ||
|
|
fa7730975e | ||
|
|
03d7b9e2e2 | ||
|
|
a0bff12263 | ||
|
|
70e708601e | ||
|
|
f01418d0de | ||
|
|
ad539adb2a | ||
|
|
3c9fec989f | ||
|
|
21db3e3ee5 | ||
|
|
5b1ad2e075 | ||
|
|
63b3f68bdb | ||
|
|
7c1537c4a7 | ||
|
|
9836998087 | ||
|
|
8a1bb4cad8 | ||
|
|
a9dadec8ef | ||
|
|
3eaffaef87 | ||
|
|
b3a943e155 | ||
|
|
06dd4af131 | ||
|
|
0d51469975 | ||
|
|
aa10c88588 | ||
|
|
db27f64832 | ||
|
|
3903039aac | ||
|
|
41f42ee110 | ||
|
|
74f54e1257 | ||
|
|
a72e48f690 | ||
|
|
a813af8b1f | ||
|
|
abee7b2732 | ||
|
|
4c71ffbb7e | ||
|
|
18050e2a8a | ||
|
|
a0d83763d4 | ||
|
|
0461c8e4ec | ||
|
|
072f32975a |
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>anti-raid</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>anti-raid</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>assignable-roles</artifactId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>assignable-roles</artifactId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>assignable-roles-int</artifactId>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>custom-command</artifactId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>custom-command</artifactId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>dynamic-activity</artifactId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>dynamic-activity</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>entertainment</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>entertainment</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>experience-tracking</artifactId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
package dev.sheldan.abstracto.experience.command;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
|
||||
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||
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.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.interaction.InteractionService;
|
||||
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
|
||||
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||
import dev.sheldan.abstracto.experience.config.ExperienceFeatureDefinition;
|
||||
import dev.sheldan.abstracto.experience.config.ExperienceSlashCommandNames;
|
||||
import dev.sheldan.abstracto.experience.service.AUserExperienceService;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
public class ExpLevelUpNotification extends AbstractConditionableCommand {
|
||||
|
||||
private static final String FLAG_PARAMETER = "newValue";
|
||||
private static final String EXP_LEVEL_UP_NOTIFICATION_COMMAND = "expLevelUpNotification";
|
||||
private static final String EXP_LEVEL_UP_NOTIFICATION_RESPONSE = "expLevelUpNotification_response";
|
||||
|
||||
@Autowired
|
||||
private UserInServerManagementService userInServerManagementService;
|
||||
|
||||
@Autowired
|
||||
private AUserExperienceService aUserExperienceService;
|
||||
|
||||
@Autowired
|
||||
private InteractionService interactionService;
|
||||
|
||||
@Autowired
|
||||
private SlashCommandParameterService slashCommandParameterService;
|
||||
|
||||
@Override
|
||||
public CommandResult execute(CommandContext commandContext) {
|
||||
Boolean newValue = (Boolean) commandContext.getParameters().getParameters().get(0);
|
||||
updateExpLevelNotification(commandContext.getAuthor(), newValue);
|
||||
return CommandResult.fromSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||
Boolean newValue = slashCommandParameterService.getCommandOption(FLAG_PARAMETER, event, Boolean.class);
|
||||
updateExpLevelNotification(event.getMember(), newValue);
|
||||
return interactionService.replyEmbed(EXP_LEVEL_UP_NOTIFICATION_RESPONSE, event)
|
||||
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
private void updateExpLevelNotification(Member member, Boolean newValue) {
|
||||
AUserInAServer aUserInAServer = userInServerManagementService.loadOrCreateUser(member);
|
||||
aUserExperienceService.setLevelUpNotification(aUserInAServer, newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return ExperienceFeatureDefinition.EXPERIENCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
Parameter memberParameter = Parameter
|
||||
.builder()
|
||||
.name(FLAG_PARAMETER)
|
||||
.templated(true)
|
||||
.type(Boolean.class)
|
||||
.build();
|
||||
List<Parameter> parameters = Arrays.asList(memberParameter);
|
||||
HelpInfo helpInfo = HelpInfo
|
||||
.builder()
|
||||
.templated(true)
|
||||
.build();
|
||||
|
||||
SlashCommandConfig slashCommandConfig = SlashCommandConfig
|
||||
.builder()
|
||||
.enabled(true)
|
||||
.rootCommandName(ExperienceSlashCommandNames.EXPERIENCE)
|
||||
.commandName(EXP_LEVEL_UP_NOTIFICATION_COMMAND)
|
||||
.build();
|
||||
|
||||
return CommandConfiguration.builder()
|
||||
.name(EXP_LEVEL_UP_NOTIFICATION_COMMAND)
|
||||
.module(ExperienceModuleDefinition.EXPERIENCE)
|
||||
.slashCommandConfig(slashCommandConfig)
|
||||
.causesReaction(true)
|
||||
.supportsEmbedException(true)
|
||||
.templated(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -104,7 +104,17 @@ public class Rank extends AbstractConditionableCommand {
|
||||
AUserInAServer aUserInAServer = userInServerManagementService.loadOrCreateUser(toRender);
|
||||
AUserExperience experienceObj = userExperienceManagementService.findUserInServer(aUserInAServer);
|
||||
log.info("Rendering rank for user {} in server {}.", toRender.getId(), toRender.getGuild().getId());
|
||||
rankModel.setExperienceToNextLevel(experienceLevelService.calculateExperienceToNextLevel(experienceObj.getCurrentLevel().getLevel(), experienceObj.getExperience()));
|
||||
Long currentExpNeeded = experienceObj.getCurrentLevel().getExperienceNeeded();
|
||||
Long experienceNeededToNextLevel = experienceLevelService.calculateExperienceToNextLevel(experienceObj.getCurrentLevel().getLevel(), experienceObj.getExperience());
|
||||
Long nextLevelExperience = experienceLevelService.calculateNextLevel(experienceObj.getCurrentLevel().getLevel()).getExperienceNeeded();
|
||||
Long levelExperience = nextLevelExperience - currentExpNeeded;
|
||||
Long inLevelExperience = experienceObj.getExperience() - currentExpNeeded;
|
||||
rankModel.setExperienceForCurrentLevel(currentExpNeeded);
|
||||
rankModel.setCurrentLevelPercentage(((float) inLevelExperience / levelExperience) * 100);
|
||||
rankModel.setLevelExperience(levelExperience);
|
||||
rankModel.setExperienceToNextLevel(experienceNeededToNextLevel);
|
||||
rankModel.setInLevelExperience(inLevelExperience);
|
||||
rankModel.setNextLevelExperience(nextLevelExperience);
|
||||
return templateService.renderEmbedTemplate(RANK_POST_EMBED_TEMPLATE, rankModel, toRender.getGuild().getIdLong());
|
||||
}
|
||||
|
||||
|
||||
@@ -37,12 +37,16 @@ public class JoiningUserRoleListener implements AsyncJoinListener {
|
||||
|
||||
@Override
|
||||
public DefaultListenerResult execute(MemberJoinModel model) {
|
||||
if(model.getMember().isPending()) {
|
||||
log.info("Joining member {} in guild {} is still pending - ignoring for experience role assignment.", model.getJoiningUser().getUserId(), model.getJoiningUser().getServerId());
|
||||
return DefaultListenerResult.IGNORED;
|
||||
}
|
||||
Optional<AUserInAServer> userInAServerOptional = userInServerManagementService.loadUserOptional(model.getServerId(), model.getJoiningUser().getUserId());
|
||||
userInAServerOptional.ifPresent(aUserInAServer -> {
|
||||
Optional<AUserExperience> userExperienceOptional = userExperienceManagementService.findByUserInServerIdOptional(aUserInAServer.getUserInServerId());
|
||||
if(userExperienceOptional.isPresent()) {
|
||||
log.info("User {} joined {} with previous experience. Setting up experience role again (if necessary).", model.getJoiningUser().getUserId(), model.getServerId());
|
||||
userExperienceService.syncForSingleUser(userExperienceOptional.get(), model.getMember()).thenAccept(result ->
|
||||
userExperienceService.syncForSingleUser(userExperienceOptional.get(), model.getMember(), true).thenAccept(result ->
|
||||
log.info("Finished re-assigning experience for re-joining user {} in server {}.", model.getJoiningUser().getUserId(), model.getServerId())
|
||||
);
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package dev.sheldan.abstracto.experience.listener;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.listener.DefaultListenerResult;
|
||||
import dev.sheldan.abstracto.core.listener.async.jda.AsyncUpdatePendingListener;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.models.listener.MemberUpdatePendingModel;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||
import dev.sheldan.abstracto.experience.config.ExperienceFeatureDefinition;
|
||||
import dev.sheldan.abstracto.experience.model.database.AUserExperience;
|
||||
import dev.sheldan.abstracto.experience.service.AUserExperienceService;
|
||||
import dev.sheldan.abstracto.experience.service.management.UserExperienceManagementService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* If a {@link Member member} updates the pending status, this {@link AsyncUpdatePendingListener listener} retrieves the previously stored {@link AUserExperience experience} and gives the
|
||||
* member the necessary {@link net.dv8tion.jda.api.entities.Role role} according to the current configuration, if any
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class MemberPendingRoleListener implements AsyncUpdatePendingListener {
|
||||
|
||||
@Autowired
|
||||
private UserExperienceManagementService userExperienceManagementService;
|
||||
|
||||
@Autowired
|
||||
private AUserExperienceService userExperienceService;
|
||||
|
||||
@Autowired
|
||||
private UserInServerManagementService userInServerManagementService;
|
||||
|
||||
@Override
|
||||
public DefaultListenerResult execute(MemberUpdatePendingModel model) {
|
||||
Optional<AUserInAServer> userInAServerOptional = userInServerManagementService.loadUserOptional(model.getServerId(), model.getUser().getUserId());
|
||||
userInAServerOptional.ifPresent(aUserInAServer -> {
|
||||
Optional<AUserExperience> userExperienceOptional = userExperienceManagementService.findByUserInServerIdOptional(aUserInAServer.getUserInServerId());
|
||||
if(userExperienceOptional.isPresent()) {
|
||||
log.info("User {} updated pending status {} with previous experience. Setting up experience role again (if necessary).", model.getUser().getUserId(), model.getServerId());
|
||||
userExperienceService.syncForSingleUser(userExperienceOptional.get(), model.getMember(), true).thenAccept(result ->
|
||||
log.info("Finished re-assigning experience for update pending user {} in server {}.", model.getUser().getUserId(), model.getServerId())
|
||||
);
|
||||
} else {
|
||||
log.info("Member updating pending {} in server {} does not have any previous experience. Not setting up anything.", model.getUser().getUserId(), model.getServerId());
|
||||
}
|
||||
});
|
||||
|
||||
return DefaultListenerResult.PROCESSED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return ExperienceFeatureDefinition.EXPERIENCE;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -138,7 +138,10 @@ public class AUserExperienceServiceBean implements AUserExperienceService {
|
||||
// we store when the user is eligible for experience _again_
|
||||
Long maxSeconds = configService.getLongValueOrConfigDefault(EXP_COOLDOWN_SECONDS_KEY, serverId);
|
||||
serverExperience.put(userId, Instant.now().plus(maxSeconds, ChronoUnit.SECONDS));
|
||||
CompletableFuture.runAsync(() -> self.addExperienceToMember(member, message), experienceUpdateExecutor);
|
||||
CompletableFuture.runAsync(() -> self.addExperienceToMember(member, message), experienceUpdateExecutor).exceptionally(throwable -> {
|
||||
log.error("Failed to add experience to member {} in server {}.", message.getAuthor().getId(), message.getGuild().getIdLong(), throwable);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
runTimeExperienceService.releaseLock();
|
||||
@@ -252,17 +255,17 @@ public class AUserExperienceServiceBean implements AUserExperienceService {
|
||||
public CompletableFuture<Void> syncUser(Member member, List<AExperienceRole> roles) {
|
||||
AUserInAServer aUserInAServer = userInServerManagementService.loadOrCreateUser(member);
|
||||
AUserExperience userExperience = userExperienceManagementService.findByUserInServerId(aUserInAServer.getUserInServerId());
|
||||
return calculateAndApplyExperienceRole(userExperience, member, roles);
|
||||
return calculateAndApplyExperienceRole(userExperience, member, roles, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> syncForSingleUser(AUserExperience userExperience, Member member) {
|
||||
public CompletableFuture<Void> syncForSingleUser(AUserExperience userExperience, Member member, boolean forceRoles) {
|
||||
List<AExperienceRole> roles = experienceRoleManagementService.getExperienceRolesForServer(userExperience.getServer());
|
||||
roles.sort(Comparator.comparing(role -> role.getLevel().getLevel()));
|
||||
return calculateAndApplyExperienceRole(userExperience, member, roles);
|
||||
return calculateAndApplyExperienceRole(userExperience, member, roles, forceRoles);
|
||||
}
|
||||
|
||||
private CompletableFuture<Void> calculateAndApplyExperienceRole(AUserExperience userExperience, Member member, List<AExperienceRole> roles) {
|
||||
private CompletableFuture<Void> calculateAndApplyExperienceRole(AUserExperience userExperience, Member member, List<AExperienceRole> roles, boolean forceRoles) {
|
||||
AExperienceRole calculatedNewRole = experienceRoleService.calculateRole(roles, userExperience.getCurrentLevel().getLevel());
|
||||
Long oldRoleId = userExperience.getCurrentExperienceRole() != null && userExperience.getCurrentExperienceRole().getRole() != null ? userExperience.getCurrentExperienceRole().getRole().getId() : null;
|
||||
Long newRoleId = calculatedNewRole != null ? calculatedNewRole.getRole().getId() : null;
|
||||
@@ -270,15 +273,15 @@ public class AUserExperienceServiceBean implements AUserExperienceService {
|
||||
userExperience.setCurrentExperienceRole(calculatedNewRole);
|
||||
|
||||
CompletableFuture<Void> returningFuture;
|
||||
if(!Objects.equals(oldRoleId, newRoleId)) {
|
||||
if(!Objects.equals(oldRoleId, newRoleId) || forceRoles) {
|
||||
CompletableFuture<Void> addingFuture;
|
||||
if(oldRoleId != null) {
|
||||
if(oldRoleId != null || forceRoles) {
|
||||
addingFuture = roleService.removeRoleFromMemberAsync(member, oldRoleId);
|
||||
} else {
|
||||
addingFuture = CompletableFuture.completedFuture(null);
|
||||
}
|
||||
CompletableFuture<Void> removingFeature;
|
||||
if(newRoleId != null) {
|
||||
if(newRoleId != null || forceRoles) {
|
||||
removingFeature = roleService.addRoleToMemberAsync(member, newRoleId);
|
||||
} else {
|
||||
removingFeature = CompletableFuture.completedFuture(null);
|
||||
@@ -336,11 +339,13 @@ public class AUserExperienceServiceBean implements AUserExperienceService {
|
||||
oldLevel);
|
||||
aUserExperience.setCurrentLevel(newLevel);
|
||||
AExperienceRole calculatedNewRole = experienceRoleService.calculateRole(roles, newLevel.getLevel());
|
||||
Long oldRoleId = aUserExperience.getCurrentExperienceRole() != null ? aUserExperience.getCurrentExperienceRole().getRole().getId() : null;
|
||||
Long newRoleId = calculatedNewRole != null ? calculatedNewRole.getRole().getId() : null;
|
||||
Long oldRoleId = aUserExperience.getCurrentExperienceRole() != null && aUserExperience.getCurrentExperienceRole().getRole() != null ? aUserExperience.getCurrentExperienceRole().getRole().getId() : null;
|
||||
Long newRoleId = calculatedNewRole != null && calculatedNewRole.getRole() != null ? calculatedNewRole.getRole().getId() : null;
|
||||
result.setOldRoleId(oldRoleId);
|
||||
result.setNewRoleId(newRoleId);
|
||||
if(message != null && featureModeService.featureModeActive(ExperienceFeatureDefinition.EXPERIENCE, serverId, ExperienceFeatureMode.LEVEL_UP_NOTIFICATION)) {
|
||||
if(message != null
|
||||
&& aUserExperience.getLevelUpNotification()
|
||||
&& featureModeService.featureModeActive(ExperienceFeatureDefinition.EXPERIENCE, serverId, ExperienceFeatureMode.LEVEL_UP_NOTIFICATION)) {
|
||||
LevelUpNotificationModel model = LevelUpNotificationModel
|
||||
.builder()
|
||||
.memberDisplay(MemberDisplay.fromMember(member))
|
||||
@@ -429,6 +434,13 @@ public class AUserExperienceServiceBean implements AUserExperienceService {
|
||||
userExperience.setExperienceGainDisabled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLevelUpNotification(AUserInAServer aUserInAServer, Boolean newValue) {
|
||||
Optional<AUserExperience> aUserExperienceOptional = userExperienceManagementService.findByUserInServerIdOptional(aUserInAServer.getUserInServerId());
|
||||
AUserExperience aUserExperience = aUserExperienceOptional.orElseGet(() -> userExperienceManagementService.createUserInServer(aUserInAServer));
|
||||
aUserExperience.setLevelUpNotification(newValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a {@link MessageToSend messageToSend} to be used as a status message for the ongoing user synchronization
|
||||
* @param current The amount of users which have been synced
|
||||
|
||||
@@ -57,9 +57,14 @@ public class ExperienceLevelServiceBean implements ExperienceLevelService {
|
||||
|
||||
@Override
|
||||
public Long calculateExperienceToNextLevel(Integer level, Long currentExperience) {
|
||||
AExperienceLevel nextLevel = experienceLevelManagementService.getLevelOptional(level + 1)
|
||||
.orElseThrow(() -> new AbstractoRunTimeException(String.format("Could not find level %s", level)));
|
||||
AExperienceLevel nextLevel = calculateNextLevel(level);
|
||||
return nextLevel.getExperienceNeeded() - currentExperience;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AExperienceLevel calculateNextLevel(Integer level) {
|
||||
return experienceLevelManagementService.getLevelOptional(level + 1)
|
||||
.orElseThrow(() -> new AbstractoRunTimeException(String.format("Could not find level %s", level)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ public class UserExperienceManagementServiceBean implements UserExperienceManage
|
||||
.messageCount(0L)
|
||||
.server(aUserInAServer.getServerReference())
|
||||
.experienceGainDisabled(false)
|
||||
.levelUpNotification(true)
|
||||
.user(aUserInAServer)
|
||||
.id(aUserInAServer.getUserInServerId())
|
||||
.currentLevel(startingLevel)
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
|
||||
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
|
||||
<include file="tables/tables.xml" relativeToChangelogFile="true"/>
|
||||
<include file="seedData/data.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
|
||||
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
|
||||
<property name="experienceModule" value="(SELECT id FROM module WHERE name = 'experience')"/>
|
||||
<property name="experienceFeature" value="(SELECT id FROM feature WHERE key = 'experience')"/>
|
||||
<changeSet author="Sheldan" id="experience-expLevelUpNotification_command">
|
||||
<insert tableName="command">
|
||||
<column name="name" value="expLevelUpNotification"/>
|
||||
<column name="module_id" valueComputed="${experienceModule}"/>
|
||||
<column name="feature_id" valueComputed="${experienceFeature}"/>
|
||||
</insert>
|
||||
</changeSet>
|
||||
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
|
||||
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
|
||||
<include file="command.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
|
||||
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
|
||||
|
||||
<include file="user_experience.xml" relativeToChangelogFile="true"/>
|
||||
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
|
||||
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
|
||||
<changeSet author="Sheldan" id="user_experience-add_level_up_notification">
|
||||
<addColumn tableName="user_experience">
|
||||
<column name="level_up_notification" type="BOOLEAN" defaultValueBoolean="true"/>
|
||||
</addColumn>
|
||||
</changeSet>
|
||||
|
||||
</databaseChangeLog>
|
||||
@@ -9,4 +9,5 @@
|
||||
<include file="1.0-experience/collection.xml" relativeToChangelogFile="true"/>
|
||||
<include file="1.2.15/collection.xml" relativeToChangelogFile="true"/>
|
||||
<include file="1.4.8/collection.xml" relativeToChangelogFile="true"/>
|
||||
<include file="1.4.17/collection.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
@@ -67,7 +67,7 @@ public class JoiningUserRoleListenerTest {
|
||||
public void testUserWithExperienceRejoining() {
|
||||
AUserExperience experience = Mockito.mock(AUserExperience.class);
|
||||
when(userExperienceManagementService.findByUserInServerIdOptional(USER_IN_SERVER_ID)).thenReturn(Optional.of(experience));
|
||||
when(userExperienceService.syncForSingleUser(experience, member)).thenReturn(CompletableFuture.completedFuture(null));
|
||||
when(userExperienceService.syncForSingleUser(experience, member, true)).thenReturn(CompletableFuture.completedFuture(null));
|
||||
when(model.getMember()).thenReturn(member);
|
||||
DefaultListenerResult result = testUnit.execute(model);
|
||||
Assert.assertEquals(DefaultListenerResult.PROCESSED, result);
|
||||
@@ -75,9 +75,18 @@ public class JoiningUserRoleListenerTest {
|
||||
|
||||
@Test
|
||||
public void testUserWithOutExperienceRejoining() {
|
||||
when(model.getMember()).thenReturn(member);
|
||||
when(userExperienceManagementService.findByUserInServerIdOptional(USER_IN_SERVER_ID)).thenReturn(Optional.empty());
|
||||
testUnit.execute(model);
|
||||
verify(userExperienceService, times(0)).syncForSingleUser(any(), any());
|
||||
verify(userExperienceService, times(0)).syncForSingleUser(any(), any(), eq(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPendingUserJoining() {
|
||||
when(member.isPending()).thenReturn(true);
|
||||
when(model.getMember()).thenReturn(member);
|
||||
testUnit.execute(model);
|
||||
verify(userExperienceService, times(0)).syncForSingleUser(any(), any(), eq(true));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>experience-tracking</artifactId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -60,6 +60,9 @@ public class AUserExperience implements Serializable {
|
||||
@Column(name = "experience_gain_disabled", nullable = false)
|
||||
private Boolean experienceGainDisabled = false;
|
||||
|
||||
@Column(name = "level_up_notification")
|
||||
private Boolean levelUpNotification;
|
||||
|
||||
/**
|
||||
* The {@link AExperienceLevel level} which the user currently has.
|
||||
*/
|
||||
|
||||
@@ -23,6 +23,26 @@ public class RankModel {
|
||||
* The necessary experience to the next level up.
|
||||
*/
|
||||
private Long experienceToNextLevel;
|
||||
/**
|
||||
* Total experience needed for this level
|
||||
*/
|
||||
private Long experienceForCurrentLevel;
|
||||
/**
|
||||
* Percentage of progress within this level
|
||||
*/
|
||||
private Float currentLevelPercentage;
|
||||
/**
|
||||
* The total amount of experience needed for this level
|
||||
*/
|
||||
private Long levelExperience;
|
||||
/**
|
||||
* The experience which has been reached _within_ this level
|
||||
*/
|
||||
private Long inLevelExperience;
|
||||
/**
|
||||
* The experience needed to reach the next level
|
||||
*/
|
||||
private Long nextLevelExperience;
|
||||
/**
|
||||
* The member to show the rank for
|
||||
*/
|
||||
|
||||
@@ -44,7 +44,7 @@ public interface AUserExperienceService {
|
||||
|
||||
CompletableFuture<Void> syncUserRolesWithFeedback(AServer server, MessageChannel messageChannel);
|
||||
|
||||
CompletableFuture<Void> syncForSingleUser(AUserExperience userExperience, Member member);
|
||||
CompletableFuture<Void> syncForSingleUser(AUserExperience userExperience, Member member, boolean changeRoles);
|
||||
|
||||
/**
|
||||
* Loads the desired page of the ordered complete leaderboard from the {@link AServer} and returns the information as a {@link LeaderBoard}
|
||||
@@ -75,6 +75,7 @@ public interface AUserExperienceService {
|
||||
* @param userInAServer The {@link AUserInAServer} to enable experience for
|
||||
*/
|
||||
void enableExperienceForUser(AUserInAServer userInAServer);
|
||||
void setLevelUpNotification(AUserInAServer aUserInAServer, Boolean newValue);
|
||||
|
||||
boolean experienceGainEnabledInChannel(MessageChannel messageChannel);
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package dev.sheldan.abstracto.experience.service;
|
||||
|
||||
import dev.sheldan.abstracto.experience.model.database.AExperienceLevel;
|
||||
|
||||
/**
|
||||
* Service responsible for operations on {@link dev.sheldan.abstracto.experience.model.database.AExperienceLevel experienceLevel}
|
||||
* This includes creating and calculations.
|
||||
@@ -20,6 +22,7 @@ public interface ExperienceLevelService {
|
||||
* @return The amount of experience required necessary to reach the next level
|
||||
*/
|
||||
Long calculateExperienceToNextLevel(Integer level, Long currentExperience);
|
||||
AExperienceLevel calculateNextLevel(Integer level);
|
||||
|
||||
/**
|
||||
* Calculates the required experience to reach this level. This calculated experience is relative, in the sense that
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>invite-filter</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>invite-filter</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>link-embed</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>link-embed</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>logging</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>logging</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>moderation</artifactId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import net.dv8tion.jda.api.interactions.modals.ModalMapping;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static dev.sheldan.abstracto.moderation.service.ReactionReportServiceBean.REACTION_REPORT_FAILURE_RESPONSE_TEMPLATE;
|
||||
import static dev.sheldan.abstracto.moderation.service.ReactionReportServiceBean.REACTION_REPORT_RESPONSE_TEMPLATE;
|
||||
|
||||
@Component
|
||||
@@ -46,27 +47,35 @@ public class ReportContextModalListener implements ModalInteractionListener {
|
||||
.map(ModalMapping::getAsString)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
messageCache.getMessageFromCache(payload.getServerId(), payload.getChannelId(), payload.getMessageId()).thenAccept(cachedMessage -> {
|
||||
ServerUser userReporting = ServerUser
|
||||
.builder()
|
||||
.serverId(model.getServerId())
|
||||
.userId(cachedMessage.getAuthor().getAuthorId())
|
||||
.isBot(cachedMessage.getAuthor().getIsBot())
|
||||
.build();
|
||||
reactionReportService.createReactionReport(cachedMessage, userReporting, context)
|
||||
.thenAccept(unused -> {
|
||||
interactionService.replyEmbed(REACTION_REPORT_RESPONSE_TEMPLATE, new Object(), model.getEvent());
|
||||
log.info("Handled modal for message report with id {} in guild {} in channel {} on message {}",
|
||||
model.getEvent().getModalId(), payload.getServerId(), payload.getChannelId(), payload.getMessageId());
|
||||
componentPayloadManagementService.deletePayload(payload.getModalId());
|
||||
}).exceptionally(throwable -> {
|
||||
log.error("Failed to create reaction report in server {} on message {} in channel {} with interaction.",
|
||||
model.getServerId(), cachedMessage.getMessageId(), model.getEvent().getChannel().getIdLong(), throwable);
|
||||
model.getEvent().deferReply(true).queue(interactionHook -> {
|
||||
messageCache.getMessageFromCache(payload.getServerId(), payload.getChannelId(), payload.getMessageId()).thenAccept(cachedMessage -> {
|
||||
ServerUser userReporting = ServerUser
|
||||
.builder()
|
||||
.serverId(model.getServerId())
|
||||
.userId(cachedMessage.getAuthor().getAuthorId())
|
||||
.isBot(cachedMessage.getAuthor().getIsBot())
|
||||
.build();
|
||||
reactionReportService.createReactionReport(cachedMessage, userReporting, context)
|
||||
.thenAccept(unused -> {
|
||||
interactionService.sendMessageToInteraction(REACTION_REPORT_RESPONSE_TEMPLATE, new Object(), interactionHook);
|
||||
log.info("Handled modal for message report with id {} in guild {} in channel {} on message {}",
|
||||
model.getEvent().getModalId(), payload.getServerId(), payload.getChannelId(), payload.getMessageId());
|
||||
componentPayloadManagementService.deletePayload(payload.getModalId());
|
||||
}).exceptionally(throwable -> {
|
||||
interactionService.sendMessageToInteraction(REACTION_REPORT_FAILURE_RESPONSE_TEMPLATE, new Object(), interactionHook);
|
||||
log.error("Failed to create reaction report in server {} on message {} in channel {} with interaction.",
|
||||
model.getServerId(), cachedMessage.getMessageId(), model.getEvent().getChannel().getIdLong(), throwable);
|
||||
return null;
|
||||
});
|
||||
}).exceptionally(throwable -> {
|
||||
interactionService.sendMessageToInteraction(REACTION_REPORT_FAILURE_RESPONSE_TEMPLATE, new Object(), interactionHook);
|
||||
log.error("Failed to load reported message for reporting message {} in channel {} with context.",
|
||||
model.getEvent().getMessage().getIdLong(), model.getEvent().getChannel().getIdLong(), throwable);
|
||||
return null;
|
||||
});
|
||||
}).exceptionally(throwable -> {
|
||||
log.error("Failed to load reported message.", throwable);
|
||||
return null;
|
||||
}, throwable -> {
|
||||
log.error("Failed to acknowledge modal interaction for report context modal listener in guild {} on message {}.", model.getServerId(),
|
||||
model.getEvent().getMessage() != null ? model.getEvent().getMessage().getIdLong() : 0, throwable);
|
||||
});
|
||||
|
||||
return ModalInteractionListenerResult.ACKNOWLEDGED;
|
||||
|
||||
@@ -71,6 +71,7 @@ public class ReactionReportServiceBean implements ReactionReportService {
|
||||
private static final String REACTION_REPORT_TEMPLATE_KEY = "reactionReport_notification";
|
||||
public static final String REACTION_REPORT_MODAL_ORIGIN = "reportMessageModal";
|
||||
public static final String REACTION_REPORT_RESPONSE_TEMPLATE = "reactionReport_response";
|
||||
public static final String REACTION_REPORT_FAILURE_RESPONSE_TEMPLATE = "reactionReport_failure_response";
|
||||
public static final String REACTION_REPORT_COOLDOWN_RESPONSE_TEMPLATE = "reactionReport_cooldown_response";
|
||||
public static final String REACTION_REPORT_OWN_MESSAGE_RESPONSE_TEMPLATE = "reactionReport_own_message_response";
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>moderation</artifactId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>modmail</artifactId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>modmail</artifactId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto</groupId>
|
||||
<artifactId>abstracto-application</artifactId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>profanity-filter</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>profanity-filter</artifactId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>remind</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>remind</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>repost-detection</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>repost-detection</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>starboard</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>starboard</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>statistic</artifactId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>statistic</artifactId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>suggestion</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -29,6 +29,8 @@ import dev.sheldan.abstracto.suggestion.service.management.SuggestionManagementS
|
||||
import dev.sheldan.abstracto.suggestion.service.management.SuggestionVoteManagementService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.*;
|
||||
import net.dv8tion.jda.api.entities.channel.attribute.IThreadContainer;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -37,9 +39,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
@@ -131,6 +131,7 @@ public class SuggestionServiceBean implements SuggestionService {
|
||||
if(autoEvaluationEnabled) {
|
||||
autoEvaluateDays = configService.getLongValueOrConfigDefault(SUGGESTION_AUTO_EVALUATE_DAYS_CONFIG_KEY, serverId);
|
||||
}
|
||||
Instant autoEvaluationTargetDate = autoEvaluationEnabled ? Instant.now().plus(autoEvaluateDays, ChronoUnit.DAYS) : null;
|
||||
SuggestionLog model = SuggestionLog
|
||||
.builder()
|
||||
.suggestionId(newSuggestionId)
|
||||
@@ -143,7 +144,7 @@ public class SuggestionServiceBean implements SuggestionService {
|
||||
.suggester(suggester.getUser())
|
||||
.text(text)
|
||||
.autoEvaluationEnabled(autoEvaluationEnabled)
|
||||
.autoEvaluationTargetDate(autoEvaluationEnabled ? Instant.now().plus(autoEvaluateDays, ChronoUnit.DAYS) : null)
|
||||
.autoEvaluationTargetDate(autoEvaluationTargetDate)
|
||||
.build();
|
||||
if(useButtons) {
|
||||
setupButtonIds(model);
|
||||
@@ -151,32 +152,73 @@ public class SuggestionServiceBean implements SuggestionService {
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate(SUGGESTION_CREATION_TEMPLATE, model, serverId);
|
||||
log.info("Creating suggestion with id {} in server {} from member {}.", newSuggestionId, serverId, suggester.getIdLong());
|
||||
List<CompletableFuture<Message>> completableFutures = postTargetService.sendEmbedInPostTarget(messageToSend, SuggestionPostTarget.SUGGESTION, serverId);
|
||||
List<ButtonConfigModel> buttonConfigModels = Arrays.asList(model.getAgreeButtonModel(), model.getDisAgreeButtonModel(), model.getRemoveVoteButtonModel());
|
||||
return FutureUtils.toSingleFutureGeneric(completableFutures)
|
||||
.thenCompose(aVoid -> self.addDeletionPossibility(suggestionChannelId, suggestionMessageId, text, suggester, serverId, newSuggestionId, completableFutures, model));
|
||||
.thenCompose(aVoid -> self.addVotingPossibility(suggestionChannelId, suggestionMessageId, text, suggester, serverId, newSuggestionId, completableFutures, buttonConfigModels, useButtons))
|
||||
.thenCompose(aVoid -> self.createSuggestionThread(serverId, newSuggestionId, suggester, text, autoEvaluationEnabled, autoEvaluationTargetDate));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public CompletableFuture<Void> addDeletionPossibility(Long suggestionChannelId, Long suggestionMessageId, String text, Member suggester, Long serverId,
|
||||
Long newSuggestionId, List<CompletableFuture<Message>> completableFutures, SuggestionLog model) {
|
||||
Message message = completableFutures.get(0).join();
|
||||
if(model.getUseButtons()) {
|
||||
configureDecisionButtonPayload(serverId, newSuggestionId, model.getAgreeButtonModel(), SuggestionDecision.AGREE);
|
||||
configureDecisionButtonPayload(serverId, newSuggestionId, model.getDisAgreeButtonModel(), SuggestionDecision.DISAGREE);
|
||||
configureDecisionButtonPayload(serverId, newSuggestionId, model.getRemoveVoteButtonModel(), SuggestionDecision.REMOVE_VOTE);
|
||||
AServer server = serverManagementService.loadServer(serverId);
|
||||
componentPayloadManagementService.createButtonPayload(model.getAgreeButtonModel(), server);
|
||||
componentPayloadManagementService.createButtonPayload(model.getDisAgreeButtonModel(), server);
|
||||
componentPayloadManagementService.createButtonPayload(model.getRemoveVoteButtonModel(), server);
|
||||
self.persistSuggestionInDatabase(suggester, text, message, newSuggestionId, suggestionChannelId, suggestionMessageId);
|
||||
return CompletableFuture.completedFuture(null);
|
||||
public CompletableFuture<Void> createSuggestionThread(Long serverId, Long suggestionId, Member suggester, String suggestionText,
|
||||
Boolean autoEvaluationEnabled, Instant autoEvaluationTargetDate) {
|
||||
if(featureModeService.featureModeActive(SuggestionFeatureDefinition.SUGGEST, serverId, SuggestionFeatureMode.SUGGESTION_THREAD)) {
|
||||
Optional<GuildMessageChannel> suggestionTargetChannelOptional = postTargetService.getPostTargetChannel(SuggestionPostTarget.SUGGESTION, serverId);
|
||||
log.info("Trying to create thread for suggestion {} in server {}.", suggestionId, serverId);
|
||||
if (suggestionTargetChannelOptional.isPresent()) {
|
||||
GuildMessageChannel messageChannel = suggestionTargetChannelOptional.get();
|
||||
if(messageChannel instanceof IThreadContainer) {
|
||||
SuggestionThreadModel model = SuggestionThreadModel
|
||||
.builder()
|
||||
.suggestionId(suggestionId)
|
||||
.suggester(suggester.getUser())
|
||||
.member(suggester)
|
||||
.autoEvaluationEnabled(autoEvaluationEnabled)
|
||||
.text(suggestionText)
|
||||
.autoEvaluationTargetDate(autoEvaluationTargetDate)
|
||||
.build();
|
||||
IThreadContainer threadContainer = (IThreadContainer) messageChannel;
|
||||
String threadName = templateService.renderTemplate("suggestion_thread_name", model, serverId);
|
||||
return threadContainer.createThreadChannel(threadName).submit()
|
||||
.thenAccept(threadChannel -> log.info("Created thread for suggestion {} in server {}.", suggestionId, serverId));
|
||||
} else {
|
||||
log.info("Suggestion thread was not created - post target for suggestions does not allow to create threads");
|
||||
}
|
||||
} else {
|
||||
log.info("Suggestion thread was not created - post target did not evaluate to a channel or post target is disabled.");
|
||||
}
|
||||
} else {
|
||||
log.debug("Posted message, adding reaction for suggestion {} to message {}.", newSuggestionId, message.getId());
|
||||
CompletableFuture<Void> firstReaction = reactionService.addReactionToMessageAsync(SUGGESTION_YES_EMOTE, serverId, message);
|
||||
CompletableFuture<Void> secondReaction = reactionService.addReactionToMessageAsync(SUGGESTION_NO_EMOTE, serverId, message);
|
||||
return CompletableFuture.allOf(firstReaction, secondReaction).thenAccept(aVoid1 -> {
|
||||
log.debug("Reaction added to message {} for suggestion {}.", message.getId(), newSuggestionId);
|
||||
log.info("Suggestion thread feature disabled - not creating thread for suggestion {} in server {}.", suggestionId, serverId);
|
||||
}
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public CompletableFuture<Void> addVotingPossibility(Long suggestionChannelId, Long suggestionMessageId, String text, Member suggester, Long serverId,
|
||||
Long newSuggestionId, List<CompletableFuture<Message>> completableFutures, List<ButtonConfigModel> buttonConfigModels,
|
||||
Boolean useButtons) {
|
||||
if(!completableFutures.isEmpty()) {
|
||||
Message message = completableFutures.get(0).join();
|
||||
if(useButtons) {
|
||||
configureDecisionButtonPayload(serverId, newSuggestionId, buttonConfigModels.get(0), SuggestionDecision.AGREE);
|
||||
configureDecisionButtonPayload(serverId, newSuggestionId, buttonConfigModels.get(1), SuggestionDecision.DISAGREE);
|
||||
configureDecisionButtonPayload(serverId, newSuggestionId, buttonConfigModels.get(2), SuggestionDecision.REMOVE_VOTE);
|
||||
AServer server = serverManagementService.loadServer(serverId);
|
||||
componentPayloadManagementService.createButtonPayload(buttonConfigModels.get(0), server);
|
||||
componentPayloadManagementService.createButtonPayload(buttonConfigModels.get(1), server);
|
||||
componentPayloadManagementService.createButtonPayload(buttonConfigModels.get(2), server);
|
||||
self.persistSuggestionInDatabase(suggester, text, message, newSuggestionId, suggestionChannelId, suggestionMessageId);
|
||||
});
|
||||
return CompletableFuture.completedFuture(null);
|
||||
} else {
|
||||
log.debug("Posted message, adding reaction for suggestion {} to message {}.", newSuggestionId, message.getId());
|
||||
CompletableFuture<Void> firstReaction = reactionService.addReactionToMessageAsync(SUGGESTION_YES_EMOTE, serverId, message);
|
||||
CompletableFuture<Void> secondReaction = reactionService.addReactionToMessageAsync(SUGGESTION_NO_EMOTE, serverId, message);
|
||||
return CompletableFuture.allOf(firstReaction, secondReaction).thenAccept(aVoid1 -> {
|
||||
log.debug("Reaction added to message {} for suggestion {}.", message.getId(), newSuggestionId);
|
||||
self.persistSuggestionInDatabase(suggester, text, message, newSuggestionId, suggestionChannelId, suggestionMessageId);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,14 +317,23 @@ public class SuggestionServiceBean implements SuggestionService {
|
||||
Long serverId = suggestion.getServer().getId();
|
||||
Long channelId = suggestion.getChannel().getId();
|
||||
Long originalMessageId = suggestion.getMessageId();
|
||||
boolean buttonsActive = featureModeService.featureModeActive(SuggestionFeatureDefinition.SUGGEST, serverId, SuggestionFeatureMode.SUGGESTION_BUTTONS);
|
||||
Long agreements = suggestionVoteManagementService.getDecisionsForSuggestion(suggestion, SuggestionDecision.AGREE);
|
||||
Long disagreements = suggestionVoteManagementService.getDecisionsForSuggestion(suggestion, SuggestionDecision.DISAGREE);
|
||||
Long suggestionId = suggestion.getSuggestionId().getId();
|
||||
Long totalVotes = disagreements + agreements;
|
||||
float agreementPercentage = 0;
|
||||
float disAgreementPercentage = 0;
|
||||
if(totalVotes > 0) {
|
||||
agreementPercentage = (((float) agreements) / totalVotes) * 100;
|
||||
disAgreementPercentage = 100f - agreementPercentage;
|
||||
}
|
||||
SuggestionUpdateModel model = SuggestionUpdateModel
|
||||
.builder()
|
||||
.suggestionId(suggestionId)
|
||||
.state(suggestion.getState())
|
||||
.serverId(serverId)
|
||||
.buttonsActive(buttonsActive)
|
||||
.member(memberExecutingCommand)
|
||||
.agreeVotes(agreements)
|
||||
.disAgreeVotes(disagreements)
|
||||
@@ -290,6 +341,9 @@ public class SuggestionServiceBean implements SuggestionService {
|
||||
.text(suggestion.getSuggestionText())
|
||||
.originalChannelId(channelId)
|
||||
.reason(reason)
|
||||
.totalVotes(totalVotes)
|
||||
.agreementPercentage(agreementPercentage)
|
||||
.disAgreementPercentage(disAgreementPercentage)
|
||||
.build();
|
||||
log.info("Updated posted suggestion {} in server {}.", suggestionId, suggestion.getServer().getId());
|
||||
CompletableFuture<User> memberById = userService.retrieveUserForId(suggestion.getSuggester().getUserReference().getId());
|
||||
|
||||
@@ -11,6 +11,10 @@ abstracto.featureModes.suggestionReminder.featureName=suggestion
|
||||
abstracto.featureModes.suggestionReminder.mode=suggestionReminder
|
||||
abstracto.featureModes.suggestionReminder.enabled=false
|
||||
|
||||
abstracto.featureModes.suggestionThread.featureName=suggestion
|
||||
abstracto.featureModes.suggestionThread.mode=suggestionThread
|
||||
abstracto.featureModes.suggestionThread.enabled=false
|
||||
|
||||
abstracto.systemConfigs.suggestionReminderDays.name=suggestionReminderDays
|
||||
abstracto.systemConfigs.suggestionReminderDays.longValue=7
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>suggestion</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -36,7 +36,8 @@ public class SuggestionFeatureConfig implements FeatureConfig {
|
||||
return Arrays.asList(
|
||||
SuggestionFeatureMode.SUGGESTION_REMINDER,
|
||||
SuggestionFeatureMode.SUGGESTION_BUTTONS,
|
||||
SuggestionFeatureMode.SUGGESTION_AUTO_EVALUATE);
|
||||
SuggestionFeatureMode.SUGGESTION_AUTO_EVALUATE,
|
||||
SuggestionFeatureMode.SUGGESTION_THREAD);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,7 +5,10 @@ import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum SuggestionFeatureMode implements FeatureMode {
|
||||
SUGGESTION_REMINDER("suggestionReminder"), SUGGESTION_BUTTONS("suggestionButton"), SUGGESTION_AUTO_EVALUATE("suggestionAutoEvaluate");
|
||||
SUGGESTION_REMINDER("suggestionReminder"),
|
||||
SUGGESTION_BUTTONS("suggestionButton"),
|
||||
SUGGESTION_AUTO_EVALUATE("suggestionAutoEvaluate"),
|
||||
SUGGESTION_THREAD("suggestionThread");
|
||||
|
||||
private final String key;
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package dev.sheldan.abstracto.suggestion.model.template;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public class SuggestionThreadModel {
|
||||
private Long suggestionId;
|
||||
private User suggester;
|
||||
private Member member;
|
||||
private String text;
|
||||
private Long serverId;
|
||||
private Instant autoEvaluationTargetDate;
|
||||
private Boolean autoEvaluationEnabled;
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import net.dv8tion.jda.api.entities.User;
|
||||
public class SuggestionUpdateModel {
|
||||
private Long suggestionId;
|
||||
private SuggestionState state;
|
||||
private Boolean buttonsActive;
|
||||
private User suggester;
|
||||
private Member member;
|
||||
private String text;
|
||||
@@ -25,6 +26,9 @@ public class SuggestionUpdateModel {
|
||||
private Long originalMessageId;
|
||||
private Long agreeVotes;
|
||||
private Long disAgreeVotes;
|
||||
private Long totalVotes;
|
||||
private Float agreementPercentage;
|
||||
private Float disAgreementPercentage;
|
||||
|
||||
public String getOriginalMessageUrl() {
|
||||
return MessageUtils.buildMessageUrl(serverId, originalChannelId , originalMessageId);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>utility</artifactId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>utility</artifactId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>voice-channel-context</artifactId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>voice-channel-context</artifactId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>abstracto-modules</artifactId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>webservices</artifactId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.modules</groupId>
|
||||
<artifactId>webservices</artifactId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto</groupId>
|
||||
<artifactId>abstracto-application</artifactId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.core</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
@@ -22,6 +22,11 @@ public class ListenerExecutorConfig {
|
||||
return executorService.setupExecutorFor("joinListener");
|
||||
}
|
||||
|
||||
@Bean(name = "memberPendingUpdateExecutor")
|
||||
public TaskExecutor memberPendingUpdateExecutor() {
|
||||
return executorService.setupExecutorFor("memberPendingUpdateListener");
|
||||
}
|
||||
|
||||
@Bean(name = "leaveListenerExecutor")
|
||||
public TaskExecutor leaveListenerExecutor() {
|
||||
return executorService.setupExecutorFor("leaveListener");
|
||||
|
||||
@@ -9,8 +9,8 @@ import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
||||
import net.dv8tion.jda.api.events.interaction.command.GenericCommandInteractionEvent;
|
||||
import net.dv8tion.jda.api.interactions.components.ActionRow;
|
||||
import net.dv8tion.jda.api.interactions.components.ItemComponent;
|
||||
import net.dv8tion.jda.api.interactions.components.Modal;
|
||||
import net.dv8tion.jda.api.interactions.components.text.TextInput;
|
||||
import net.dv8tion.jda.api.interactions.modals.Modal;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
@@ -62,8 +62,6 @@ public class ModalInteractionListenerBean extends ListenerAdapter {
|
||||
@Override
|
||||
public void onModalInteraction(@Nonnull ModalInteractionEvent event) {
|
||||
if(listenerList == null) return;
|
||||
// TODO remove this and make this configurable
|
||||
event.deferEdit().queue();
|
||||
CompletableFuture.runAsync(() -> self.executeListenerLogic(event), modalInteractionExecutor).exceptionally(throwable -> {
|
||||
log.error("Failed to execute listener logic in modal interaction event.", throwable);
|
||||
return null;
|
||||
|
||||
@@ -124,14 +124,18 @@ public class SlashCommandServiceBean implements SlashCommandService {
|
||||
for (OptionType type : types) {
|
||||
String parameterName = slashCommandParameterService.getFullQualifiedParameterName(parameter.getSlashCompatibleName(), type) + "_" + i;
|
||||
String parameterDescription = isTemplated ? templateService.renderSimpleTemplate(internalCommandName + "_parameter_" + parameter.getName()) : parameter.getDescription();
|
||||
optionalParameters.add(new OptionData(type, parameterName, parameterDescription, false));
|
||||
OptionData optionData = new OptionData(type, parameterName, parameterDescription, false);
|
||||
addChoices(optionData, parameter, internalCommandName, isTemplated);
|
||||
optionalParameters.add(optionData);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
types.forEach(type -> {
|
||||
String parameterName = slashCommandParameterService.getFullQualifiedParameterName(parameter.getSlashCompatibleName(), type);
|
||||
String parameterDescription = isTemplated ? templateService.renderSimpleTemplate(internalCommandName + "_parameter_" + parameter.getName()) : parameter.getDescription();
|
||||
optionalParameters.add(new OptionData(type, parameterName, parameterDescription, false));
|
||||
OptionData optionData = new OptionData(type, parameterName, parameterDescription, false);
|
||||
addChoices(optionData, parameter, internalCommandName, isTemplated);
|
||||
optionalParameters.add(optionData);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
@@ -139,10 +143,14 @@ public class SlashCommandServiceBean implements SlashCommandService {
|
||||
String parameterDescription = isTemplated ? templateService.renderSimpleTemplate(internalCommandName + "_parameter_" + parameter.getName()) : parameter.getDescription();
|
||||
if(parameter.isListParam()) {
|
||||
for (int i = 0; i < parameter.getListSize(); i++) {
|
||||
optionalParameters.add(new OptionData(type, parameter.getSlashCompatibleName() + "_" + i, parameterDescription, false));
|
||||
OptionData optionData = new OptionData(type, parameter.getSlashCompatibleName() + "_" + i, parameterDescription, false);
|
||||
addChoices(optionData, parameter, internalCommandName, isTemplated);
|
||||
optionalParameters.add(optionData);
|
||||
}
|
||||
} else {
|
||||
requiredParameters.add(new OptionData(type, parameter.getSlashCompatibleName(), parameterDescription, !parameter.isOptional(), parameter.getSupportsAutoComplete()));
|
||||
OptionData optionData = new OptionData(type, parameter.getSlashCompatibleName(), parameterDescription, !parameter.isOptional(), parameter.getSupportsAutoComplete());
|
||||
addChoices(optionData, parameter, internalCommandName, isTemplated);
|
||||
requiredParameters.add(optionData);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -150,6 +158,13 @@ public class SlashCommandServiceBean implements SlashCommandService {
|
||||
return requiredParameters;
|
||||
}
|
||||
|
||||
private void addChoices(OptionData optionData, Parameter parameter, String commandName, boolean isTemplated) {
|
||||
parameter.getChoices().forEach(choiceKey -> {
|
||||
String value = isTemplated ? templateService.renderSimpleTemplate(commandName + "_parameter_" + parameter.getName() + "_choice_" + choiceKey) : choiceKey;
|
||||
optionData.addChoice(value, choiceKey);
|
||||
});
|
||||
}
|
||||
|
||||
private boolean shouldParameterBeCreated(Parameter parameter, Long serverId) {
|
||||
if(parameter.getDependentFeatures().isEmpty()) {
|
||||
return true;
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package dev.sheldan.abstracto.core.listener.async.jda;
|
||||
|
||||
import dev.sheldan.abstracto.core.listener.ListenerService;
|
||||
import dev.sheldan.abstracto.core.models.ServerUser;
|
||||
import dev.sheldan.abstracto.core.models.listener.MemberUpdatePendingModel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.events.guild.member.update.GuildMemberUpdatePendingEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class AsyncMemberPendingUpdateListenerBean extends ListenerAdapter {
|
||||
|
||||
@Autowired(required = false)
|
||||
private List<AsyncUpdatePendingListener> listenerList;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("memberPendingUpdateExecutor")
|
||||
private TaskExecutor memberPendingUpdateListenerExecutor;
|
||||
|
||||
@Autowired
|
||||
private ListenerService listenerService;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void onGuildMemberUpdatePending(@Nonnull GuildMemberUpdatePendingEvent event) {
|
||||
if(listenerList == null) return;
|
||||
MemberUpdatePendingModel model = getModel(event);
|
||||
listenerList.forEach(joinListener -> listenerService.executeFeatureAwareListener(joinListener, model, memberPendingUpdateListenerExecutor));
|
||||
}
|
||||
|
||||
private MemberUpdatePendingModel getModel(GuildMemberUpdatePendingEvent event) {
|
||||
ServerUser serverUser = ServerUser
|
||||
.builder()
|
||||
.serverId(event.getGuild().getIdLong())
|
||||
.userId(event.getUser().getIdLong())
|
||||
.isBot(event.getUser().isBot())
|
||||
.build();
|
||||
return MemberUpdatePendingModel
|
||||
.builder()
|
||||
.user(serverUser)
|
||||
.member(event.getMember())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -166,6 +166,7 @@ public class EmoteServiceBean implements EmoteService {
|
||||
.builder()
|
||||
.fake(true)
|
||||
.custom(false)
|
||||
.animated(false)
|
||||
.emoteKey(emoteText)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -52,8 +52,8 @@ public class PostTargetServiceBean implements PostTargetService {
|
||||
private MessageService messageService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Message> sendTextInPostTarget(String text, PostTarget target) {
|
||||
if(target.getDisabled()) {
|
||||
public CompletableFuture<Message> sendTextInPostTarget(String text, PostTarget target) {
|
||||
if (target.getDisabled()) {
|
||||
log.info("Post target {} has been disabled in server {} - not sending message.", target.getName(), target.getServerReference().getId());
|
||||
return CompletableFuture.completedFuture(null);
|
||||
} else {
|
||||
@@ -63,46 +63,47 @@ public class PostTargetServiceBean implements PostTargetService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Message> sendEmbedInPostTarget(MessageEmbed embed, PostTarget target) {
|
||||
if(target.getDisabled()) {
|
||||
public CompletableFuture<Message> sendEmbedInPostTarget(MessageEmbed embed, PostTarget target) {
|
||||
if (target.getDisabled()) {
|
||||
log.info("Post target {} has been disabled in server {} - not sending message.", target.getName(), target.getServerReference().getId());
|
||||
return CompletableFuture.completedFuture(null);
|
||||
} else {
|
||||
GuildMessageChannel messageChannelForPostTarget = getMessageChannelForPostTarget(target);
|
||||
log.debug("Sending message embed to post target {}.", target.getName());
|
||||
return channelService.sendEmbedToChannel(embed, messageChannelForPostTarget);
|
||||
return getMessageChannelForPostTarget(target)
|
||||
.map(channel -> channelService.sendEmbedToChannel(embed, channel))
|
||||
.orElse(CompletableFuture.completedFuture(null));
|
||||
}
|
||||
}
|
||||
|
||||
private GuildMessageChannel getMessageChannelForPostTarget(PostTarget target) {
|
||||
private Optional<GuildMessageChannel> getMessageChannelForPostTarget(PostTarget target) {
|
||||
Guild guild = botService.getInstance().getGuildById(target.getServerReference().getId());
|
||||
if(guild != null) {
|
||||
if (guild != null) {
|
||||
GuildChannel guildChannelById = guild.getGuildChannelById(target.getChannelReference().getId());
|
||||
if(guildChannelById instanceof GuildMessageChannel) {
|
||||
return (GuildMessageChannel) guildChannelById;
|
||||
if (guildChannelById instanceof GuildMessageChannel) {
|
||||
return Optional.of((GuildMessageChannel) guildChannelById);
|
||||
} else {
|
||||
log.error("Incorrect post target configuration (it is not a message channel): {} points to {} on server {}", target.getName(),
|
||||
target.getChannelReference().getId(), target.getServerReference().getId());
|
||||
throw new ChannelNotInGuildException(target.getChannelReference().getId());
|
||||
return Optional.empty();
|
||||
}
|
||||
} else {
|
||||
throw new GuildNotFoundException(target.getServerReference().getId());
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Message> sendTextInPostTarget(String text, PostTargetEnum postTargetEnum, Long serverId) {
|
||||
public CompletableFuture<Message> sendTextInPostTarget(String text, PostTargetEnum postTargetEnum, Long serverId) {
|
||||
Optional<PostTarget> postTargetOptional = getPostTarget(postTargetEnum, serverId);
|
||||
if(!postTargetOptional.isPresent()) {
|
||||
if (!postTargetOptional.isPresent()) {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
return this.sendTextInPostTarget(text, postTargetOptional.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Message> sendEmbedInPostTarget(MessageEmbed embed, PostTargetEnum postTargetName, Long serverId) {
|
||||
public CompletableFuture<Message> sendEmbedInPostTarget(MessageEmbed embed, PostTargetEnum postTargetName, Long serverId) {
|
||||
Optional<PostTarget> postTargetOptional = getPostTarget(postTargetName, serverId);
|
||||
if(!postTargetOptional.isPresent()) {
|
||||
if (!postTargetOptional.isPresent()) {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
return this.sendEmbedInPostTarget(embed, postTargetOptional.get());
|
||||
@@ -111,7 +112,7 @@ public class PostTargetServiceBean implements PostTargetService {
|
||||
@Override
|
||||
public CompletableFuture<Message> sendMessageInPostTarget(Message message, PostTargetEnum postTargetName, Long serverId) {
|
||||
Optional<PostTarget> postTargetOptional = getPostTarget(postTargetName, serverId);
|
||||
if(!postTargetOptional.isPresent()) {
|
||||
if (!postTargetOptional.isPresent()) {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
return sendMessageInPostTarget(message, postTargetOptional.get());
|
||||
@@ -119,7 +120,7 @@ public class PostTargetServiceBean implements PostTargetService {
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Message> sendMessageInPostTarget(Message message, PostTarget target) {
|
||||
if(target.getDisabled()) {
|
||||
if (target.getDisabled()) {
|
||||
log.info("Post target {} has been disabled in server {} - not sending message.", target.getName(), target.getServerReference().getId());
|
||||
return CompletableFuture.completedFuture(null);
|
||||
} else {
|
||||
@@ -129,121 +130,123 @@ public class PostTargetServiceBean implements PostTargetService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CompletableFuture<Message>> sendEmbedInPostTarget(MessageToSend message, PostTargetEnum postTargetName, Long serverId) {
|
||||
public List<CompletableFuture<Message>> sendEmbedInPostTarget(MessageToSend message, PostTargetEnum postTargetName, Long serverId) {
|
||||
Optional<PostTarget> postTargetOptional = getPostTarget(postTargetName, serverId);
|
||||
if(!postTargetOptional.isPresent()) {
|
||||
if (!postTargetOptional.isPresent()) {
|
||||
return Arrays.asList(CompletableFuture.completedFuture(null));
|
||||
}
|
||||
return this.sendEmbedInPostTarget(message, postTargetOptional.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CompletableFuture<Message>> sendEmbedInPostTarget(MessageToSend message, PostTarget target) {
|
||||
if(target.getDisabled()) {
|
||||
public List<CompletableFuture<Message>> sendEmbedInPostTarget(MessageToSend message, PostTarget target) {
|
||||
if (target.getDisabled()) {
|
||||
log.info("Post target {} has been disabled in server {} - not sending message.", target.getName(), target.getServerReference().getId());
|
||||
return Arrays.asList(CompletableFuture.completedFuture(null));
|
||||
} else {
|
||||
GuildMessageChannel guildMessageChannel = getMessageChannelForPostTarget(target);
|
||||
log.debug("Send messageToSend towards post target {}.", target.getName());
|
||||
return channelService.sendMessageToSendToChannel(message, guildMessageChannel);
|
||||
return getMessageChannelForPostTarget(target)
|
||||
.map(channel -> channelService.sendMessageToSendToChannel(message, channel))
|
||||
.orElse(Arrays.asList(CompletableFuture.completedFuture(null)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CompletableFuture<Message>> editEmbedInPostTarget(Long messageId, MessageToSend message, PostTarget target) {
|
||||
if(target.getDisabled()) {
|
||||
public List<CompletableFuture<Message>> editEmbedInPostTarget(Long messageId, MessageToSend message, PostTarget target) {
|
||||
if (target.getDisabled()) {
|
||||
log.info("Post target {} has been disabled in server {} - not sending message.", target.getName(), target.getServerReference().getId());
|
||||
return Arrays.asList(CompletableFuture.completedFuture(null));
|
||||
} else {
|
||||
GuildMessageChannel guildMessageChannel = getMessageChannelForPostTarget(target);
|
||||
// always takes the first one, only applicable for this scenario
|
||||
String messageText = message.getMessages().get(0);
|
||||
if(StringUtils.isBlank(messageText)) {
|
||||
log.debug("Editing embeds of message {} in post target {}.", messageId, target.getName());
|
||||
return Arrays.asList(channelService.editEmbedMessageInAChannel(message.getEmbeds().get(0), guildMessageChannel, messageId));
|
||||
} else {
|
||||
log.debug("Editing message text and potentially text for message {} in post target {}.", messageId, target.getName());
|
||||
return Arrays.asList(channelService.editTextMessageInAChannel(messageText, message.getEmbeds().get(0), guildMessageChannel, messageId));
|
||||
}
|
||||
return getMessageChannelForPostTarget(target).map(messageChannel -> {
|
||||
// always takes the first one, only applicable for this scenario
|
||||
String messageText = message.getMessages().get(0);
|
||||
if (StringUtils.isBlank(messageText)) {
|
||||
log.debug("Editing embeds of message {} in post target {}.", messageId, target.getName());
|
||||
return Arrays.asList(channelService.editEmbedMessageInAChannel(message.getEmbeds().get(0), messageChannel, messageId));
|
||||
} else {
|
||||
log.debug("Editing message text and potentially text for message {} in post target {}.", messageId, target.getName());
|
||||
return Arrays.asList(channelService.editTextMessageInAChannel(messageText, message.getEmbeds().get(0), messageChannel, messageId));
|
||||
}
|
||||
}).orElse(Arrays.asList(CompletableFuture.completedFuture(null)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CompletableFuture<Message>> editOrCreatedInPostTarget(Long messageId, MessageToSend messageToSend, PostTarget target) {
|
||||
if(target.getDisabled()) {
|
||||
public List<CompletableFuture<Message>> editOrCreatedInPostTarget(Long messageId, MessageToSend messageToSend, PostTarget target) {
|
||||
if (target.getDisabled()) {
|
||||
log.info("Post target {} has been disabled in server {} - not sending message.", target.getName(), target.getServerReference().getId());
|
||||
return Arrays.asList(CompletableFuture.completedFuture(null));
|
||||
} else {
|
||||
List<CompletableFuture<Message>> futures = new ArrayList<>();
|
||||
GuildMessageChannel guildMessageChannel = getMessageChannelForPostTarget(target);
|
||||
CompletableFuture<Message> messageEditFuture = new CompletableFuture<>();
|
||||
futures.add(messageEditFuture);
|
||||
if (StringUtils.isBlank(messageToSend.getMessages().get(0).trim())) {
|
||||
channelService.retrieveMessageInChannel(guildMessageChannel, messageId).thenAccept(message -> {
|
||||
log.debug("Editing existing message {} when upserting message embeds in channel {} in server {}.",
|
||||
messageId, guildMessageChannel.getIdLong(), guildMessageChannel.getGuild().getId());
|
||||
messageService.editMessage(message, messageToSend.getEmbeds().get(0))
|
||||
.queue(messageEditFuture::complete, messageEditFuture::completeExceptionally);
|
||||
}).exceptionally(throwable -> {
|
||||
log.debug("Creating new message when upserting message embeds for message {} in channel {} in server {}.",
|
||||
messageId, guildMessageChannel.getIdLong(), guildMessageChannel.getGuild().getId());
|
||||
sendEmbedInPostTarget(messageToSend, target).get(0)
|
||||
.thenAccept(messageEditFuture::complete).exceptionally(innerThrowable -> {
|
||||
log.error("Failed to send message to create a message.", innerThrowable);
|
||||
messageEditFuture.completeExceptionally(innerThrowable);
|
||||
return getMessageChannelForPostTarget(target).map(messageChannel -> {
|
||||
CompletableFuture<Message> messageEditFuture = new CompletableFuture<>();
|
||||
futures.add(messageEditFuture);
|
||||
if (StringUtils.isBlank(messageToSend.getMessages().get(0).trim())) {
|
||||
channelService.retrieveMessageInChannel(messageChannel, messageId).thenAccept(message -> {
|
||||
log.debug("Editing existing message {} when upserting message embeds in channel {} in server {}.",
|
||||
messageId, messageChannel.getIdLong(), messageChannel.getGuild().getId());
|
||||
messageService.editMessage(message, messageToSend.getEmbeds().get(0))
|
||||
.queue(messageEditFuture::complete, messageEditFuture::completeExceptionally);
|
||||
}).exceptionally(throwable -> {
|
||||
log.debug("Creating new message when upserting message embeds for message {} in channel {} in server {}.",
|
||||
messageId, messageChannel.getIdLong(), messageChannel.getGuild().getId());
|
||||
sendEmbedInPostTarget(messageToSend, target).get(0)
|
||||
.thenAccept(messageEditFuture::complete).exceptionally(innerThrowable -> {
|
||||
log.error("Failed to send message to create a message.", innerThrowable);
|
||||
messageEditFuture.completeExceptionally(innerThrowable);
|
||||
return null;
|
||||
});
|
||||
return null;
|
||||
});
|
||||
return null;
|
||||
});
|
||||
} else {
|
||||
channelService.retrieveMessageInChannel(guildMessageChannel, messageId).thenAccept(message -> {
|
||||
log.debug("Editing existing message {} when upserting message in channel {} in server {}.",
|
||||
messageId, guildMessageChannel.getIdLong(), guildMessageChannel.getGuild().getId());
|
||||
messageService.editMessage(message, messageToSend.getMessages().get(0), messageToSend.getEmbeds().get(0))
|
||||
.queue(messageEditFuture::complete, messageEditFuture::completeExceptionally);
|
||||
}).exceptionally(throwable -> {
|
||||
log.debug("Creating new message when trying to upsert a message {} in channel {} in server {}.",
|
||||
messageId, guildMessageChannel.getIdLong(), guildMessageChannel.getGuild().getId());
|
||||
sendEmbedInPostTarget(messageToSend, target).get(0)
|
||||
.thenAccept(messageEditFuture::complete).exceptionally(innerThrowable -> {
|
||||
log.error("Failed to send message to create a message.", innerThrowable);
|
||||
messageEditFuture.completeExceptionally(innerThrowable);
|
||||
} else {
|
||||
channelService.retrieveMessageInChannel(messageChannel, messageId).thenAccept(message -> {
|
||||
log.debug("Editing existing message {} when upserting message in channel {} in server {}.",
|
||||
messageId, messageChannel.getIdLong(), messageChannel.getGuild().getId());
|
||||
messageService.editMessage(message, messageToSend.getMessages().get(0), messageToSend.getEmbeds().get(0))
|
||||
.queue(messageEditFuture::complete, messageEditFuture::completeExceptionally);
|
||||
}).exceptionally(throwable -> {
|
||||
log.debug("Creating new message when trying to upsert a message {} in channel {} in server {}.",
|
||||
messageId, messageChannel.getIdLong(), messageChannel.getGuild().getId());
|
||||
sendEmbedInPostTarget(messageToSend, target).get(0)
|
||||
.thenAccept(messageEditFuture::complete).exceptionally(innerThrowable -> {
|
||||
log.error("Failed to send message to create a message.", innerThrowable);
|
||||
messageEditFuture.completeExceptionally(innerThrowable);
|
||||
return null;
|
||||
});
|
||||
return null;
|
||||
});
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
return futures;
|
||||
}
|
||||
return futures;
|
||||
}).orElse(Arrays.asList(CompletableFuture.completedFuture(null)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CompletableFuture<Message>> editOrCreatedInPostTarget(Long messageId, MessageToSend messageToSend, PostTargetEnum postTargetName, Long serverId) {
|
||||
public List<CompletableFuture<Message>> editOrCreatedInPostTarget(Long messageId, MessageToSend messageToSend, PostTargetEnum postTargetName, Long serverId) {
|
||||
Optional<PostTarget> postTargetOptional = getPostTarget(postTargetName, serverId);
|
||||
if(!postTargetOptional.isPresent()) {
|
||||
if (!postTargetOptional.isPresent()) {
|
||||
return Arrays.asList(CompletableFuture.completedFuture(null));
|
||||
}
|
||||
return this.editOrCreatedInPostTarget(messageId, messageToSend, postTargetOptional.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void throwIfPostTargetIsNotDefined(PostTargetEnum name, Long serverId) {
|
||||
Optional<PostTarget> postTargetOptional = getPostTarget(name, serverId);
|
||||
if(!postTargetOptional.isPresent()) {
|
||||
throw new PostTargetNotValidException(name.getKey(), defaultPostTargetManagementService.getDefaultPostTargetKeys());
|
||||
public void throwIfPostTargetIsNotDefined(PostTargetEnum targetEnum, Long serverId) {
|
||||
Optional<PostTarget> postTargetOptional = getPostTarget(targetEnum, serverId);
|
||||
if (!postTargetOptional.isPresent()) {
|
||||
throw new PostTargetNotValidException(targetEnum.getKey(), defaultPostTargetManagementService.getDefaultPostTargetKeys());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean postTargetDefinedInServer(PostTargetEnum name, Long serverId) {
|
||||
return postTargetManagement.postTargetExists(name.getKey(), serverId);
|
||||
public boolean postTargetDefinedInServer(PostTargetEnum targetEnum, Long serverId) {
|
||||
return postTargetManagement.postTargetExists(targetEnum.getKey(), serverId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CompletableFuture<Message>> editEmbedInPostTarget(Long messageId, MessageToSend message, PostTargetEnum postTargetName, Long serverId) {
|
||||
public List<CompletableFuture<Message>> editEmbedInPostTarget(Long messageId, MessageToSend message, PostTargetEnum postTargetName, Long serverId) {
|
||||
Optional<PostTarget> postTargetOptional = getPostTarget(postTargetName, serverId);
|
||||
if(!postTargetOptional.isPresent()) {
|
||||
if (!postTargetOptional.isPresent()) {
|
||||
return Arrays.asList(CompletableFuture.completedFuture(null));
|
||||
}
|
||||
return editEmbedInPostTarget(messageId, message, postTargetOptional.get());
|
||||
@@ -260,15 +263,15 @@ public class PostTargetServiceBean implements PostTargetService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validatePostTarget(PostTargetEnum name, Long serverId) {
|
||||
if(!postTargetUsableInServer(name, serverId)) {
|
||||
throw new PostTargetNotUsableException(name.getKey());
|
||||
public void validatePostTarget(PostTargetEnum targetEnum, Long serverId) {
|
||||
if (!postTargetUsableInServer(targetEnum, serverId)) {
|
||||
throw new PostTargetNotUsableException(targetEnum.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean postTargetUsableInServer(PostTargetEnum name, Long serverId) {
|
||||
Optional<PostTarget> postTargetOptional = getPostTarget(name, serverId);
|
||||
public boolean postTargetUsableInServer(PostTargetEnum targetEnum, Long serverId) {
|
||||
Optional<PostTarget> postTargetOptional = getPostTarget(targetEnum, serverId);
|
||||
return postTargetOptional.isPresent() && !postTargetOptional.get().getDisabled();
|
||||
}
|
||||
|
||||
@@ -287,7 +290,7 @@ public class PostTargetServiceBean implements PostTargetService {
|
||||
List<String> postTargets = new ArrayList<>();
|
||||
List<FeatureConfig> allFeatureConfigs = featureConfigService.getAllFeatureConfigs();
|
||||
allFeatureConfigs.forEach(featureConfig -> {
|
||||
if(featureFlagService.isFeatureEnabled(featureConfig, server)) {
|
||||
if (featureFlagService.isFeatureEnabled(featureConfig, server)) {
|
||||
featureConfig.getRequiredPostTargets().forEach(postTargetEnum -> postTargets.add(postTargetEnum.getKey()));
|
||||
}
|
||||
});
|
||||
@@ -305,4 +308,16 @@ public class PostTargetServiceBean implements PostTargetService {
|
||||
PostTarget postTarget = postTargetManagement.getPostTarget(name, serverId);
|
||||
postTarget.setDisabled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<GuildMessageChannel> getPostTargetChannel(PostTargetEnum postTargetEnum, Long serverId) {
|
||||
Optional<PostTarget> postTarget = getPostTarget(postTargetEnum, serverId);
|
||||
return postTarget.flatMap(target -> {
|
||||
if (target.getDisabled()) {
|
||||
return Optional.empty();
|
||||
} else {
|
||||
return getMessageChannelForPostTarget(target);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,10 +122,6 @@ public class RoleServiceBean implements RoleService {
|
||||
}
|
||||
|
||||
private CompletableFuture<Void> addRoleToUserAsync(Guild guild, Long userId, ARole role) {
|
||||
if(role.getDeleted()) {
|
||||
log.warn("Not possible to add role to user. Role {} was marked as deleted.", role.getId());
|
||||
throw new RoleDeletedException(role);
|
||||
}
|
||||
Role roleById = guild.getRoleById(role.getId());
|
||||
if(roleById != null) {
|
||||
log.info("Adding role {} to user {} in server {}.", role.getId(), userId, guild.getId());
|
||||
|
||||
@@ -160,15 +160,16 @@ public class EmoteManagementServiceBean implements EmoteManagementService {
|
||||
if(fakeEmote.getCustom()) {
|
||||
log.debug("Setting existing emote (a: {}, c: {}, id: {}, discord id: {}) to new custom emote configuration: new id {}, animated {}.",
|
||||
emoteBeingSet.getAnimated(), emoteBeingSet.getCustom(), emoteBeingSet.getId(), emoteBeingSet.getEmoteId(), fakeEmote.getEmoteId(), fakeEmote.getAnimated());
|
||||
emoteBeingSet.setCustom(fakeEmote.getCustom());
|
||||
emoteBeingSet.setEmoteId(fakeEmote.getEmoteId());
|
||||
emoteBeingSet.setEmoteKey(fakeEmote.getEmoteKey());
|
||||
emoteBeingSet.setAnimated(fakeEmote.getAnimated());
|
||||
} else {
|
||||
log.debug("Setting existing emote (a: {}, c: {}, id: {}, discord id: {}) to new default emote {}.",
|
||||
emoteBeingSet.getAnimated(), emoteBeingSet.getCustom(), emoteBeingSet.getId(), emoteBeingSet.getEmoteId(), fakeEmote.getEmoteKey());
|
||||
emoteBeingSet.setCustom(false);
|
||||
emoteBeingSet.setEmoteKey(fakeEmote.getEmoteKey());
|
||||
emoteBeingSet.setEmoteId(null);
|
||||
emoteBeingSet.setAnimated(false);
|
||||
}
|
||||
emoteBeingSet.setCustom(fakeEmote.getCustom());
|
||||
emoteBeingSet.setEmoteKey(fakeEmote.getEmoteKey());
|
||||
return emoteBeingSet;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>dev.sheldan.abstracto.core</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<version>1.4.13</version>
|
||||
<version>1.4.21</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
@@ -37,6 +37,8 @@ public class Parameter implements Serializable {
|
||||
// these are the features which potentially require this parameter
|
||||
@Builder.Default
|
||||
private List<String> dependentFeatures = new ArrayList<>();
|
||||
@Builder.Default
|
||||
private List<String> choices = new ArrayList<>();
|
||||
|
||||
public String getSlashCompatibleName() {
|
||||
return name.toLowerCase(Locale.ROOT);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user