mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-27 14:23:56 +00:00
[AB-177] adding ability to restrict the allowed mentions and configure them via commands on a server basis, default is defined via property file
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
package dev.sheldan.abstracto.core.exception;
|
||||
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
public class UnknownMentionTypeException extends AbstractoRunTimeException implements Templatable {
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "unknown_mention_type_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
return new Object();
|
||||
}
|
||||
}
|
||||
@@ -44,9 +44,14 @@ public class AServer implements SnowFlake, Serializable {
|
||||
this.updated = Instant.now();
|
||||
}
|
||||
|
||||
@OneToOne(mappedBy = "server", cascade = CascadeType.ALL)
|
||||
@PrimaryKeyJoinColumn
|
||||
private AllowedMention allowedMention;
|
||||
|
||||
@OneToMany(
|
||||
fetch = FetchType.LAZY,
|
||||
orphanRemoval = true,
|
||||
cascade = {CascadeType.PERSIST, CascadeType.MERGE},
|
||||
mappedBy = "server")
|
||||
@Builder.Default
|
||||
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package dev.sheldan.abstracto.core.models.database;
|
||||
|
||||
import lombok.*;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.time.Instant;
|
||||
|
||||
@Entity
|
||||
@Table(name="allowed_mention")
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
@Cacheable
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
|
||||
public class AllowedMention implements Serializable {
|
||||
|
||||
@Id
|
||||
@Column(name = "server_id")
|
||||
private Long id;
|
||||
|
||||
@OneToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
|
||||
@MapsId
|
||||
@JoinColumn(name = "server_id")
|
||||
private AServer server;
|
||||
|
||||
@Getter
|
||||
@Column(name = "everyone_mention")
|
||||
private Boolean everyone;
|
||||
|
||||
@Getter
|
||||
@Column(name = "user_mention")
|
||||
private Boolean user;
|
||||
|
||||
@Getter
|
||||
@Column(name = "role_mention")
|
||||
private Boolean role;
|
||||
|
||||
@Column(name = "created")
|
||||
private Instant created;
|
||||
|
||||
@PrePersist
|
||||
private void onInsert() {
|
||||
this.created = Instant.now();
|
||||
}
|
||||
|
||||
@Column(name = "updated")
|
||||
private Instant updateTimestamp;
|
||||
|
||||
@PreUpdate
|
||||
private void onUpdate() {
|
||||
this.updateTimestamp = Instant.now();
|
||||
}
|
||||
|
||||
public boolean allAllowed() {
|
||||
return everyone && user && role;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package dev.sheldan.abstracto.core.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.AllowedMention;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface AllowedMentionService {
|
||||
boolean allMentionsAllowed(Long serverId);
|
||||
List<Message.MentionType> getAllowedMentionTypesForServer(Long serverId);
|
||||
void allowMentionForServer(Message.MentionType mentionType, Long serverId);
|
||||
void disAllowMentionForServer(Message.MentionType mentionType, Long serverId);
|
||||
AllowedMention getDefaultAllowedMention();
|
||||
AllowedMention getEffectiveAllowedMention(Long serverId);
|
||||
Message.MentionType getMentionTypeFromString(String input);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package dev.sheldan.abstracto.core.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.models.database.AllowedMention;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface AllowedMentionManagementService {
|
||||
Optional<AllowedMention> getCustomAllowedMentionFor(Long serverId);
|
||||
Optional<AllowedMention> getCustomAllowedMentionFor(AServer server);
|
||||
boolean hasCustomAllowedMention(Long serverId);
|
||||
AllowedMention createCustomAllowedMention(Long server, AllowedMention base);
|
||||
void deleteCustomAllowedMention(Long serverId);
|
||||
}
|
||||
Reference in New Issue
Block a user