[AB-xxx] adding modmail support for ban appeals

refactoring modmail to use user objects instead of member in various places
This commit is contained in:
Sheldan
2024-05-31 00:54:32 +02:00
parent 4991ad8f1c
commit 336c3d0bd8
29 changed files with 386 additions and 618 deletions

View File

@@ -21,6 +21,7 @@ import java.util.List;
public class ModMailFeatureConfig implements FeatureConfig {
public static final String MOD_MAIL_CLOSING_TEXT_SYSTEM_CONFIG_KEY = "modMailClosingText";
public static final String MOD_MAIL_APPEAL_SERVER = "modMailAppealServer";
@Autowired
private ModMailFeatureValidator modMailFeatureValidator;
@@ -34,27 +35,33 @@ public class ModMailFeatureConfig implements FeatureConfig {
@Override
public List<PostTargetEnum> getRequiredPostTargets() {
return Arrays.asList(ModMailPostTargets.MOD_MAIL_PING, ModMailPostTargets.MOD_MAIL_LOG, ModMailPostTargets.MOD_MAIL_CONTAINER);
return List.of(ModMailPostTargets.MOD_MAIL_PING,
ModMailPostTargets.MOD_MAIL_LOG,
ModMailPostTargets.MOD_MAIL_CONTAINER);
}
@Override
public List<FeatureValidator> getAdditionalFeatureValidators() {
return Arrays.asList(modMailFeatureValidator);
return List.of(modMailFeatureValidator);
}
@Override
public List<String> getRequiredEmotes() {
return Arrays.asList("readReaction");
return List.of("readReaction");
}
@Override
public List<FeatureMode> getAvailableModes() {
return Arrays.asList(ModMailMode.LOGGING, ModMailMode.SEPARATE_MESSAGE, ModMailMode.THREAD_CONTAINER);
return List.of(ModMailMode.LOGGING,
ModMailMode.SEPARATE_MESSAGE,
ModMailMode.THREAD_CONTAINER,
ModMailMode.MOD_MAIL_APPEALS
);
}
@Override
public List<String> getRequiredSystemConfigKeys() {
return Arrays.asList(MOD_MAIL_CLOSING_TEXT_SYSTEM_CONFIG_KEY);
return List.of(MOD_MAIL_CLOSING_TEXT_SYSTEM_CONFIG_KEY, MOD_MAIL_APPEAL_SERVER);
}
@Override

View File

@@ -9,7 +9,10 @@ import lombok.Getter;
*/
@Getter
public enum ModMailMode implements FeatureMode {
LOGGING("log"), SEPARATE_MESSAGE("threadMessage"), THREAD_CONTAINER("threadContainer");
LOGGING("log"),
SEPARATE_MESSAGE("threadMessage"),
THREAD_CONTAINER("threadContainer"),
MOD_MAIL_APPEALS("modMailAppeals");
private final String key;

View File

@@ -13,6 +13,5 @@ public class ClosingContext {
private Boolean notifyUser;
private Boolean log;
private Member closingMember;
private Channel channel;
private String note;
}

View File

@@ -1,15 +1,15 @@
package dev.sheldan.abstracto.modmail.model.template;
import dev.sheldan.abstracto.core.models.template.display.UserDisplay;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
@Getter
@Setter
@Builder
public class ContactNotificationModel {
private Member targetMember;
private UserDisplay userDisplay;
private MessageChannel createdChannel;
}

View File

@@ -1,6 +1,6 @@
package dev.sheldan.abstracto.modmail.model.template;
import dev.sheldan.abstracto.core.models.FullUserInServer;
import dev.sheldan.abstracto.core.models.template.display.UserDisplay;
import dev.sheldan.abstracto.modmail.model.database.ModMailThread;
import lombok.Builder;
import lombok.Getter;
@@ -18,10 +18,7 @@ import java.util.Map;
@Setter
@Builder
public class ModMailModeratorReplyModel {
/**
* A {@link FullUserInServer} reference representing the user the thread is about. The member attribute is null, if the user left the guild
*/
private FullUserInServer threadUser;
private UserDisplay userDisplay;
/**
* The staff {@link Member} which replied to the thread, be it anonymously or normal.
*/

View File

@@ -1,13 +1,12 @@
package dev.sheldan.abstracto.modmail.model.template;
import dev.sheldan.abstracto.core.models.FullUserInServer;
import dev.sheldan.abstracto.core.models.context.ServerContext;
import dev.sheldan.abstracto.core.models.template.display.UserDisplay;
import dev.sheldan.abstracto.modmail.model.database.ModMailRole;
import dev.sheldan.abstracto.modmail.model.database.ModMailThread;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
import java.util.List;
@@ -24,10 +23,7 @@ public class ModMailNotificationModel extends ServerContext {
* The created {@link ModMailThread} which was just created
*/
private ModMailThread modMailThread;
/**
* The {@link FullUserInServer} for which this thread is about
*/
private Member member;
private UserDisplay userDisplay;
/**
* A list of roles which will be notified upon creation of the mod mail thread.
*/

View File

@@ -1,12 +1,10 @@
package dev.sheldan.abstracto.modmail.model.template;
import dev.sheldan.abstracto.core.models.template.display.UserDisplay;
import dev.sheldan.abstracto.modmail.model.database.ModMailThread;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import net.dv8tion.jda.api.entities.Member;
import java.time.Instant;
/**
* This is the model used when a new mod mail thread is opened and a message containing some information about the user
@@ -16,16 +14,12 @@ import java.time.Instant;
@Setter
@Builder
public class ModMailThreaderHeader {
/**
* A {@link Member} instance to retrieve information from
*/
private Member member;
private UserDisplay userDisplay;
/**
* The latest {@link ModMailThread}, before the current opened one. This is null if there is no closed mod mail thread
* for the user
*/
private ModMailThread latestModMailThread;
private Instant memberJoinDate;
/**
* The amount of previous mod mail thread the user has.
*/

View File

@@ -1,5 +1,6 @@
package dev.sheldan.abstracto.modmail.model.template;
import dev.sheldan.abstracto.core.models.template.display.UserDisplay;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
@@ -16,10 +17,7 @@ import java.util.Map;
@Setter
@Builder
public class ModMailUserReplyModel {
/**
* The {@link Member} from which the message is and whose mod mail thread it is
*/
private Member member;
private UserDisplay userDisplay;
/**
* The {@link Message} which was posted, which contains all the possible information
*/

View File

@@ -22,16 +22,16 @@ public interface ModMailThreadService {
* Creates a new mod mail thread for the given user. including: the {@link net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel}
* in the appropriate {@link net.dv8tion.jda.api.entities.channel.concrete.Category} and calls the methods responsible for storing
* the necessary data in the database, notifying the users and sending messages related to the creation of the {@link ModMailThread}
* @param member The {@link AUserInAServer} to create the mod mail thread for
* @param user The {@link User} to create the mod mail thread for
* @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 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.
* @return A {@link CompletableFuture future} which completes when the modmail thread is set up
*/
CompletableFuture<MessageChannel> createModMailThreadForUser(Member member, Message initialMessage, boolean userInitiated, List<UndoActionInstance> undoActions);
CompletableFuture<MessageChannel> createModMailThreadForUser(User user, Guild guild, Message initialMessage, boolean userInitiated, List<UndoActionInstance> undoActions);
CompletableFuture<Void> sendContactNotification(Member member, MessageChannel createdMessageChannel, MessageChannel feedBackChannel);
CompletableFuture<Void> sendContactNotification(Member member, MessageChannel createdMessageChannel, InteractionHook interactionHook);
CompletableFuture<Void> sendContactNotification(User user, MessageChannel createdMessageChannel, MessageChannel feedBackChannel);
CompletableFuture<Void> sendContactNotification(User user, MessageChannel createdMessageChannel, InteractionHook interactionHook);
/**
* Changes the configuration value of the category used to create mod mail threads to the given ID.
@@ -68,10 +68,11 @@ public interface ModMailThreadService {
* @param text The parsed text of the reply
* @param message The pure {@link Message} containing the command which caused the reply
* @param anonymous Whether or nor the message should be send anonymous
* @param targetMember The {@link Member} the {@link ModMailThread} is about.
* @param targetUser The {@link User} the {@link ModMailThread} is about.
* @param guild The guild the reply is created in
* @return A {@link CompletableFuture future} which completes when the message has been relayed to the DM
*/
CompletableFuture<Void> loadExecutingMemberAndRelay(Long threadId, String text, Message message, boolean anonymous, Member targetMember);
CompletableFuture<Void> loadExecutingMemberAndRelay(Long threadId, String text, Message message, boolean anonymous, User targetUser, Guild guild);
/**
* Closes the mod mail thread which means: deletes the {@link net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel} associated with the mod mail thread,
@@ -98,4 +99,6 @@ public interface ModMailThreadService {
boolean isModMailThread(AChannel channel);
boolean isModMailThread(Long channelId);
CompletableFuture<Void> rejectAppeal(ModMailThread modMailThread, String reason, Member memberPerforming);
}