fixed command and feature mapping

added a bunch of java doc to moderation interface
added check in case the text channel on the server was deleted while the mod mail thread was still open
This now returns an error to the user side and prompts to message the bot again in order to create a new mod mail thread
This commit is contained in:
Sheldan
2020-05-12 22:44:44 +02:00
parent 8d8f735672
commit 5755d033eb
25 changed files with 338 additions and 21 deletions

View File

@@ -24,18 +24,18 @@ public class MuteManagementServiceBean implements MuteManagementService {
private UserInServerManagementService userInServerManagementService;
@Override
public Mute createMute(AUserInAServer aUserInAServer, AUserInAServer mutingUser, String reason, Instant unmuteDate, AServerAChannelMessage origin) {
public Mute createMute(AUserInAServer mutedUser, AUserInAServer mutingUser, String reason, Instant unmuteDate, AServerAChannelMessage muteMessage) {
log.trace("Creating mute for user {} executed by user {} in server {}, user will be unmuted at {}",
aUserInAServer.getUserReference().getId(), mutingUser.getUserReference().getId(), aUserInAServer.getServerReference().getId(), unmuteDate);
mutedUser.getUserReference().getId(), mutingUser.getUserReference().getId(), mutedUser.getServerReference().getId(), unmuteDate);
Mute mute = Mute
.builder()
.muteDate(Instant.now())
.mutedUser(aUserInAServer)
.mutedUser(mutedUser)
.mutingUser(mutingUser)
.muteTargetDate(unmuteDate)
.mutingServer(aUserInAServer.getServerReference())
.mutingChannel(origin.getChannel())
.messageId(origin.getMessageId())
.mutingServer(mutedUser.getServerReference())
.mutingChannel(muteMessage.getChannel())
.messageId(muteMessage.getMessageId())
.reason(reason)
.muteEnded(false)
.build();
@@ -65,8 +65,8 @@ public class MuteManagementServiceBean implements MuteManagementService {
}
@Override
public Mute getAMuteOf(Member userInAServer) {
return getAMuteOf(userInServerManagementService.loadUser(userInAServer));
public Mute getAMuteOf(Member member) {
return getAMuteOf(userInServerManagementService.loadUser(member));
}
@Override

View File

@@ -9,6 +9,9 @@ import javax.persistence.*;
import java.time.Instant;
import java.util.Objects;
/**
* Table used to store mutes in order to track when the mute was cast and when it ended.
*/
@Entity
@Table(name="mute")
@Builder
@@ -18,37 +21,70 @@ import java.util.Objects;
@Setter
public class Mute {
/**
* The globally unique id of the mute.
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
/**
* The {@link AUserInAServer} which was muted
*/
@ManyToOne
@JoinColumn(name = "mutedUser", nullable = false)
private AUserInAServer mutedUser;
/**
* The {@link AUserInAServer} which casted the mute
*/
@ManyToOne
@JoinColumn(name = "mutingUser", nullable = false)
private AUserInAServer mutingUser;
/**
* The reason of the mute which is stored
*/
private String reason;
/**
* The date when the mute was cast, and the start date
*/
private Instant muteDate;
/**
* The date at which this mute should be removed in the future
*/
private Instant muteTargetDate;
/**
* Whether or not the mute already ended, be it manually or when the time passed
*/
private Boolean muteEnded;
/**
* The message which contained the command which caused this mute
*/
@Column
private Long messageId;
/**
* The {@link AServer} in which this mute was cast
*/
@ManyToOne
@JoinColumn(name = "mutingServer", nullable = false)
private AServer mutingServer;
/**
* The channel in which this mute was cast
*/
@ManyToOne
@JoinColumn(name = "mutingChannel")
private AChannel mutingChannel;
/**
* When the mute is scheduled to be un-done with quartz, this stores the quartz trigger in order to cancel it, if need be.
*/
private String triggerKey;
@Override

View File

@@ -7,6 +7,9 @@ import javax.persistence.*;
import java.time.Instant;
import java.util.Objects;
/**
* A warning which was given a member with a special reason by a moderating member. This warning is bound to a server.
*/
@Entity
@Table(name="warning")
@Builder
@@ -14,31 +17,52 @@ import java.util.Objects;
@NoArgsConstructor
public class Warning {
/**
* The globally unique id of this warning
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Getter
private Long id;
/**
* The {@link AUserInAServer} which was warned
*/
@Getter
@ManyToOne
@JoinColumn(name = "warnedUserId", nullable = false)
private AUserInAServer warnedUser;
/**
* The {@link AUserInAServer} which gave the warning
*/
@Getter
@ManyToOne
@JoinColumn(name = "warningUserId", nullable = false)
private AUserInAServer warningUser;
/**
* The reason why this warning was cast
*/
@Getter
private String reason;
/**
* The date at which the warning was cast
*/
@Getter
private Instant warnDate;
/**
* Whether or not the warning was already decayed and is not active anymore
*/
@Getter
@Setter
private Boolean decayed;
/**
* The date at which the warning was decayed
*/
@Getter
@Setter
private Instant decayDate;

View File

@@ -6,12 +6,26 @@ import lombok.Setter;
import lombok.experimental.SuperBuilder;
import net.dv8tion.jda.api.entities.Member;
/**
* Used when rendering the notification when a member was banned by ID. The template is: "banid_log_embed"
*/
@Getter
@SuperBuilder
@Setter
public class BanIdLog extends UserInitiatedServerContext {
/**
* The reason of the ban
*/
private String reason;
/**
* The member executing the ban
*/
private Member banningUser;
/**
* The Discord Snowflake of the user being banned.
*/
private Long bannedUserId;
}

View File

@@ -6,12 +6,24 @@ import lombok.Setter;
import lombok.experimental.SuperBuilder;
import net.dv8tion.jda.api.entities.Member;
/**
* Used when rendering the notification when a member was banned. The template is: "ban_log_embed"
*/
@Getter
@SuperBuilder
@Setter
public class BanLog extends UserInitiatedServerContext {
/**
* The reason of the ban
*/
private String reason;
/**
* The member executing the ban
*/
private Member banningUser;
/**
* The member being banned
*/
private Member bannedUser;
}

View File

@@ -6,11 +6,23 @@ import lombok.Setter;
import lombok.experimental.SuperBuilder;
import net.dv8tion.jda.api.entities.Member;
/**
* Used when rendering the notification when a member was kicked. The template is: "kick_log_embed"
*/
@Getter
@SuperBuilder
@Setter
public class KickLogModel extends UserInitiatedServerContext {
/**
* The reason of the kick
*/
private String reason;
/**
* The member executing the kick
*/
private Member kickingUser;
/**
* The member being kicked
*/
private Member kickedUser;
}

View File

@@ -11,16 +11,34 @@ import net.dv8tion.jda.api.entities.Message;
import java.time.Duration;
/**
* Used when rendering the notification when a member was muted. The template is: "mute_log_embed"
*/
@Getter
@SuperBuilder
@Setter
public class MuteLog extends UserInitiatedServerContext {
/**
* The {@link Member} being muted
*/
private Member mutedUser;
/**
* The {@link Member} executing the mute
*/
private Member mutingUser;
/**
* The {@link Message} triggering the command to mute
*/
private Message message;
/**
* The persisted mute object from the database containing the information about the mute
*/
private Mute mute;
/**
* The {@link Duration} of the mute between the mute was cast and and the date it should end
* @return The {@link Duration} between start and target date
*/
public Duration getMuteDuration() {
return Duration.between(mute.getMuteDate(), mute.getMuteTargetDate());
}

View File

@@ -4,9 +4,18 @@ import dev.sheldan.abstracto.moderation.models.database.Mute;
import lombok.Builder;
import lombok.Value;
/**
* Used to render the message notification send to the member informing about the mute. The template is: "mute_notification"
*/
@Value
@Builder
public class MuteNotification {
/**
* The persisted mute object from the database containing the information about the mute
*/
private Mute mute;
/**
* The name of the server in which the user was muted.
*/
private String serverName;
}

View File

@@ -5,10 +5,19 @@ import lombok.Getter;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
/**
* Used to render the response of the myWarnings command. The template is: 'myWarnings_response_embed'
*/
@Getter
@Setter
@SuperBuilder
public class MyWarningsModel extends UserInitiatedServerContext {
/**
* The total amount of warnings the member has
*/
private Long totalWarnCount;
/**
* The current (only active) amount of warnings the member has
*/
private Long currentWarnCount;
}

View File

@@ -12,28 +12,55 @@ import net.dv8tion.jda.api.entities.Member;
import java.time.Duration;
import java.time.Instant;
/**
* Used when rendering the notification when a member was muted. The template is: "unmute_log_embed"
*/
@Getter
@SuperBuilder
@Setter
@NoArgsConstructor
public class UnMuteLog extends ServerContext {
/**
* The un-muted Member, is null if the member left the server
*/
private Member unMutedUser;
/**
* The user casting the mute, is null if the member left the server
*/
private Member mutingUser;
/**
* The persisted mute object from the database containing the information about the mute
*/
private Mute mute;
/**
* The actual duration between the date the mute started and the current time
* @return The difference between mute start and now
*/
public Duration getMuteDuration() {
return Duration.between(mute.getMuteDate(), Instant.now());
}
/**
* The duration between the date the mute started and the un-mute planned
* @return The difference between mute start and the target date
*/
public Duration getPlannedMuteDuration() {
return Duration.between(mute.getMuteDate(), mute.getMuteTargetDate());
}
/**
* The un-mute date, which is now, because this is the un-mute log message.
* @return The current time stamp
*/
public Instant getUnmuteDate() {
return Instant.now();
}
/**
* Builds the link to the original message triggering the mute
* @return A string containing an URL leading to the message where the mute was triggered
*/
public String getMessageUrl() {
return MessageUtils.buildMessageUrl(this.mute.getMutingServer().getId() ,this.getMute().getMutingChannel().getId(), this.mute.getMessageId());
}

View File

@@ -6,11 +6,24 @@ import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
/**
* A single warning containing the full user instead of only the warning object when the warnings command is executed.
* The template is: "warnings_warn_entry"
*/
@Getter
@Setter
@Builder
public class WarnEntry {
/**
* The {@link Warning} of this entry
*/
private Warning warning;
/**
* The {@link FullUser} containing information about the user being warned. The member property is null if the user left the server
*/
private FullUser warnedUser;
/**
* The {@link FullUser} containing information about the user warning. The member property is null if the user left the server
*/
private FullUser warningUser;
}

View File

@@ -8,14 +8,31 @@ import lombok.experimental.SuperBuilder;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
/**
* Used when rendering the notification when a member was warned. The template is: "warn_log_embed"
*/
@Getter
@SuperBuilder
@Setter
public class WarnLog extends UserInitiatedServerContext {
/**
* The reason why the warn was cast
*/
private String reason;
/**
* The {@link Member} being warned
*/
private Member warnedUser;
/**
* The {@link Member} casting the warn
*/
private Member warningUser;
/**
* The {@link Message} which contained the command triggering the warn
*/
private Message message;
/**
* The persisted {@link Warning} object from the database containing the information about the warning
*/
private Warning warning;
}

View File

@@ -4,9 +4,18 @@ import dev.sheldan.abstracto.moderation.models.database.Warning;
import lombok.Builder;
import lombok.Value;
/**
* Used to render the message notification send to the member informing about the warn. The template is: "warn_notification"
*/
@Value
@Builder
public class WarnNotification {
/**
* The persisted mute object from the database containing the information about the warning
*/
private Warning warning;
/**
* The name of the server on which the warn was cast
*/
private String serverName;
}

View File

@@ -7,9 +7,15 @@ import lombok.experimental.SuperBuilder;
import java.util.List;
/**
* Used to render the paginator used to display all the warnings of a user or all users. The template is: "warnings_response_paginator"
*/
@Getter
@Setter
@SuperBuilder
public class WarningsModel extends UserInitiatedServerContext {
/**
* A collection of {@link dev.sheldan.abstracto.moderation.models.database.Warning}s being rendered, might be all warnings of the server, or only the warnings of a specific user
*/
private List<WarnEntry> warnings;
}

View File

@@ -7,9 +7,15 @@ import lombok.experimental.SuperBuilder;
import java.util.List;
/**
* Used when rendering the log message when warnings were decayed. The template is: "warn_decay_log_embed"
*/
@Getter
@Setter
@SuperBuilder
public class WarnDecayLogModel extends ServerContext {
/**
* The warnings which were decayed
*/
private List<WarnDecayWarning> warnings;
}

View File

@@ -6,11 +6,24 @@ import lombok.Getter;
import lombok.Setter;
import net.dv8tion.jda.api.entities.Member;
/**
* A single warning containing the full user instead of only the warning object when logging the decayed warnings
* The template is: "warnDecay_log_warn_entry_en_US.ftl"
*/
@Getter
@Setter
@Builder
public class WarnDecayWarning {
/**
* The persisted {@link Warning} object from the database containing the information about the warning
*/
private Warning warning;
/**
* The member which was warned, is null if the user left the server
*/
private Member warnedMember;
/**
* The user which casted the warn, is null if the user left the server
*/
private Member warningMember;
}

View File

@@ -5,8 +5,20 @@ import lombok.Getter;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
@Getter @Setter @SuperBuilder
/**
* Used when rendering the attachment message, when the message contained multiple attachments.
* The template is: "message_deleted_attachment_embed"
*/
@Getter
@Setter
@SuperBuilder
public class MessageDeletedAttachmentLog extends UserInitiatedServerContext {
/**
* The proxy URL to the attachment which was deleted.
*/
private String imageUrl;
/**
* The index of this attachment in the deleted message.
*/
private Integer counter;
}

View File

@@ -6,7 +6,15 @@ import lombok.Getter;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
@Getter @Setter @SuperBuilder
/**
* Used when rendering the log message when a message was deleted. The template is: "message_deleted_embed"
*/
@Getter
@Setter
@SuperBuilder
public class MessageDeletedLog extends UserInitiatedServerContext {
/**
* A {@link CachedMessage} representing the deleted message
*/
private CachedMessage message;
}

View File

@@ -7,8 +7,20 @@ import lombok.Setter;
import lombok.experimental.SuperBuilder;
import net.dv8tion.jda.api.entities.Message;
@Getter @Setter @SuperBuilder
/**
* Used when rendering the log message when a message was edited. The template is: "message_edited_embed"
*/
@Getter
@Setter
@SuperBuilder
public class MessageEditedLog extends UserInitiatedServerContext {
/**
* The {@link Message} instance which contains the new content of the message
*/
private Message messageAfter;
/**
* The {@link CachedMessage} which contains the message before the edit was made
*/
private CachedMessage messageBefore;
}

View File

@@ -8,12 +8,60 @@ import net.dv8tion.jda.api.entities.Member;
import java.time.Instant;
import java.util.List;
/**
* Responsible for creating/updating/retrieving mutes in the database.
*/
public interface MuteManagementService {
Mute createMute(AUserInAServer aUserInAServer, AUserInAServer mutingUser, String reason, Instant unmuteDate, AServerAChannelMessage creation);
/**
* Creates a mute object with the given parameters. The only parameter set by this method is that, the mute is not ended yet.
* @param mutedUser The member which is being muted
* @param mutingUser The member which mutes
* @param reason The reason why this user is getting muted
* @param unmuteDate The date at which the mute should end
* @param muteMessage The message containing the command which caused the mute
* @return The created mute object containing the mute ID
*/
Mute createMute(AUserInAServer mutedUser, AUserInAServer mutingUser, String reason, Instant unmuteDate, AServerAChannelMessage muteMessage);
/**
* Finds the mute from the database by the given ID.
* @param muteId The id of the mute to search for
* @return The found {@link Mute}, the first access fails, if the entity was not found
*/
Mute findMute(Long muteId);
/**
* Saves the given mute to the database.
* @param mute The {@link Mute} to save
* @return The (maybe) updated {@link Mute} object
*/
Mute saveMute(Mute mute);
/**
* Returns if the given {@link AUserInAServer} has an active mute which has not yet been ended yet.
* @param userInAServer The {@link AUserInAServer} to check for
* @return Whether or not the userInAServer has an active mute
*/
boolean hasActiveMute(AUserInAServer userInAServer);
/**
* Returns any active {@link Mute} of this {@link AUserInAServer} in the database
* @param userInAServer The {@link AUserInAServer} to search a mute for
* @return The found {@link Mute}, and null if none was found
*/
Mute getAMuteOf(AUserInAServer userInAServer);
Mute getAMuteOf(Member userInAServer);
/**
* Returns any active {@link Mute} of this {@link Member} in the databaes
* @param member The {@link Member} to search a mute for
* @return The found {@link Mute}, and null if none was found
*/
Mute getAMuteOf(Member member);
/**
* Retrieves all active mutes of the given {@link AUserInAServer} in a collection
* @param aUserInAServer The {@link AUserInAServer} to search the actie mutes for
* @return A collection of {@link Mute} objects of the user which are active
*/
List<Mute> getAllMutesOf(AUserInAServer aUserInAServer);
}

View File

@@ -249,6 +249,11 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
if(textChannelFromServer.isPresent()) {
TextChannel textChannel = textChannelFromServer.get();
self.sendUserReply(textChannel, modMailThread, message);
} else {
// in this case there was no text channel on the server associated with the mod mail thread
// close the existing one, so the user can start a new one
message.getChannel().sendMessage(templateService.renderTemplate("modmail_failed_to_forward_message", new Object())).queue();
self.closeModMailThreadInDb(modMailThread.getId());
}
}