mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-14 19:56:29 +00:00
[AB-167] adding warning created events and infraction counter
adding disabling of post targets adding some logging for message sending failure consumer
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package dev.sheldan.abstracto.moderation.config.feature;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.config.PostTargetEnum;
|
||||
import dev.sheldan.abstracto.moderation.config.posttarget.InfractionPostTarget;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class InfractionFeatureConfig implements FeatureConfig {
|
||||
|
||||
public static final String INFRACTION_LEVELS = "infractionLevels";
|
||||
public static final String INFRACTION_LEVEL_PREFIX = "infractionLevel";
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return ModerationFeatureDefinition.INFRACTIONS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getRequiredSystemConfigKeys() {
|
||||
return Arrays.asList(INFRACTION_LEVELS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PostTargetEnum> getRequiredPostTargets() {
|
||||
return Arrays.asList(InfractionPostTarget.INFRACTION_NOTIFICATION);
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,8 @@ public enum ModerationFeatureDefinition implements FeatureDefinition {
|
||||
AUTOMATIC_WARN_DECAY("warnDecay"),
|
||||
USER_NOTES("userNotes"),
|
||||
INVITE_FILTER("inviteFilter"),
|
||||
REPORT_REACTIONS("reportReactions")
|
||||
REPORT_REACTIONS("reportReactions"),
|
||||
INFRACTIONS("infractions")
|
||||
;
|
||||
|
||||
private final String key;
|
||||
|
||||
@@ -15,6 +15,8 @@ import java.util.List;
|
||||
@Component
|
||||
public class WarningFeatureConfig implements FeatureConfig {
|
||||
|
||||
public static final String WARN_INFRACTION_POINTS = "warnInfractionPoints";
|
||||
|
||||
@Autowired
|
||||
private WarningDecayFeatureConfig warningDecayFeatureConfig;
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package dev.sheldan.abstracto.moderation.config.posttarget;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.PostTargetEnum;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum InfractionPostTarget implements PostTargetEnum {
|
||||
INFRACTION_NOTIFICATION("infractionNotification");
|
||||
|
||||
private String key;
|
||||
|
||||
InfractionPostTarget(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package dev.sheldan.abstracto.moderation.listener;
|
||||
|
||||
import dev.sheldan.abstracto.core.listener.DefaultListenerResult;
|
||||
import dev.sheldan.abstracto.core.listener.FeatureAwareListener;
|
||||
import dev.sheldan.abstracto.moderation.model.listener.InfractionLevelChangedEventModel;
|
||||
|
||||
public interface InfractionLevelChangedListener extends FeatureAwareListener<InfractionLevelChangedEventModel, DefaultListenerResult> {
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package dev.sheldan.abstracto.moderation.listener;
|
||||
|
||||
import dev.sheldan.abstracto.core.listener.DefaultListenerResult;
|
||||
import dev.sheldan.abstracto.core.listener.FeatureAwareListener;
|
||||
import dev.sheldan.abstracto.moderation.model.listener.WarningCreatedEventModel;
|
||||
|
||||
public interface WarningCreatedListener extends FeatureAwareListener<WarningCreatedEventModel, DefaultListenerResult> {
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package dev.sheldan.abstracto.moderation.model.database;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import lombok.*;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.time.Instant;
|
||||
|
||||
@Entity
|
||||
@Table(name="infraction")
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
@EqualsAndHashCode
|
||||
public class Infraction {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Long id;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "infraction_user_in_server_id", nullable = false)
|
||||
private AUserInAServer user;
|
||||
|
||||
@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "server_id", referencedColumnName = "id", nullable = false)
|
||||
private AServer server;
|
||||
|
||||
@Column(name = "points")
|
||||
private Long points;
|
||||
|
||||
@Column(name = "decayed")
|
||||
private Boolean decayed;
|
||||
|
||||
@Column(name = "decayed_date")
|
||||
private Instant decayedDate;
|
||||
|
||||
@Column(name = "created", nullable = false, insertable = false, updatable = false)
|
||||
private Instant created;
|
||||
|
||||
@Column(name = "updated", insertable = false, updatable = false)
|
||||
private Instant updated;
|
||||
}
|
||||
@@ -28,7 +28,7 @@ public class Warning implements Serializable {
|
||||
@Setter
|
||||
private ServerSpecificId warnId;
|
||||
|
||||
@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
|
||||
@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.LAZY)
|
||||
@MapsId("serverId")
|
||||
@JoinColumn(name = "server_id", referencedColumnName = "id", nullable = false)
|
||||
private AServer server;
|
||||
@@ -90,4 +90,10 @@ public class Warning implements Serializable {
|
||||
@Column(name = "updated", insertable = false, updatable = false)
|
||||
private Instant updated;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@OneToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "infraction_id")
|
||||
private Infraction infraction;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package dev.sheldan.abstracto.moderation.model.listener;
|
||||
|
||||
import dev.sheldan.abstracto.core.listener.FeatureAwareListenerModel;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public class InfractionLevelChangedEventModel implements FeatureAwareListenerModel {
|
||||
private Integer oldLevel;
|
||||
private Long oldPoints;
|
||||
private Integer newLevel;
|
||||
private Long newPoints;
|
||||
private Long userId;
|
||||
private Long serverId;
|
||||
|
||||
@Override
|
||||
public Long getServerId() {
|
||||
return serverId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package dev.sheldan.abstracto.moderation.model.listener;
|
||||
|
||||
import dev.sheldan.abstracto.core.listener.FeatureAwareListenerModel;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public class WarningCreatedEventModel implements FeatureAwareListenerModel {
|
||||
private Long warningId;
|
||||
private Long warnedUserId;
|
||||
private Long serverId;
|
||||
private Long warningUserId;
|
||||
private Long warningChannelId;
|
||||
private Long warningMessageId;
|
||||
private String reason;
|
||||
|
||||
@Override
|
||||
public Long getServerId() {
|
||||
return serverId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package dev.sheldan.abstracto.moderation.model.template;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.template.display.MemberDisplay;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public class InfractionLevelChangeModel {
|
||||
private Long newPoints;
|
||||
private Long oldPoints;
|
||||
private Integer newLevel;
|
||||
private Integer oldLevel;
|
||||
private MemberDisplay member;
|
||||
}
|
||||
@@ -26,4 +26,5 @@ public class WarnContext extends SlimUserInitiatedServerContext {
|
||||
* The persisted {@link Warning} object from the database containing the information about the warning
|
||||
*/
|
||||
private Long warnId;
|
||||
private Long infractionId;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package dev.sheldan.abstracto.moderation.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.moderation.model.database.Infraction;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public interface InfractionService {
|
||||
void decayInfraction(Infraction infraction);
|
||||
Long getActiveInfractionPointsForUser(AUserInAServer aUserInAServer);
|
||||
CompletableFuture<Infraction> createInfractionWithNotification(AUserInAServer aUserInAServer, Long points);
|
||||
CompletableFuture<Void> createInfractionNotification(AUserInAServer aUserInAServer, Long points);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package dev.sheldan.abstracto.moderation.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.moderation.model.database.Infraction;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface InfractionManagementService {
|
||||
Infraction createInfraction(AUserInAServer aUserInAServer, Long points);
|
||||
List<Infraction> getActiveInfractionsForUser(AUserInAServer aUserInAServer);
|
||||
Infraction loadInfraction(Long infraction);
|
||||
}
|
||||
@@ -16,7 +16,8 @@ public interface WarnManagementService {
|
||||
Long getTotalWarnsForUser(AUserInAServer aUserInAServer);
|
||||
List<Warning> getAllWarnsForUser(AUserInAServer aUserInAServer);
|
||||
List<Warning> getAllWarningsOfServer(AServer server);
|
||||
Long getActiveWarnsForUser(AUserInAServer aUserInAServer);
|
||||
Long getActiveWarnCountForUser(AUserInAServer aUserInAServer);
|
||||
List<Warning> getActiveWarnsForUser(AUserInAServer aUserInAServer);
|
||||
Optional<Warning> findByIdOptional(Long id, Long serverId);
|
||||
Warning findById(Long id, Long serverId);
|
||||
List<Warning> getWarningsViaId(List<Long> warnIds, Long serverId);
|
||||
|
||||
Reference in New Issue
Block a user