[AB-68] adding invite filter with commands to allow/disallow invites, remove stored filtered invite links and show filtered invite links

removing database entities from command context
This commit is contained in:
Sheldan
2021-01-23 15:33:00 +01:00
parent fb3ed69650
commit 2a2a3aea70
182 changed files with 2571 additions and 325 deletions

View File

@@ -10,7 +10,11 @@ import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.command.execution.ContextConverter;
import dev.sheldan.abstracto.core.config.FeatureEnum;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import dev.sheldan.abstracto.core.service.ChannelService;
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
import dev.sheldan.abstracto.core.utils.FutureUtils;
import dev.sheldan.abstracto.experience.config.features.ExperienceFeature;
import dev.sheldan.abstracto.experience.converter.LeaderBoardModelConverter;
@@ -51,20 +55,26 @@ public class LeaderBoardCommand extends AbstractConditionableCommand {
@Autowired
private LeaderBoardModelConverter converter;
@Autowired
private ServerManagementService serverManagementService;
@Autowired
private UserInServerManagementService userInServerManagementService;
@Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
List<Object> parameters = commandContext.getParameters().getParameters();
// parameter is optional, in case its not present, we default to the 0th page
Integer page = !parameters.isEmpty() ? (Integer) parameters.get(0) : 1;
LeaderBoard leaderBoard = userExperienceService.findLeaderBoardData(commandContext.getUserInitiatedContext().getServer(), page);
AServer server = serverManagementService.loadServer(commandContext.getGuild());
LeaderBoard leaderBoard = userExperienceService.findLeaderBoardData(server, page);
LeaderBoardModel leaderBoardModel = (LeaderBoardModel) ContextConverter.slimFromCommandContext(commandContext, LeaderBoardModel.class);
List<CompletableFuture<LeaderBoardEntryModel>> futures = new ArrayList<>();
List<CompletableFuture<LeaderBoardEntryModel>> completableFutures = converter.fromLeaderBoard(leaderBoard);
futures.addAll(completableFutures);
log.info("Rendering leaderboard for page {} in server {} for user {}.", page, commandContext.getAuthor().getId(), commandContext.getGuild().getId());
LeaderBoardEntry userRank = userExperienceService.getRankOfUserInServer(commandContext.getUserInitiatedContext().getAUserInAServer());
AUserInAServer aUserInAServer = userInServerManagementService.loadUser(commandContext.getAuthor());
LeaderBoardEntry userRank = userExperienceService.getRankOfUserInServer(aUserInAServer);
CompletableFuture<LeaderBoardEntryModel> userRankFuture = converter.fromLeaderBoardEntry(userRank);
futures.add(userRankFuture);
return FutureUtils.toSingleFutureGeneric(futures).thenCompose(aVoid -> {

View File

@@ -9,8 +9,10 @@ import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.command.execution.ContextConverter;
import dev.sheldan.abstracto.core.config.FeatureEnum;
import dev.sheldan.abstracto.core.models.FullRole;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.service.ChannelService;
import dev.sheldan.abstracto.core.service.RoleService;
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
import dev.sheldan.abstracto.core.utils.FutureUtils;
import dev.sheldan.abstracto.experience.config.features.ExperienceFeature;
import dev.sheldan.abstracto.experience.models.database.ADisabledExpRole;
@@ -40,9 +42,13 @@ public class ListDisabledExperienceRoles extends AbstractConditionableCommand {
@Autowired
private ChannelService channelService;
@Autowired
private ServerManagementService serverManagementService;
@Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
List<ADisabledExpRole> disabledRolesForServer = disabledExpRoleManagementService.getDisabledRolesForServer(commandContext.getUserInitiatedContext().getServer());
AServer server = serverManagementService.loadServer(commandContext.getGuild());
List<ADisabledExpRole> disabledRolesForServer = disabledExpRoleManagementService.getDisabledRolesForServer(server);
DisabledExperienceRolesModel disabledExperienceRolesModel = (DisabledExperienceRolesModel) ContextConverter.fromCommandContext(commandContext, DisabledExperienceRolesModel.class);
disabledRolesForServer.forEach(aDisabledExpRole -> {
FullRole role = FullRole

View File

@@ -67,7 +67,8 @@ public class Rank extends AbstractConditionableCommand {
@Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
RankModel rankModel = (RankModel) ContextConverter.slimFromCommandContext(commandContext, RankModel.class);
LeaderBoardEntry userRank = userExperienceService.getRankOfUserInServer(commandContext.getUserInitiatedContext().getAUserInAServer());
AUserInAServer aUserInAServer = userInServerManagementService.loadUser(commandContext.getAuthor());
LeaderBoardEntry userRank = userExperienceService.getRankOfUserInServer(aUserInAServer);
CompletableFuture<LeaderBoardEntryModel> future = converter.fromLeaderBoardEntry(userRank);
return future.thenCompose(leaderBoardEntryModel ->
self.renderAndSendRank(commandContext, rankModel, leaderBoardEntryModel)

View File

@@ -44,7 +44,7 @@ public class SetExpRole extends AbstractConditionableCommand {
Integer level = (Integer) commandContext.getParameters().getParameters().get(0);
Role role = (Role) commandContext.getParameters().getParameters().get(1);
log.info("Setting role {} to be used for level {} on server {}", role.getId(), level, role.getGuild().getId());
return experienceRoleService.setRoleToLevel(role, level, commandContext.getUserInitiatedContext().getChannel())
return experienceRoleService.setRoleToLevel(role, level, commandContext.getChannel().getIdLong())
.thenApply(aVoid -> CommandResult.fromSuccess());
}

View File

@@ -8,6 +8,7 @@ import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureEnum;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
import dev.sheldan.abstracto.experience.config.features.ExperienceFeature;
import dev.sheldan.abstracto.experience.service.AUserExperienceService;
import lombok.extern.slf4j.Slf4j;
@@ -31,11 +32,14 @@ public class SyncRoles extends AbstractConditionableCommand {
@Autowired
private AUserExperienceService userExperienceService;
@Autowired
private ServerManagementService serverManagementService;
@Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
AServer server = commandContext.getUserInitiatedContext().getServer();
AServer server = serverManagementService.loadServer(commandContext.getGuild());
log.info("Synchronizing roles on server {}", server.getId());
return userExperienceService.syncUserRolesWithFeedback(server, commandContext.getUserInitiatedContext().getChannel())
return userExperienceService.syncUserRolesWithFeedback(server, commandContext.getChannel().getIdLong())
.thenApply(aVoid -> CommandResult.fromIgnored());
}

View File

@@ -37,7 +37,7 @@ public class UnSetExpRole extends AbstractConditionableCommand {
ARole actualRole = roleManagementService.findRole(role.getId());
// do not check for the existence of the role, because if the role was deleted, users should be able
// to get rid of it in the configuration
return experienceRoleService.unsetRole(actualRole, commandContext.getUserInitiatedContext().getChannel())
return experienceRoleService.unsetRole(actualRole, commandContext.getChannel().getIdLong())
.thenApply(aVoid -> CommandResult.fromSuccess());
}

View File

@@ -4,10 +4,8 @@ import dev.sheldan.abstracto.core.models.database.AChannel;
import dev.sheldan.abstracto.core.models.database.ARole;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import dev.sheldan.abstracto.core.service.BotService;
import dev.sheldan.abstracto.core.service.ConfigService;
import dev.sheldan.abstracto.core.service.MessageService;
import dev.sheldan.abstracto.core.service.RoleService;
import dev.sheldan.abstracto.core.service.*;
import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
import dev.sheldan.abstracto.core.utils.CompletableFutureList;
@@ -79,6 +77,9 @@ public class AUserExperienceServiceBean implements AUserExperienceService {
@Autowired
private ServerManagementService serverManagementService;
@Autowired
private ChannelManagementService channelManagementService;
@Autowired
private AUserExperienceServiceBean self;
@@ -403,10 +404,11 @@ public class AUserExperienceServiceBean implements AUserExperienceService {
/**
* Synchronizes the roles of all the users and provides feedback to the user executing
* @param server The {@link AServer} to update users for
* @param channel The {@link AChannel} in which the {@link dev.sheldan.abstracto.experience.models.templates.UserSyncStatusModel}
* @param channelId The ID of the channel in which the {@link dev.sheldan.abstracto.experience.models.templates.UserSyncStatusModel} should be posted to
*/
@Override
public CompletableFuture<Void> syncUserRolesWithFeedback(AServer server, AChannel channel) {
public CompletableFuture<Void> syncUserRolesWithFeedback(AServer server, Long channelId) {
AChannel channel = channelManagementService.loadChannel(channelId);
List<AUserExperience> aUserExperiences = userExperienceManagementService.loadAllUsers(server);
log.info("Found {} users to synchronize", aUserExperiences.size());
List<AExperienceRole> roles = experienceRoleManagementService.getExperienceRolesForServer(server);

View File

@@ -3,6 +3,7 @@ package dev.sheldan.abstracto.experience.service;
import dev.sheldan.abstracto.core.models.database.AChannel;
import dev.sheldan.abstracto.core.models.database.ARole;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
import dev.sheldan.abstracto.core.service.management.RoleManagementService;
import dev.sheldan.abstracto.core.utils.CompletableFutureList;
import dev.sheldan.abstracto.experience.models.RoleCalculationResult;
@@ -42,6 +43,9 @@ public class ExperienceRoleServiceBean implements ExperienceRoleService {
@Autowired
private RoleManagementService roleManagementService;
@Autowired
private ChannelManagementService channelManagementService;
/**
* UnSets the current configuration for the passed level, and sets the {@link ARole} to be used for this level
* in the given {@link AServer}
@@ -49,10 +53,10 @@ public class ExperienceRoleServiceBean implements ExperienceRoleService {
* @param level The level the {@link ARole} should be awarded at
*/
@Override
public CompletableFuture<Void> setRoleToLevel(Role role, Integer level, AChannel feedbackChannel) {
public CompletableFuture<Void> setRoleToLevel(Role role, Integer level, Long channelId) {
Long roleId = role.getIdLong();
ARole aRole = roleManagementService.findRole(roleId);
return unsetRole(aRole, feedbackChannel).thenAccept(aVoid ->
return unsetRole(aRole, channelId).thenAccept(aVoid ->
self.unsetRoleInDb(level, roleId)
);
}
@@ -73,7 +77,8 @@ public class ExperienceRoleServiceBean implements ExperienceRoleService {
* configuration
*/
@Override
public CompletableFuture<Void> unsetRole(ARole role, AChannel feedbackChannel) {
public CompletableFuture<Void> unsetRole(ARole role, Long feedbackChannelId) {
AChannel channel = channelManagementService.loadChannel(feedbackChannelId);
Optional<AExperienceRole> roleInServerOptional = experienceRoleManagementService.getRoleInServerOptional(role);
if(roleInServerOptional.isPresent()) {
AExperienceRole roleInServer = roleInServerOptional.get();
@@ -82,7 +87,7 @@ public class ExperienceRoleServiceBean implements ExperienceRoleService {
List<AExperienceRole> roles = experienceRoleManagementService.getExperienceRolesForServer(role.getServer());
roles.removeIf(role1 -> role1.getId().equals(roleInServer.getId()));
Long roleId = role.getId();
CompletableFutureList<RoleCalculationResult> calculationResults = userExperienceService.executeActionOnUserExperiencesWithFeedBack(roleInServer.getUsers(), feedbackChannel,
CompletableFutureList<RoleCalculationResult> calculationResults = userExperienceService.executeActionOnUserExperiencesWithFeedBack(roleInServer.getUsers(), channel,
(AUserExperience ex) -> userExperienceService.updateUserRole(ex, roles, ex.getLevelOrDefault()));
return calculationResults.getMainFuture().thenAccept(aVoid ->
self.persistData(calculationResults, roleId)