mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-14 11:48:16 +00:00
[AB-xxx] adding information whether a modmail thread comes from an appeal to storage and to modmail notification
This commit is contained in:
@@ -88,7 +88,7 @@ public class Contact extends AbstractConditionableCommand {
|
|||||||
List<CompletableFuture<Message>> futures = channelService.sendEmbedTemplateInTextChannelList(MODMAIL_THREAD_ALREADY_EXISTS_TEMPLATE, model, commandContext.getChannel());
|
List<CompletableFuture<Message>> futures = channelService.sendEmbedTemplateInTextChannelList(MODMAIL_THREAD_ALREADY_EXISTS_TEMPLATE, model, commandContext.getChannel());
|
||||||
return FutureUtils.toSingleFutureGeneric(futures).thenApply(aVoid -> CommandResult.fromIgnored());
|
return FutureUtils.toSingleFutureGeneric(futures).thenApply(aVoid -> CommandResult.fromIgnored());
|
||||||
} else {
|
} else {
|
||||||
return modMailThreadService.createModMailThreadForUser(targetUser.getUser(), targetUser.getGuild(), null, false, commandContext.getUndoActions())
|
return modMailThreadService.createModMailThreadForUser(targetUser.getUser(), targetUser.getGuild(), null, false, commandContext.getUndoActions(), false)
|
||||||
.thenCompose(unused -> modMailThreadService.sendContactNotification(targetUser.getUser(), unused, commandContext.getChannel()))
|
.thenCompose(unused -> modMailThreadService.sendContactNotification(targetUser.getUser(), unused, commandContext.getChannel()))
|
||||||
.thenApply(aVoid -> CommandResult.fromSuccess());
|
.thenApply(aVoid -> CommandResult.fromSuccess());
|
||||||
}
|
}
|
||||||
@@ -112,7 +112,7 @@ public class Contact extends AbstractConditionableCommand {
|
|||||||
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
||||||
} else {
|
} else {
|
||||||
CompletableFuture<InteractionHook> response = interactionService.replyEmbed(CONTACT_RESPONSE, event);
|
CompletableFuture<InteractionHook> response = interactionService.replyEmbed(CONTACT_RESPONSE, event);
|
||||||
CompletableFuture<MessageChannel> threadFuture = modMailThreadService.createModMailThreadForUser(user, event.getGuild(), null, false, new ArrayList<>());
|
CompletableFuture<MessageChannel> threadFuture = modMailThreadService.createModMailThreadForUser(user, event.getGuild(), null, false, new ArrayList<>(), false);
|
||||||
return CompletableFuture.allOf(response, threadFuture)
|
return CompletableFuture.allOf(response, threadFuture)
|
||||||
.thenCompose(unused -> modMailThreadService.sendContactNotification(user, threadFuture.join(), response.join()))
|
.thenCompose(unused -> modMailThreadService.sendContactNotification(user, threadFuture.join(), response.join()))
|
||||||
.thenApply(o -> CommandResult.fromSuccess());
|
.thenApply(o -> CommandResult.fromSuccess());
|
||||||
|
|||||||
@@ -53,10 +53,11 @@ public class ModMailInitialButtonListener implements ButtonClickedListener {
|
|||||||
log.debug("Executing action for creationg a modmail thread in server {} for user {}.", chosenServer.getServerId(), userId);
|
log.debug("Executing action for creationg a modmail thread in server {} for user {}.", chosenServer.getServerId(), userId);
|
||||||
ArrayList<UndoActionInstance> undoActions = new ArrayList<>();
|
ArrayList<UndoActionInstance> undoActions = new ArrayList<>();
|
||||||
Guild guild = guildService.getGuildById(chosenServer.getServerId());
|
Guild guild = guildService.getGuildById(chosenServer.getServerId());
|
||||||
|
boolean appeal = chosenServer.getAppealModmail() != null && chosenServer.getAppealModmail();
|
||||||
channelService.retrieveMessageInChannel(model.getEvent().getChannel(), choices.getMessageId())
|
channelService.retrieveMessageInChannel(model.getEvent().getChannel(), choices.getMessageId())
|
||||||
.thenCompose(originalMessage -> {
|
.thenCompose(originalMessage -> {
|
||||||
try {
|
try {
|
||||||
return modMailThreadService.createModMailThreadForUser(model.getEvent().getUser(), guild, originalMessage, true, undoActions);
|
return modMailThreadService.createModMailThreadForUser(model.getEvent().getUser(), guild, originalMessage, true, undoActions, appeal);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
log.error("Failed to setup thread correctly", ex);
|
log.error("Failed to setup thread correctly", ex);
|
||||||
undoActionService.performActions(undoActions);
|
undoActionService.performActions(undoActions);
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
|||||||
public static final String MODMAIL_INITIAL_ORIGIN = "modmailInitial";
|
public static final String MODMAIL_INITIAL_ORIGIN = "modmailInitial";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<MessageChannel> createModMailThreadForUser(User user, Guild guild, Message initialMessage, boolean userInitiated, List<UndoActionInstance> undoActions) {
|
public CompletableFuture<MessageChannel> createModMailThreadForUser(User user, Guild guild, Message initialMessage, boolean userInitiated, List<UndoActionInstance> undoActions, boolean appeal) {
|
||||||
Long serverId = guild.getIdLong();
|
Long serverId = guild.getIdLong();
|
||||||
AServer server = serverManagementService.loadServer(serverId);
|
AServer server = serverManagementService.loadServer(serverId);
|
||||||
metricService.incrementCounter(MODMAIL_THREAD_CREATED_COUNTER);
|
metricService.incrementCounter(MODMAIL_THREAD_CREATED_COUNTER);
|
||||||
@@ -204,7 +204,7 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
|||||||
.build();
|
.build();
|
||||||
String channelName = templateService.renderTemplate(TEXT_CHANNEL_NAME_TEMPLATE_KEY, model, serverId);
|
String channelName = templateService.renderTemplate(TEXT_CHANNEL_NAME_TEMPLATE_KEY, model, serverId);
|
||||||
if (featureModeService.featureModeActive(ModMailFeatureDefinition.MOD_MAIL, serverId, ModMailMode.THREAD_CONTAINER)) {
|
if (featureModeService.featureModeActive(ModMailFeatureDefinition.MOD_MAIL, serverId, ModMailMode.THREAD_CONTAINER)) {
|
||||||
MessageToSend notificationMessageToSend = getModmailNotificationMessageToSend(user, null, serverId, false);
|
MessageToSend notificationMessageToSend = getModmailNotificationMessageToSend(user, null, serverId, false, appeal);
|
||||||
Optional<GuildMessageChannel> modmailContainerOptional = postTargetService.getPostTargetChannel(ModMailPostTargets.MOD_MAIL_CONTAINER, serverId);
|
Optional<GuildMessageChannel> modmailContainerOptional = postTargetService.getPostTargetChannel(ModMailPostTargets.MOD_MAIL_CONTAINER, serverId);
|
||||||
if(modmailContainerOptional.isEmpty()) {
|
if(modmailContainerOptional.isEmpty()) {
|
||||||
throw new AbstractoRunTimeException("Modmail thread container not setup.");
|
throw new AbstractoRunTimeException("Modmail thread container not setup.");
|
||||||
@@ -220,7 +220,7 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
|||||||
.thenCompose(unused -> channelService.createThreadWithStarterMessage(textChannel, channelName, notificationMessage.get(0).join().getIdLong()))
|
.thenCompose(unused -> channelService.createThreadWithStarterMessage(textChannel, channelName, notificationMessage.get(0).join().getIdLong()))
|
||||||
.thenCompose(threadChannel -> {
|
.thenCompose(threadChannel -> {
|
||||||
undoActions.add(UndoActionInstance.getChannelDeleteAction(serverId, threadChannel.getIdLong()));
|
undoActions.add(UndoActionInstance.getChannelDeleteAction(serverId, threadChannel.getIdLong()));
|
||||||
return self.performModMailThreadSetup(user, initialMessage, threadChannel, userInitiated, undoActions)
|
return self.performModMailThreadSetup(user, initialMessage, threadChannel, userInitiated, undoActions, appeal)
|
||||||
.thenCompose(unused -> CompletableFuture.completedFuture(threadChannel));
|
.thenCompose(unused -> CompletableFuture.completedFuture(threadChannel));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -229,7 +229,7 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
|||||||
CompletableFuture<TextChannel> textChannelFuture = channelService.createTextChannel(channelName, server, categoryId);
|
CompletableFuture<TextChannel> textChannelFuture = channelService.createTextChannel(channelName, server, categoryId);
|
||||||
return textChannelFuture.thenCompose(channel -> {
|
return textChannelFuture.thenCompose(channel -> {
|
||||||
undoActions.add(UndoActionInstance.getChannelDeleteAction(serverId, channel.getIdLong()));
|
undoActions.add(UndoActionInstance.getChannelDeleteAction(serverId, channel.getIdLong()));
|
||||||
return self.performModMailThreadSetup(user, initialMessage, channel, userInitiated, undoActions)
|
return self.performModMailThreadSetup(user, initialMessage, channel, userInitiated, undoActions, appeal)
|
||||||
.thenCompose(unused -> CompletableFuture.completedFuture(channel));
|
.thenCompose(unused -> CompletableFuture.completedFuture(channel));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -264,10 +264,11 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
|||||||
* @param channel The created {@link TextChannel} in which the mod mail thread is dealt with
|
* @param channel The created {@link TextChannel} in which the mod mail thread is dealt with
|
||||||
* @param userInitiated Whether the thread was initiated by a member
|
* @param userInitiated Whether the thread was initiated by a member
|
||||||
* @param undoActions The list of actions to undo, in case an exception occurs
|
* @param undoActions The list of actions to undo, in case an exception occurs
|
||||||
|
* @param appeal Whether the modmail thread is for the purpose of an appeal
|
||||||
* @return A {@link CompletableFuture future} which completes when the setup is done
|
* @return A {@link CompletableFuture future} which completes when the setup is done
|
||||||
*/
|
*/
|
||||||
@Transactional
|
@Transactional
|
||||||
public CompletableFuture<Void> performModMailThreadSetup(User user, Message initialMessage, GuildMessageChannel channel, boolean userInitiated, List<UndoActionInstance> undoActions) {
|
public CompletableFuture<Void> performModMailThreadSetup(User user, Message initialMessage, GuildMessageChannel channel, boolean userInitiated, List<UndoActionInstance> undoActions, boolean appeal) {
|
||||||
log.info("Performing modmail thread setup for channel {} for user {} in server {}. It was initiated by a user: {}.", channel.getIdLong(), user.getId(), channel.getGuild().getId(), userInitiated);
|
log.info("Performing modmail thread setup for channel {} for user {} in server {}. It was initiated by a user: {}.", channel.getIdLong(), user.getId(), channel.getGuild().getId(), userInitiated);
|
||||||
CompletableFuture<Void> headerFuture = sendModMailHeader(channel, user);
|
CompletableFuture<Void> headerFuture = sendModMailHeader(channel, user);
|
||||||
CompletableFuture<Message> userReplyMessage;
|
CompletableFuture<Message> userReplyMessage;
|
||||||
@@ -280,21 +281,21 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
|||||||
}
|
}
|
||||||
CompletableFuture notificationFuture;
|
CompletableFuture notificationFuture;
|
||||||
if (userInitiated) {
|
if (userInitiated) {
|
||||||
notificationFuture = self.sendModMailNotification(user, channel);
|
notificationFuture = self.sendModMailNotification(user, channel, appeal);
|
||||||
} else {
|
} else {
|
||||||
notificationFuture = CompletableFuture.completedFuture(null);
|
notificationFuture = CompletableFuture.completedFuture(null);
|
||||||
}
|
}
|
||||||
return CompletableFuture.allOf(headerFuture, notificationFuture, userReplyMessage).thenAccept(aVoid -> {
|
return CompletableFuture.allOf(headerFuture, notificationFuture, userReplyMessage).thenAccept(aVoid -> {
|
||||||
undoActions.clear();
|
undoActions.clear();
|
||||||
self.setupModMailThreadInDB(initialMessage, channel, user, userReplyMessage.join());
|
self.setupModMailThreadInDB(initialMessage, channel, user, userReplyMessage.join(), appeal);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void setupModMailThreadInDB(Message initialMessage, GuildMessageChannel channel, User user, Message sendMessage) {
|
public void setupModMailThreadInDB(Message initialMessage, GuildMessageChannel channel, User user, Message sendMessage, boolean appeal) {
|
||||||
log.info("Persisting info about modmail thread {} in database.", channel.getIdLong());
|
log.info("Persisting info about modmail thread {} in database.", channel.getIdLong());
|
||||||
AUserInAServer aUserInAServer = userInServerManagementService.loadOrCreateUser(channel.getGuild().getIdLong(), user.getIdLong());
|
AUserInAServer aUserInAServer = userInServerManagementService.loadOrCreateUser(channel.getGuild().getIdLong(), user.getIdLong());
|
||||||
ModMailThread thread = createThreadObject(channel, aUserInAServer);
|
ModMailThread thread = createThreadObject(channel, aUserInAServer, appeal);
|
||||||
if(initialMessage != null) {
|
if(initialMessage != null) {
|
||||||
log.debug("Adding initial message {} to modmail thread in channel {}.", initialMessage.getId(), channel.getId());
|
log.debug("Adding initial message {} to modmail thread in channel {}.", initialMessage.getId(), channel.getId());
|
||||||
modMailMessageManagementService.addMessageToThread(thread, null, sendMessage, initialMessage, aUserInAServer, false, false);
|
modMailMessageManagementService.addMessageToThread(thread, null, sendMessage, initialMessage, aUserInAServer, false, false);
|
||||||
@@ -305,16 +306,17 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
|||||||
* Sends the message containing the pings to notify the staff members to handle the opened {@link ModMailThread}
|
* Sends the message containing the pings to notify the staff members to handle the opened {@link ModMailThread}
|
||||||
* @param user The {@link FullUserInServer} which opened the thread
|
* @param user The {@link FullUserInServer} which opened the thread
|
||||||
* @param channel The created {@link GuildMessageChannel} in which the mod mail thread is dealt with
|
* @param channel The created {@link GuildMessageChannel} in which the mod mail thread is dealt with
|
||||||
|
* @param appeal Whether the modmail thread is for the purpose of an appeal
|
||||||
* @return A {@link CompletableFuture future} which completes when the notification has been sent
|
* @return A {@link CompletableFuture future} which completes when the notification has been sent
|
||||||
*/
|
*/
|
||||||
@Transactional
|
@Transactional
|
||||||
public CompletableFuture<Void> sendModMailNotification(User user, GuildMessageChannel channel) {
|
public CompletableFuture<Void> sendModMailNotification(User user, GuildMessageChannel channel, boolean appeal) {
|
||||||
Long serverId = channel.getGuild().getIdLong();
|
Long serverId = channel.getGuild().getIdLong();
|
||||||
MessageToSend messageToSend = getModmailNotificationMessageToSend(user, channel, serverId, true);
|
MessageToSend messageToSend = getModmailNotificationMessageToSend(user, channel, serverId, true, appeal);
|
||||||
return FutureUtils.toSingleFutureGeneric(postTargetService.sendEmbedInPostTarget(messageToSend, ModMailPostTargets.MOD_MAIL_PING, serverId));
|
return FutureUtils.toSingleFutureGeneric(postTargetService.sendEmbedInPostTarget(messageToSend, ModMailPostTargets.MOD_MAIL_PING, serverId));
|
||||||
}
|
}
|
||||||
|
|
||||||
private MessageToSend getModmailNotificationMessageToSend(User user, GuildMessageChannel channel, Long serverId, boolean pingRole) {
|
private MessageToSend getModmailNotificationMessageToSend(User user, GuildMessageChannel channel, Long serverId, boolean pingRole, boolean appeal) {
|
||||||
log.info("Sending modmail notification for new modmail thread about user {} in server {}.", user.getId(), serverId);
|
log.info("Sending modmail notification for new modmail thread about user {} in server {}.", user.getId(), serverId);
|
||||||
AServer server = serverManagementService.loadServer(serverId);
|
AServer server = serverManagementService.loadServer(serverId);
|
||||||
List<ModMailRole> rolesToPing;
|
List<ModMailRole> rolesToPing;
|
||||||
@@ -328,6 +330,7 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
|||||||
.builder()
|
.builder()
|
||||||
.userDisplay(UserDisplay.fromUser(user))
|
.userDisplay(UserDisplay.fromUser(user))
|
||||||
.roles(rolesToPing)
|
.roles(rolesToPing)
|
||||||
|
.appeal(appeal)
|
||||||
.channel(channel)
|
.channel(channel)
|
||||||
.build();
|
.build();
|
||||||
return templateService.renderEmbedTemplate("modmail_notification_message", modMailNotificationModel, serverId);
|
return templateService.renderEmbedTemplate("modmail_notification_message", modMailNotificationModel, serverId);
|
||||||
@@ -337,14 +340,15 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
|||||||
* Creates the instance of the {@link ModMailThread} in the database.
|
* Creates the instance of the {@link ModMailThread} in the database.
|
||||||
* @param channel The {@link GuildMessageChannel} in which the {@link ModMailThread} is being done
|
* @param channel The {@link GuildMessageChannel} in which the {@link ModMailThread} is being done
|
||||||
* @param user The {@link AUserInAServer} which the thread is about
|
* @param user The {@link AUserInAServer} which the thread is about
|
||||||
|
* @param appeal Whether the modmail thread is for the purpose of an appeal
|
||||||
* @return The created instance of {@link ModMailThread}
|
* @return The created instance of {@link ModMailThread}
|
||||||
*/
|
*/
|
||||||
public ModMailThread createThreadObject(GuildMessageChannel channel, AUserInAServer user) {
|
public ModMailThread createThreadObject(GuildMessageChannel channel, AUserInAServer user, boolean appeal) {
|
||||||
log.info("Creating database objects related to modmail thread in channel {} and about user {} in server {}.", channel.getIdLong(), user.getUserReference().getId(), channel.getGuild().getId());
|
log.info("Creating database objects related to modmail thread in channel {} and about user {} in server {}.", channel.getIdLong(), user.getUserReference().getId(), channel.getGuild().getId());
|
||||||
boolean useThreads = featureModeService.featureModeActive(ModMailFeatureDefinition.MOD_MAIL, channel.getGuild().getIdLong(), ModMailMode.THREAD_CONTAINER);
|
boolean useThreads = featureModeService.featureModeActive(ModMailFeatureDefinition.MOD_MAIL, channel.getGuild().getIdLong(), ModMailMode.THREAD_CONTAINER);
|
||||||
AChannel aChannel = channelManagementService.createChannel(channel.getIdLong(), useThreads ? AChannelType.PUBLIC_THREAD : AChannelType.TEXT, user.getServerReference());
|
AChannel aChannel = channelManagementService.createChannel(channel.getIdLong(), useThreads ? AChannelType.PUBLIC_THREAD : AChannelType.TEXT, user.getServerReference());
|
||||||
log.info("Creating mod mail thread in channel {} with db channel {}", channel.getIdLong(), aChannel.getId());
|
log.info("Creating mod mail thread in channel {} with db channel {}", channel.getIdLong(), aChannel.getId());
|
||||||
return modMailThreadManagementService.createModMailThread(user, aChannel);
|
return modMailThreadManagementService.createModMailThread(user, aChannel, appeal);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -368,103 +372,108 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
|||||||
AServer server = serverManagementService.loadServer(guild);
|
AServer server = serverManagementService.loadServer(guild);
|
||||||
servers.add(server);
|
servers.add(server);
|
||||||
});
|
});
|
||||||
if(!servers.isEmpty()) {
|
|
||||||
log.info("There are {} shared servers between user and the bot.", servers.size());
|
|
||||||
List<ServerChoice> availableGuilds = new ArrayList<>();
|
|
||||||
Set<Long> alreadyConsideredServers = new HashSet<>();
|
|
||||||
for (AServer server : servers) {
|
|
||||||
// only take the servers in which mod mail is actually enabled, would not make much sense to make the
|
|
||||||
// other servers available
|
|
||||||
boolean possibleForModmail = featureFlagService.isFeatureEnabled(modMailFeatureConfig, server);
|
|
||||||
if (possibleForModmail) {
|
|
||||||
Guild guild = guildService.getGuildById(server.getId());
|
|
||||||
ServerChoice serverChoice = ServerChoice
|
|
||||||
.builder()
|
|
||||||
.serverId(guild.getIdLong())
|
|
||||||
.serverName(guild.getName())
|
|
||||||
.build();
|
|
||||||
availableGuilds.add(serverChoice);
|
|
||||||
}
|
|
||||||
alreadyConsideredServers.add(server.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
List<AServer> restOfKnownServers = serverManagementService.getAllServers()
|
if(servers.isEmpty()) {
|
||||||
.stream()
|
log.warn("User {} which was not known in any of the servers tried to contact the bot.", user.getId());
|
||||||
.filter(server -> alreadyConsideredServers.contains(server.getId()))
|
return;
|
||||||
.toList();
|
}
|
||||||
for (AServer server : restOfKnownServers) {
|
|
||||||
boolean possibleForModmail = false;
|
log.info("There are {} shared servers between user and the bot.", servers.size());
|
||||||
Long actualServerId = 0L;
|
List<ServerChoice> availableGuilds = new ArrayList<>();
|
||||||
Long potentialMainServer = configService.getLongValue(ModMailFeatureConfig.MOD_MAIL_APPEAL_SERVER, server.getId()); // what _other_ server is the appeal server
|
Set<Long> alreadyConsideredServers = new HashSet<>();
|
||||||
if(potentialMainServer != 0) {
|
for (AServer server : servers) {
|
||||||
if(featureModeService.featureModeActive(ModMailFeatureDefinition.MOD_MAIL, potentialMainServer, ModMailMode.MOD_MAIL_APPEALS)) {
|
// only take the servers in which mod mail is actually enabled, would not make much sense to make the
|
||||||
Long configuredAppealServerId = configService.getLongValue(ModMailFeatureConfig.MOD_MAIL_APPEAL_SERVER, potentialMainServer);
|
// other servers available
|
||||||
if(configuredAppealServerId != 0 && configuredAppealServerId.equals(server.getId())) { // if the other server has set the current server as the appeal config
|
boolean possibleForModmail = featureFlagService.isFeatureEnabled(modMailFeatureConfig, server);
|
||||||
Guild otherGuild = guildService.getGuildById(potentialMainServer);
|
if (possibleForModmail) {
|
||||||
if(otherGuild != null) { // check if we are part of that server
|
Guild guild = guildService.getGuildById(server.getId());
|
||||||
possibleForModmail = true;
|
ServerChoice serverChoice = ServerChoice
|
||||||
actualServerId = potentialMainServer;
|
.builder()
|
||||||
log.info("Server {} was available, because it is using server {} as a mod mail appeal server.", server.getId(), otherGuild.getIdLong());
|
.serverId(guild.getIdLong())
|
||||||
}
|
.serverName(guild.getName())
|
||||||
|
.build();
|
||||||
|
availableGuilds.add(serverChoice);
|
||||||
|
}
|
||||||
|
alreadyConsideredServers.add(server.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
List<AServer> restOfKnownServers = serverManagementService.getAllServers()
|
||||||
|
.stream()
|
||||||
|
.filter(server -> alreadyConsideredServers.contains(server.getId()))
|
||||||
|
.toList();
|
||||||
|
for (AServer server : restOfKnownServers) {
|
||||||
|
boolean possibleForModmail = false;
|
||||||
|
Long actualServerId = 0L;
|
||||||
|
Long potentialMainServer = configService.getLongValue(ModMailFeatureConfig.MOD_MAIL_APPEAL_SERVER, server.getId()); // what _other_ server is the appeal server
|
||||||
|
if(potentialMainServer != 0) {
|
||||||
|
if(featureModeService.featureModeActive(ModMailFeatureDefinition.MOD_MAIL, potentialMainServer, ModMailMode.MOD_MAIL_APPEALS)) {
|
||||||
|
Long configuredAppealServerId = configService.getLongValue(ModMailFeatureConfig.MOD_MAIL_APPEAL_SERVER, potentialMainServer);
|
||||||
|
if(configuredAppealServerId != 0 && configuredAppealServerId.equals(server.getId())) { // if the other server has set the current server as the appeal config
|
||||||
|
Guild otherGuild = guildService.getGuildById(potentialMainServer);
|
||||||
|
if(otherGuild != null) { // check if we are part of that server
|
||||||
|
possibleForModmail = true;
|
||||||
|
actualServerId = potentialMainServer;
|
||||||
|
log.info("Server {} was available, because it is using server {} as a mod mail appeal server.", server.getId(), otherGuild.getIdLong());
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
log.info("Server {} has set the appeal server {}, but that server does not have mod mail appeals enabled.", server.getId(), potentialMainServer);
|
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
if(possibleForModmail) {
|
log.info("Server {} has set the appeal server {}, but that server does not have mod mail appeals enabled.", server.getId(), potentialMainServer);
|
||||||
Guild guild = guildService.getGuildById(actualServerId);
|
|
||||||
ServerChoice serverChoice = ServerChoice
|
|
||||||
.builder()
|
|
||||||
.serverId(guild.getIdLong())
|
|
||||||
.serverName(guild.getName())
|
|
||||||
.build();
|
|
||||||
availableGuilds.add(serverChoice);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.info("There were {} available servers found.", availableGuilds.size());
|
if(possibleForModmail) {
|
||||||
// if more than 1 server is available, show a choice dialog
|
Guild guild = guildService.getGuildById(actualServerId);
|
||||||
ArrayList<UndoActionInstance> undoActions = new ArrayList<>();
|
ServerChoice serverChoice = ServerChoice
|
||||||
if(availableGuilds.size() > 1) {
|
|
||||||
Map<String, ServerChoice> choices = new HashMap<>();
|
|
||||||
ServerChoices serverChoices = ServerChoices
|
|
||||||
.builder()
|
.builder()
|
||||||
.commonGuilds(choices)
|
.serverId(guild.getIdLong())
|
||||||
.userId(initialMessage.getAuthor().getIdLong())
|
.serverName(guild.getName())
|
||||||
.messageId(initialMessage.getIdLong())
|
.appealModmail(true)
|
||||||
.build();
|
.build();
|
||||||
availableGuilds.forEach(serverChoice -> choices.put(componentService.generateComponentId(), serverChoice));
|
availableGuilds.add(serverChoice);
|
||||||
ModMailServerChooserModel modMailServerChooserModel = ModMailServerChooserModel
|
}
|
||||||
.builder()
|
}
|
||||||
.choices(serverChoices)
|
log.info("There were {} available servers found.", availableGuilds.size());
|
||||||
.build();
|
// if more than 1 server is available, show a choice dialog
|
||||||
MessageToSend messageToSend = templateService.renderEmbedTemplate("modmail_modal_server_choice", modMailServerChooserModel);
|
ArrayList<UndoActionInstance> undoActions = new ArrayList<>();
|
||||||
FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(messageToSend, initialMessage.getChannel()))
|
if(availableGuilds.size() > 1) {
|
||||||
.thenAccept(unused -> self.persistInitialCallbacks(serverChoices))
|
Map<String, ServerChoice> choices = new HashMap<>();
|
||||||
.exceptionally(throwable -> {
|
ServerChoices serverChoices = ServerChoices
|
||||||
log.error("Failed to setup prompt message correctly", throwable);
|
.builder()
|
||||||
undoActionService.performActions(undoActions);
|
.commonGuilds(choices)
|
||||||
return null;
|
.userId(initialMessage.getAuthor().getIdLong())
|
||||||
});
|
.messageId(initialMessage.getIdLong())
|
||||||
log.debug("Displaying server choice message for user {} in channel {}.", user.getId(), initialMessage.getChannel().getId());
|
.build();
|
||||||
} else if(availableGuilds.size() == 1) {
|
availableGuilds.forEach(serverChoice -> choices.put(componentService.generateComponentId(), serverChoice));
|
||||||
// if exactly one server is available, open the thread directly
|
ModMailServerChooserModel modMailServerChooserModel = ModMailServerChooserModel
|
||||||
Long chosenServerId = availableGuilds.get(0).getServerId();
|
.builder()
|
||||||
Guild guild = guildService.getGuildById(chosenServerId);
|
.choices(serverChoices)
|
||||||
log.info("Only one server available to modmail. Directly opening modmail thread for user {} in server {}.", initialMessage.getAuthor().getId(), chosenServerId);
|
.build();
|
||||||
createModMailThreadForUser(initialMessage.getAuthor(), guild , initialMessage, true, undoActions)
|
MessageToSend messageToSend = templateService.renderEmbedTemplate("modmail_modal_server_choice", modMailServerChooserModel);
|
||||||
.thenAccept(messageChannel -> {
|
FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(messageToSend, initialMessage.getChannel()))
|
||||||
log.info("Setup modmail thread for user {} in guild {}.", initialMessage.getAuthor().getIdLong(), guild.getIdLong());
|
.thenAccept(unused -> self.persistInitialCallbacks(serverChoices))
|
||||||
}).exceptionally(throwable -> {
|
.exceptionally(throwable -> {
|
||||||
log.error("Failed to setup modmail channel in guild {} for user {}.", guild.getIdLong(), initialMessage.getAuthor().getIdLong(), throwable);
|
log.error("Failed to setup prompt message correctly", throwable);
|
||||||
|
undoActionService.performActions(undoActions);
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
} else {
|
log.debug("Displaying server choice message for user {} in channel {}.", user.getId(), initialMessage.getChannel().getId());
|
||||||
log.info("No server available to open a modmail thread in.");
|
} else if(availableGuilds.size() == 1) {
|
||||||
// in case there is no server available, send an error message
|
// if exactly one server is available, open the thread directly
|
||||||
channelService.sendEmbedTemplateInMessageChannelList("modmail_no_server_available", new Object(), initialMessage.getChannel());
|
ServerChoice onlyChoice = availableGuilds.get(0);
|
||||||
}
|
Long chosenServerId = onlyChoice.getServerId();
|
||||||
|
Guild guild = guildService.getGuildById(chosenServerId);
|
||||||
|
boolean appeal = onlyChoice.getAppealModmail();
|
||||||
|
log.info("Only one server available to modmail. Directly opening modmail thread for user {} in server {}.", initialMessage.getAuthor().getId(), chosenServerId);
|
||||||
|
createModMailThreadForUser(initialMessage.getAuthor(), guild , initialMessage, true, undoActions, appeal)
|
||||||
|
.thenAccept(messageChannel -> {
|
||||||
|
log.info("Setup modmail thread for user {} in guild {}.", initialMessage.getAuthor().getIdLong(), guild.getIdLong());
|
||||||
|
}).exceptionally(throwable -> {
|
||||||
|
log.error("Failed to setup modmail channel in guild {} for user {}.", guild.getIdLong(), initialMessage.getAuthor().getIdLong(), throwable);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
log.warn("User {} which was not known in any of the servers tried to contact the bot.", user.getId());
|
log.info("No server available to open a modmail thread in.");
|
||||||
|
// in case there is no server available, send an error message
|
||||||
|
channelService.sendEmbedTemplateInMessageChannelList("modmail_no_server_available", new Object(), initialMessage.getChannel());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -98,10 +98,11 @@ public class ModMailThreadManagementServiceBean implements ModMailThreadManageme
|
|||||||
* The status of the created instance is INITIAL.
|
* The status of the created instance is INITIAL.
|
||||||
* @param userInAServer The {@link AUserInAServer} for which the thread was created for
|
* @param userInAServer The {@link AUserInAServer} for which the thread was created for
|
||||||
* @param channel An instance of {@link AChannel} in which the conversation with the member is handled
|
* @param channel An instance of {@link AChannel} in which the conversation with the member is handled
|
||||||
|
* @param appeal Whether the modmail thread is for the purpose of an appeal
|
||||||
* @return the created {@link ModMailThread} instance
|
* @return the created {@link ModMailThread} instance
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ModMailThread createModMailThread(AUserInAServer userInAServer, AChannel channel) {
|
public ModMailThread createModMailThread(AUserInAServer userInAServer, AChannel channel, boolean appeal) {
|
||||||
ModMailThread thread = ModMailThread
|
ModMailThread thread = ModMailThread
|
||||||
.builder()
|
.builder()
|
||||||
.id(channel.getId())
|
.id(channel.getId())
|
||||||
@@ -111,6 +112,7 @@ public class ModMailThreadManagementServiceBean implements ModMailThreadManageme
|
|||||||
.server(userInAServer.getServerReference())
|
.server(userInAServer.getServerReference())
|
||||||
.state(ModMailThreadState.INITIAL)
|
.state(ModMailThreadState.INITIAL)
|
||||||
.updated(Instant.now())
|
.updated(Instant.now())
|
||||||
|
.appeal(appeal)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
log.info("Create modmail thread in channel {} for user {} in server {}.",
|
log.info("Create modmail thread in channel {} for user {} in server {}.",
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||||
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
|
||||||
|
<include file="tables/tables.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:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
|
||||||
|
<changeSet author="Sheldan" id="mod_mail_thread-add_appeal_boolean">
|
||||||
|
<addColumn tableName="mod_mail_thread">
|
||||||
|
<column name="appeal" type="BOOLEAN" defaultValue="false">
|
||||||
|
<constraints nullable="false" />
|
||||||
|
</column>
|
||||||
|
</addColumn>
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||||
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
|
||||||
|
<include file="modmail_thread.xml" relativeToChangelogFile="true"/>
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -4,4 +4,5 @@
|
|||||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
|
||||||
<include file="1.0-modmail/collection.xml" relativeToChangelogFile="true"/>
|
<include file="1.0-modmail/collection.xml" relativeToChangelogFile="true"/>
|
||||||
<include file="1.5.37/collection.xml" relativeToChangelogFile="true"/>
|
<include file="1.5.37/collection.xml" relativeToChangelogFile="true"/>
|
||||||
|
<include file="1.5.51/collection.xml" relativeToChangelogFile="true"/>
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
||||||
@@ -59,6 +59,9 @@ public class ModMailThread implements Serializable {
|
|||||||
@Column(name = "closed")
|
@Column(name = "closed")
|
||||||
private Instant closed;
|
private Instant closed;
|
||||||
|
|
||||||
|
@Column(name = "appeal", nullable = false)
|
||||||
|
private Boolean appeal;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The messages which were officially posted in the context of the mod mail thread. Either via command (from the
|
* The messages which were officially posted in the context of the mod mail thread. Either via command (from the
|
||||||
* staff side of view) or by messaging the bot (from the member view)
|
* staff side of view) or by messaging the bot (from the member view)
|
||||||
|
|||||||
@@ -8,11 +8,14 @@ import lombok.Getter;
|
|||||||
@Builder
|
@Builder
|
||||||
public class ServerChoicePayload {
|
public class ServerChoicePayload {
|
||||||
private Long serverId;
|
private Long serverId;
|
||||||
|
@Builder.Default
|
||||||
|
private Boolean appealModmail = false;
|
||||||
|
|
||||||
public static ServerChoicePayload fromServerChoice(ServerChoice choice) {
|
public static ServerChoicePayload fromServerChoice(ServerChoice choice) {
|
||||||
return ServerChoicePayload
|
return ServerChoicePayload
|
||||||
.builder()
|
.builder()
|
||||||
.serverId(choice.getServerId())
|
.serverId(choice.getServerId())
|
||||||
|
.appealModmail(choice.getAppealModmail())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,4 +32,8 @@ public class ModMailNotificationModel extends ServerContext {
|
|||||||
* The {@link GuildMessageChannel} in which the mod mail thread is handled
|
* The {@link GuildMessageChannel} in which the mod mail thread is handled
|
||||||
*/
|
*/
|
||||||
private GuildMessageChannel channel;
|
private GuildMessageChannel channel;
|
||||||
|
/**
|
||||||
|
* Whether the modmail is created for the purpose of an appeal
|
||||||
|
*/
|
||||||
|
private boolean appeal;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,4 +8,6 @@ import lombok.Getter;
|
|||||||
public class ServerChoice {
|
public class ServerChoice {
|
||||||
private String serverName;
|
private String serverName;
|
||||||
private Long serverId;
|
private Long serverId;
|
||||||
|
@Builder.Default
|
||||||
|
private Boolean appealModmail = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,11 +25,12 @@ public interface ModMailThreadService {
|
|||||||
* @param user The {@link User} to create the mod mail thread for
|
* @param user The {@link User} to create the mod mail thread for
|
||||||
* @param guild The {@link Guild} in which the mod mail thread should be created in
|
* @param guild The {@link Guild} in which the mod mail thread should be created in
|
||||||
* @param initialMessage The initial message sparking this mod mail thread, null in case it was created by a command
|
* @param initialMessage The initial message sparking this mod mail thread, null in case it was created by a command
|
||||||
* @param userInitiated Whether or not the mod mail thread was initiated by a user
|
* @param userInitiated Whether the mod mail thread was initiated by a user
|
||||||
* @param undoActions A list of {@link dev.sheldan.abstracto.core.models.UndoAction actions} to be undone in case the operation fails. This list will be filled in the method.
|
* @param undoActions A list of {@link dev.sheldan.abstracto.core.models.UndoAction actions} to be undone in case the operation fails. This list will be filled in the method.
|
||||||
|
* @param appeal Whether the modmail thread was created for the purpose of an appeal
|
||||||
* @return A {@link CompletableFuture future} which completes when the modmail thread is set up
|
* @return A {@link CompletableFuture future} which completes when the modmail thread is set up
|
||||||
*/
|
*/
|
||||||
CompletableFuture<MessageChannel> createModMailThreadForUser(User user, Guild guild, Message initialMessage, boolean userInitiated, List<UndoActionInstance> undoActions);
|
CompletableFuture<MessageChannel> createModMailThreadForUser(User user, Guild guild, Message initialMessage, boolean userInitiated, List<UndoActionInstance> undoActions, boolean appeal);
|
||||||
|
|
||||||
CompletableFuture<Void> sendContactNotification(User user, MessageChannel createdMessageChannel, MessageChannel feedBackChannel);
|
CompletableFuture<Void> sendContactNotification(User user, MessageChannel createdMessageChannel, MessageChannel feedBackChannel);
|
||||||
CompletableFuture<Void> sendContactNotification(User user, MessageChannel createdMessageChannel, InteractionHook interactionHook);
|
CompletableFuture<Void> sendContactNotification(User user, MessageChannel createdMessageChannel, InteractionHook interactionHook);
|
||||||
|
|||||||
@@ -104,9 +104,10 @@ public interface ModMailThreadManagementService {
|
|||||||
* Creates an instance of {@link ModMailThread} with the appropriate parameters and returns the created instance.
|
* Creates an instance of {@link ModMailThread} with the appropriate parameters and returns the created instance.
|
||||||
* @param userInAServer The {@link AUserInAServer} for which the thread was created for
|
* @param userInAServer The {@link AUserInAServer} for which the thread was created for
|
||||||
* @param channel An instance of {@link AChannel} in which the conversation with the member is handled
|
* @param channel An instance of {@link AChannel} in which the conversation with the member is handled
|
||||||
|
* @param appeal Whether the modmail thread is for the purpose of an appeal
|
||||||
* @return The created instance of {@link ModMailThread}
|
* @return The created instance of {@link ModMailThread}
|
||||||
*/
|
*/
|
||||||
ModMailThread createModMailThread(AUserInAServer userInAServer, AChannel channel);
|
ModMailThread createModMailThread(AUserInAServer userInAServer, AChannel channel, boolean appeal);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the {@link ModMailThread} with the new state and saves the instance.
|
* Updates the {@link ModMailThread} with the new state and saves the instance.
|
||||||
|
|||||||
Reference in New Issue
Block a user