[AB-60] improving java doc for assignable role module

This commit is contained in:
Sheldan
2021-03-03 23:51:26 +01:00
parent 373dfac001
commit 9c6333281b
65 changed files with 1357 additions and 210 deletions

View File

@@ -3,7 +3,10 @@ package dev.sheldan.abstracto.assignableroles.config;
import dev.sheldan.abstracto.core.command.execution.CommandParameterKey;
import lombok.Getter;
/**
* This enum is used to define the different key for which there exist properties on an {@link dev.sheldan.abstracto.assignableroles.models.database.AssignableRolePlace}.
* And is used for the command parameter when changing the value of an attribute on this place.
*/
@Getter
public enum AssignableRolePlaceParameterKey implements CommandParameterKey {
INLINE, UNIQUE, AUTOREMOVE, ACTIVE

View File

@@ -5,6 +5,11 @@ import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
import dev.sheldan.abstracto.core.models.FullEmote;
import dev.sheldan.abstracto.core.templating.Templatable;
/**
* Exception thrown in case the {@link dev.sheldan.abstracto.assignableroles.models.database.AssignableRole} has already been
* defined for an {@link dev.sheldan.abstracto.assignableroles.models.database.AssignableRolePlace}. This is identified
* via the {@link net.dv8tion.jda.api.entities.Emote} which is used to react.
*/
public class AssignableRoleAlreadyDefinedException extends AbstractoRunTimeException implements Templatable {
private final AssignableRoleAlreadyDefinedExceptionModel model;

View File

@@ -6,6 +6,11 @@ import dev.sheldan.abstracto.core.models.FullRole;
import dev.sheldan.abstracto.core.templating.Templatable;
import net.dv8tion.jda.api.entities.Guild;
/**
* Exception thrown in case the defined {@link net.dv8tion.jda.api.entities.Role role} cannot be interacted with by the bot,
* because of permissions, this can happen if the role is the same or higher than the bot, therefore cannot be given to
* {@link net.dv8tion.jda.api.entities.Member members}
*/
public class AssignableRoleNotUsableException extends AbstractoRunTimeException implements Templatable {
private final AssignableRoleNotUsableExceptionModel model;

View File

@@ -4,6 +4,10 @@ import dev.sheldan.abstracto.assignableroles.models.exception.AssignableRolePlac
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
import dev.sheldan.abstracto.core.templating.Templatable;
/**
* Exception thrown in case the {@link dev.sheldan.abstracto.assignableroles.models.database.AssignableRolePlace place}
* identified by {@link dev.sheldan.abstracto.assignableroles.models.database.AssignableRolePlace#key}
*/
public class AssignableRolePlaceAlreadyExistsException extends AbstractoRunTimeException implements Templatable {
private final AssignableRolePlaceAlreadyExistsExceptionModel model;

View File

@@ -4,11 +4,15 @@ import dev.sheldan.abstracto.assignableroles.models.exception.AssignableRolePlac
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
import dev.sheldan.abstracto.core.templating.Templatable;
public class AssignableRolePlaceChannelDoesNotExist extends AbstractoRunTimeException implements Templatable {
/**
* Exception thrown in case the {@link dev.sheldan.abstracto.core.models.database.AChannel channel} in which a
* {@link dev.sheldan.abstracto.assignableroles.models.database.AssignableRolePlace place} is defined, does not exist
*/
public class AssignableRolePlaceChannelDoesNotExistException extends AbstractoRunTimeException implements Templatable {
private final AssignableRolePlaceChannelDoesNotExistExceptionModel model;
public AssignableRolePlaceChannelDoesNotExist(Long channelId, String placeName) {
public AssignableRolePlaceChannelDoesNotExistException(Long channelId, String placeName) {
super("Assignable role place channel does not exist");
this.model = AssignableRolePlaceChannelDoesNotExistExceptionModel.builder().channelId(channelId).placeName(placeName).build();
}

View File

@@ -4,6 +4,10 @@ import dev.sheldan.abstracto.assignableroles.models.exception.AssignableRolePlac
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
import dev.sheldan.abstracto.core.templating.Templatable;
/**
* Exception which is thrown in case a {@link dev.sheldan.abstracto.assignableroles.models.database.AssignableRolePlace place}
* defined by a {@link String key} does not exist
*/
public class AssignableRolePlaceNotFoundException extends AbstractoRunTimeException implements Templatable {
private final AssignableRolePlaceNotFoundExceptionModel model;

View File

@@ -4,11 +4,15 @@ import dev.sheldan.abstracto.assignableroles.models.exception.AssignableRolePlac
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
import dev.sheldan.abstracto.core.templating.Templatable;
public class AssignablePlacePostNotFoundException extends AbstractoRunTimeException implements Templatable {
/**
* Exception which is thrown, in case the {@link dev.sheldan.abstracto.assignableroles.models.database.AssignableRolePlacePost post}
* was not found via its message ID
*/
public class AssignableRolePlacePostNotFoundException extends AbstractoRunTimeException implements Templatable {
private final AssignableRolePlacePostNotFoundExceptionModel model;
public AssignablePlacePostNotFoundException(Long messageId) {
public AssignableRolePlacePostNotFoundException(Long messageId) {
super("Assignable place post not found.");
this.model = AssignableRolePlacePostNotFoundExceptionModel.builder().messageId(messageId).build();
}

View File

@@ -5,6 +5,10 @@ import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import dev.sheldan.abstracto.core.templating.Templatable;
/**
* Exception which is thrown in case an {@link dev.sheldan.abstracto.assignableroles.models.database.AssignedRoleUser user}
* was not found.
*/
public class AssignedUserNotFoundException extends AbstractoRunTimeException implements Templatable {
private final AssignedUserNotFoundExceptionModel model;

View File

@@ -5,6 +5,11 @@ import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
import dev.sheldan.abstracto.core.models.FullEmote;
import dev.sheldan.abstracto.core.templating.Templatable;
/**
* Exception which is thrown in case a given {@link dev.sheldan.abstracto.core.models.database.AEmote} was not found
* in the {@link dev.sheldan.abstracto.assignableroles.models.database.AssignableRolePlace}, when it was tried to switch
* or move the emotes around.
*/
public class EmoteNotInAssignableRolePlaceException extends AbstractoRunTimeException implements Templatable {
private final EmoteNotInAssignableRolePlaceExceptionModel model;

View File

@@ -11,8 +11,12 @@ import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
/**
* A {@link ARole role} which can be mapped to an {@link AssignableRolePlace ṕlace}. This is uniquely defined by an emote on the
* respective assignable role place, but the same role can be given via different {@link AEmote emote}
*/
@Entity
@Table(name="assignable_role")
@Table(name = "assignable_role")
@Builder
@AllArgsConstructor
@NoArgsConstructor
@@ -21,46 +25,86 @@ import java.util.List;
@EqualsAndHashCode
public class AssignableRole implements Serializable {
/**
* The unique ID of this {@link AssignableRole assignableRole}
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
/**
* The {@link AEmote emote} this role is associated with
*/
@OneToOne(fetch = FetchType.LAZY, orphanRemoval = true)
@JoinColumn(name = "emote_id")
private AEmote emote;
/**
* The {@link ARole} which given via this {@link AssignableRole assignableRole}
*/
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "role_id", nullable = false)
private ARole role;
/**
* The {@link AServer server} in which this {@link AssignableRole assignableRole} is used
*/
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "server_id", nullable = false)
private AServer server;
/**
* The {@link AssignableRolePlace} this assignable role is in
*/
@ManyToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@JoinColumn(name = "assignable_place_id", nullable = false)
private AssignableRolePlace assignablePlace;
/**
* The {@link AssignableRolePlacePost} this assignable role is currently available as a reaction.
* This is necessary, to easier find the reaction which are valid, in case a reaction is added to a post
*/
@ManyToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@JoinColumn(name = "place_post_id")
private AssignableRolePlacePost assignableRolePlacePost;
/**
* The {@link AssignedRoleUser users} which currently have this role assigned via this mechanism.
* This is necessary to enforce the unique property of {@link AssignableRolePlace}, in which you only may chose one
* role.
*/
@ManyToMany(mappedBy = "roles")
@Builder.Default
private List<AssignedRoleUser> assignedUsers = new ArrayList<>();
/**
* The description which is shown in the embeds of the posts of the {@link AssignableRolePlace}
*/
@Column(name = "description")
private String description;
/**
* The level in experience which is required in order to receive this {@link AssignableRole}
*/
@Column(name = "required_level")
private Integer requiredLevel;
/**
* The position of this assignable role within the {@link AssignableRole}. This is required in order to show them
* the same order as the descriptions in the fields and also to move them around and switch positions
*/
@Column(name = "position")
private Integer position;
/**
* The {@link Instant} this entity was created
*/
@Column(name = "created")
private Instant created;
/**
* The {@link Instant} this entity was updated
*/
@Column(name = "updated")
private Instant updated;
}

View File

@@ -10,8 +10,13 @@ import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
/**
* The place entity holding the {@link AssignableRole roles} and {@link AssignableRolePlacePost posts} together.
* This is also the entity holding all the configuration for the place and is identified by a key as a String, which is unique
* for each server. This place holds the {@link AChannel} in which the
*/
@Entity
@Table(name="assignable_role_place")
@Table(name = "assignable_role_place")
@Builder
@AllArgsConstructor
@NoArgsConstructor
@@ -23,22 +28,38 @@ public class AssignableRolePlace implements Serializable {
public static final Long ASSIGNABLE_PLACE_NAME_LIMIT = 255L;
public static final Long ASSIGNABLE_PLACE_DESCRIPTION_LIMIT = 255L;
/**
* A unique ID created
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
/**
* The channel in which the {@link AssignableRolePlacePost posts} for this place should be created
*/
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name="channel_id")
private AChannel channel;
/**
* The {@link AServer server} for which this place is configured for. Unique in combination with the key
*/
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "server_id", nullable = false)
private AServer server;
/**
* The key this place is associated with via commands. Unique per server.
*/
@Column(name = "key")
private String key;
/**
* The {@link AssignableRolePlacePost posts} which were created when this place was setup. Is empty in the beginning
* and actively maintained in case a post is deleted.
*/
@OneToMany(
fetch = FetchType.LAZY,
cascade = {CascadeType.PERSIST, CascadeType.MERGE},
@@ -48,6 +69,9 @@ public class AssignableRolePlace implements Serializable {
@Builder.Default
private List<AssignableRolePlacePost> messagePosts = new ArrayList<>();
/**
* A List containing the {@link AssignableRole} which are associated with this place
*/
@OneToMany(
fetch = FetchType.LAZY,
cascade = {CascadeType.PERSIST, CascadeType.MERGE},
@@ -57,28 +81,49 @@ public class AssignableRolePlace implements Serializable {
@Builder.Default
private List<AssignableRole> assignableRoles = new ArrayList<>();
/**
* The text which is displayed in the first description area of the created {@link AssignableRolePlacePost}
*/
@Column(name = "text")
private String text;
/**
* Whether or not the reactions placed onto the posts should be acted upon
*/
@Builder.Default
@Column(name = "active")
private Boolean active = true;
/**
* Whether or not the fields containing the descriptions should be inline
*/
@Builder.Default
@Column(name = "inline")
private Boolean inline = false;
/**
* Whether or not it should be restricted, that a {@link AssignedRoleUser} should only have one role of this place
*/
@Builder.Default
@Column(name = "unique_roles")
private Boolean uniqueRoles = false;
/**
* Whether or not the added reactions should be removed automatically
*/
@Builder.Default
@Column(name = "auto_remove")
private Boolean autoRemove = false;
/**
* The {@link Instant} this entity was created
*/
@Column(name = "created")
private Instant created;
/**
* The {@link Instant} this entity was updated
*/
@Column(name = "updated")
private Instant updated;

View File

@@ -10,8 +10,12 @@ import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
/**
* One individual {@link net.dv8tion.jda.api.entities.Message message} which was sent when setting up an {@link AssignableRolePlace place}
* and contains the embeds and the reactions were placed onto it.
*/
@Entity
@Table(name="assignable_role_place_post")
@Table(name = "assignable_role_place_post")
@Builder
@AllArgsConstructor
@NoArgsConstructor
@@ -20,28 +24,38 @@ import java.util.List;
@EqualsAndHashCode
public class AssignableRolePlacePost implements Serializable {
/**
* The ID of the {@link net.dv8tion.jda.api.entities.Message message} which represents this post with the reactions.
*/
@Id
@Column(name = "id")
private Long id;
/**
* The actual {@link AChannel channel} in which the post ended up in
*/
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "channel_id")
private AChannel usedChannel;
@Column(name = "created")
private Instant created;
@Column(name = "updated")
private Instant updated;
/**
* The {@link AServer server} in which this place post is posted
*/
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "server_id", nullable = false)
private AServer server;
/**
* The {@link AssignableRolePlace place} this post is associated with
*/
@ManyToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@JoinColumn(name = "assignable_place_id", nullable = false)
private AssignableRolePlace assignablePlace;
/**
* The actual {@link AssignableRole assignableRoles} which are associated with this post, and whose respective {@link dev.sheldan.abstracto.core.models.database.AEmote}
* have been placed as reactions
*/
@OneToMany(
fetch = FetchType.LAZY,
cascade = {CascadeType.PERSIST, CascadeType.MERGE},
@@ -49,4 +63,16 @@ public class AssignableRolePlacePost implements Serializable {
@Builder.Default
private List<AssignableRole> assignableRoles = new ArrayList<>();
/**
* The {@link Instant} this entity was created
*/
@Column(name = "created")
private Instant created;
/**
* The {@link Instant} this entity was updated
*/
@Column(name = "updated")
private Instant updated;
}

View File

@@ -9,8 +9,12 @@ import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
/**
* A {@link AUserInAServer userInAServer} which added a reaction to an {@link AssignableRolePlace place}.
* This is required in order to guarantee the uniqueness (if desired) of {@link AssignableRole} per place.
*/
@Entity
@Table(name="assigned_role_user")
@Table(name = "assigned_role_user")
@Builder
@AllArgsConstructor
@NoArgsConstructor
@@ -19,6 +23,9 @@ import java.util.List;
@EqualsAndHashCode
public class AssignedRoleUser implements Serializable {
/**
* The ID of the associated {@link AUserInAServer userInAServer}
*/
@Id
@Column(name = "id")
private Long id;
@@ -27,6 +34,9 @@ public class AssignedRoleUser implements Serializable {
@PrimaryKeyJoinColumn
private AUserInAServer user;
/**
* The {@link AssignableRole assignableRoles} this user has in the server
*/
@ManyToMany
@JoinTable(
name = "assigned_role_in_user",
@@ -35,9 +45,15 @@ public class AssignedRoleUser implements Serializable {
@Builder.Default
private List<AssignableRole> roles = new ArrayList<>();
/**
* The {@link Instant} this entity was created
*/
@Column(name = "created")
private Instant created;
/**
* The {@link Instant} this entity was updated
*/
@Column(name = "updated")
private Instant updated;

View File

@@ -6,9 +6,19 @@ import lombok.Getter;
import java.io.Serializable;
/**
* Contains the model for {@link dev.sheldan.abstracto.assignableroles.exceptions.AssignableRoleAlreadyDefinedException}
*/
@Getter
@Builder
public class AssignableRoleAlreadyDefinedExceptionModel implements Serializable {
/**
* The {@link FullEmote emote} which was tried to be added to a {@link dev.sheldan.abstracto.assignableroles.models.database.AssignableRolePlace place}
*/
private final FullEmote emote;
/**
* The key of the {@link dev.sheldan.abstracto.assignableroles.models.database.AssignableRolePlace} for which it was tried to add a
* {@link dev.sheldan.abstracto.assignableroles.models.database.AssignableRole role}
*/
private final String placeName;
}

View File

@@ -7,9 +7,18 @@ import net.dv8tion.jda.api.entities.Guild;
import java.io.Serializable;
/**
* Contains the model for {@link dev.sheldan.abstracto.assignableroles.exceptions.AssignableRolePlaceNotFoundException}
*/
@Getter
@Builder
public class AssignableRoleNotUsableExceptionModel implements Serializable {
/**
* The {@link FullRole role} which is not usable as an {@link dev.sheldan.abstracto.assignableroles.models.database.AssignableRole role}
*/
private final FullRole role;
/**
* The {@link Guild server} in which it was not possible to use the {@link net.dv8tion.jda.api.entities.Role role}
*/
private final transient Guild guild;
}

View File

@@ -5,8 +5,14 @@ import lombok.Getter;
import java.io.Serializable;
/**
* Contains the model for {@link dev.sheldan.abstracto.assignableroles.exceptions.AssignableRolePlaceAlreadyExistsException}
*/
@Getter
@Builder
public class AssignableRolePlaceAlreadyExistsExceptionModel implements Serializable {
/**
* The key which collides with an existing {@link dev.sheldan.abstracto.assignableroles.models.database.AssignableRolePlace}
*/
private final String name;
}

View File

@@ -1,13 +1,24 @@
package dev.sheldan.abstracto.assignableroles.models.exception;
import dev.sheldan.abstracto.assignableroles.exceptions.AssignableRolePlaceChannelDoesNotExistException;
import lombok.Builder;
import lombok.Getter;
import java.io.Serializable;
/**
* Contains the model for {@link AssignableRolePlaceChannelDoesNotExistException}
*/
@Getter
@Builder
public class AssignableRolePlaceChannelDoesNotExistExceptionModel implements Serializable {
/**
* The ID of the {@link dev.sheldan.abstracto.core.models.database.AChannel channel} which does not exist in the {@link net.dv8tion.jda.api.entities.Guild}
*/
private final Long channelId;
/**
* The key of the {@link dev.sheldan.abstracto.assignableroles.models.database.AssignableRolePlace place} for which
* the channel does not exist anymore in the {@link net.dv8tion.jda.api.entities.Guild}
*/
private final String placeName;
}

View File

@@ -1,28 +0,0 @@
package dev.sheldan.abstracto.assignableroles.models.exception;
import dev.sheldan.abstracto.assignableroles.models.database.AssignableRolePlace;
import dev.sheldan.abstracto.core.models.FullUserInServer;
import dev.sheldan.abstracto.core.templating.Templatable;
import lombok.Builder;
import lombok.Getter;
import java.io.Serializable;
@Getter
@Builder
public class AssignableRolePlaceExceptionModel implements Serializable {
private final AssignableRolePlace rolePlace;
private final FullUserInServer user;
private final Throwable throwable;
public Templatable getTemplate() {
Throwable current = throwable;
while(!(current instanceof Templatable) && !current.getCause().equals(current)) {
current = current.getCause();
}
if(current instanceof Templatable) {
return (Templatable) current;
}
return null;
}
}

View File

@@ -5,8 +5,14 @@ import lombok.Getter;
import java.io.Serializable;
/**
* Contains the model for {@link dev.sheldan.abstracto.assignableroles.exceptions.AssignableRolePlaceNotFoundException}
*/
@Getter
@Builder
public class AssignableRolePlaceNotFoundExceptionModel implements Serializable {
/**
* The ID of the {@link dev.sheldan.abstracto.assignableroles.models.database.AssignableRolePlace place} which was not found
*/
private final Long placeId;
}

View File

@@ -5,8 +5,14 @@ import lombok.Getter;
import java.io.Serializable;
/**
* Contains the model for {@link dev.sheldan.abstracto.assignableroles.exceptions.AssignableRolePlacePostNotFoundException}
*/
@Getter
@Builder
public class AssignableRolePlacePostNotFoundExceptionModel implements Serializable {
/**
* The ID of the {@link dev.sheldan.abstracto.assignableroles.models.database.AssignableRolePlacePost post} which was not found in the database
*/
private final Long messageId;
}

View File

@@ -6,8 +6,14 @@ import lombok.Getter;
import java.io.Serializable;
/**
* Contains the model for {@link dev.sheldan.abstracto.assignableroles.exceptions.AssignedUserNotFoundException}
*/
@Getter
@Builder
public class AssignedUserNotFoundExceptionModel implements Serializable {
/**
* The instance of the {@link AUserInAServer userInAServer} for which the assigned user was not found
*/
private final AUserInAServer aUserInAServer;
}

View File

@@ -6,9 +6,18 @@ import lombok.Getter;
import java.io.Serializable;
/**
* Contains the model for {@link dev.sheldan.abstracto.assignableroles.exceptions.EmoteNotInAssignableRolePlaceException}
*/
@Getter
@Builder
public class EmoteNotInAssignableRolePlaceExceptionModel implements Serializable {
/**
* The {@link FullEmote emote} which was not found in the {@link dev.sheldan.abstracto.assignableroles.models.database.AssignableRolePlace place}
*/
private final FullEmote emote;
/**
* The key of the {@link dev.sheldan.abstracto.assignableroles.models.database.AssignableRolePlace place} for which the emote was not found in
*/
private final String placeName;
}

View File

@@ -8,10 +8,16 @@ import lombok.Setter;
import java.util.ArrayList;
import java.util.List;
/**
* Model used to render the overview over all {@link AssignableRolePlace places}
*/
@Getter
@Setter
@Builder
public class AssignablePlaceOverview {
/**
* The {@link AssignableRolePlace places} in the server to display
*/
@Builder.Default
private List<AssignableRolePlace> places = new ArrayList<>();
}

View File

@@ -1,19 +0,0 @@
package dev.sheldan.abstracto.assignableroles.models.templates;
import dev.sheldan.abstracto.core.models.FullEmote;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import net.dv8tion.jda.api.entities.Role;
@Getter
@Setter
@Builder
public class AssignablePostConfigRole {
private String description;
private Integer position;
private Boolean inline;
private FullEmote emote;
private Role awardedRole;
}

View File

@@ -7,11 +7,24 @@ import lombok.Setter;
import java.util.List;
/**
* Model used to render the {@link AssignableRolePlace place}
*/
@Getter
@Setter
@Builder
public class AssignablePostMessage {
public class AssignablePostMessage {
/**
* The {@link AssignableRolePlace place} to render
*/
private AssignableRolePlace place;
/**
* The awarded {@link AssignablePostRole roles} for this {@link AssignableRolePlace place}
*/
private List<AssignablePostRole> roles;
/**
* The highest number of the position within the {@link dev.sheldan.abstracto.assignableroles.models.database.AssignableRole} of the
* {@link AssignableRolePlace place}
*/
private Integer maxPosition;
}

View File

@@ -6,14 +6,35 @@ import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
/**
* The model which is used to render the {@link dev.sheldan.abstracto.assignableroles.models.database.AssignableRolePlacePost post}
* to a {@link dev.sheldan.abstracto.core.templating.model.MessageToSend messageToSend} for one individual {@link dev.sheldan.abstracto.assignableroles.models.database.AssignableRole role}
*/
@Getter
@Setter
@Builder
public class AssignablePostRole {
/**
* The {@link FullEmote emote} to be used in the field
*/
private FullEmote emote;
/**
* The description to be used in the field
*/
private String description;
/**
* The relative position within the {@link dev.sheldan.abstracto.assignableroles.models.database.AssignableRolePlace place} of this
* {@link dev.sheldan.abstracto.assignableroles.models.database.AssignableRole role}
*/
private Integer position;
/**
* Whether or not this field should be at the beginning of a new {@link net.dv8tion.jda.api.entities.Message message}
* to be send
*/
@Builder.Default
private Boolean forceNewMessage = false;
/**
* Whether or not the field should be displayed inline
*/
private Boolean inline;
}

View File

@@ -7,10 +7,19 @@ import lombok.Setter;
import java.util.List;
/**
* This model is used as a container to display the configuration of an {@link AssignableRolePlace place}
*/
@Getter
@Setter
@Builder
public class AssignableRolePlaceConfig {
/**
* The {@link AssignableRolePlace place} to show the config of
*/
private AssignableRolePlace place;
private List<AssignablePostConfigRole> roles;
/**
* The {@link AssignableRolePlaceConfig roles} which are contained in this {@link AssignableRolePlace}
*/
private List<AssignableRolePlaceConfigRole> roles;
}

View File

@@ -0,0 +1,38 @@
package dev.sheldan.abstracto.assignableroles.models.templates;
import dev.sheldan.abstracto.core.models.FullEmote;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import net.dv8tion.jda.api.entities.Role;
/**
* Model used to display the configuration of an individual {@link dev.sheldan.abstracto.assignableroles.models.database.AssignableRole}
* within an {@link dev.sheldan.abstracto.assignableroles.models.database.AssignableRolePlace place}
*/
@Getter
@Setter
@Builder
public class AssignableRolePlaceConfigRole {
/**
* The description used for the field for this {@link dev.sheldan.abstracto.assignableroles.models.database.AssignableRole role}
*/
private String description;
/**
* The position of this {@link dev.sheldan.abstracto.assignableroles.models.database.AssignableRole role}
*/
private Integer position;
/**
* Whether or not the field is displayed inline
*/
private Boolean inline;
/**
* The {@link FullEmote emote} which is associated with this {@link dev.sheldan.abstracto.assignableroles.models.database.AssignableRole role}
*/
private FullEmote emote;
/**
* The {@link dev.sheldan.abstracto.core.models.database.ARole} which is given/removed upon reacting with the emote
*/
private Role awardedRole;
}

View File

@@ -1,72 +1,425 @@
package dev.sheldan.abstracto.assignableroles.service;
import dev.sheldan.abstracto.assignableroles.config.AssignableRolePlaceParameterKey;
import dev.sheldan.abstracto.assignableroles.exceptions.EmoteNotInAssignableRolePlaceException;
import dev.sheldan.abstracto.assignableroles.models.database.AssignableRole;
import dev.sheldan.abstracto.assignableroles.models.database.AssignableRolePlace;
import dev.sheldan.abstracto.assignableroles.models.database.AssignableRolePlacePost;
import dev.sheldan.abstracto.assignableroles.models.database.AssignedRoleUser;
import dev.sheldan.abstracto.core.command.exception.AbstractoTemplatedException;
import dev.sheldan.abstracto.core.exception.ChannelNotInGuildException;
import dev.sheldan.abstracto.core.models.FullEmote;
import dev.sheldan.abstracto.core.models.database.AChannel;
import dev.sheldan.abstracto.core.models.database.AEmote;
import dev.sheldan.abstracto.core.models.database.ARole;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageReaction;
import net.dv8tion.jda.api.entities.TextChannel;
import java.util.concurrent.CompletableFuture;
/**
* Service responsible to manage actions on an {@link AssignableRolePlace assignableRolePlace}
*/
public interface AssignableRolePlaceService {
void createAssignableRolePlace(AServer server, String name, AChannel channel, String text);
/**
* Creates a {@link AssignableRolePlace place} with the given parameters
* @param name The key of the {@link AssignableRolePlace} to be used
* @param channel The {@link AChannel channel} in which the posts of this {@link AssignableRolePlace place} should be posted, also determines
* the {@link AServer server} in which the place should reside in. This {@link AServer server} needs to be unique in combination with the
* key
* @param text The description of the {@link AssignableRolePlace place} which is displayed in the first post of the place
* @throws dev.sheldan.abstracto.assignableroles.exceptions.AssignableRoleAlreadyDefinedException if the combination of {@link AServer server}
* and {@link AssignableRolePlace#key} already exists
*/
void createAssignableRolePlace(String name, AChannel channel, String text);
/**
* Whether or not the {@link AssignableRolePlace place} already has the given {@link AEmote emote} as an {@link AssignableRole role}
* with the given {@link AEmote emote}
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} should be in
* @param placeName The key of an {@link AssignableRolePlace place} to check
* @param emote The {@link AEmote emote} which is sought after
* @return Whether or not the {@link AssignableRolePlace place} already has an {@link AssignableRole role}
* with the associated {@link AEmote emote}
*/
boolean hasAssignableRolePlaceEmote(AServer server, String placeName, AEmote emote);
/**
* Whether or not the {@link AssignableRolePlace place} (identified by {@link AServer server} and placeName) already has
* the given {@link AEmote emote} as an {@link AssignableRole role}
* with the given {@link AEmote emote}
* @param place The {@link AssignableRolePlace place} in which the {@link AEmote emote} should be sought in
* @param emote The {@link AEmote emote} which is sought after
* @return Whether or not the {@link AssignableRolePlace place} already has an {@link AssignableRole role}
* with the associated {@link AEmote emote}
*/
boolean hasAssignableRolePlaceEmote(AssignableRolePlace place, AEmote emote);
/**
* Whether or not the {@link AssignableRolePlace place} has the position used. Each of the {@link AssignableRole roles}
* in the {@link AssignableRolePlace place} has a position in which it is posted. This is used to order the roles when posting them. This position is an {@link Integer integer}
* and it is not guaranteed every position up until the amount of {@link AssignableRole roles} is used.
* There can be spots, it is only used as an ordering and to swap/move {@link AssignableRole roles}
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} should be in
* @param placeName The key of the {@link AssignableRolePlace place}
* @param position The position of an {@link AssignableRole role} within the place
* @return Whether or not there exists an {@link AssignableRole role} within the
* {@link AssignableRolePlace place} identified by the {@link AServer server} and key
*/
boolean isPositionUsed(AServer server, String placeName, Integer position);
/**
* Sets the {@link AssignableRole role} identified by the
* {@link FullEmote emote} to the given {@link Integer position} in the {@link AssignableRolePlace place} identified by the
* {@link AServer server} and key.
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} should be
* @param placeName The key of the {@link AssignableRolePlace place}
* @param emote The {@link FullEmote emote} which identifies the {@link AssignableRole role}
* which position should be changed
* @param position The new position of the {@link AssignableRole role}
* within the place
* @throws AbstractoTemplatedException if the position is already used or the {@link FullEmote emote} has not associated {@link AssignableRole role}
* within the place
*/
void setEmoteToPosition(AServer server, String placeName, FullEmote emote, Integer position);
/**
* Adds the given {@link ARole role} to the {@link AssignableRolePlace place} identified by the {@link AServer server} and key
* in the form as a {@link AssignableRole role}. This role is identified
* by the given {@link FullEmote emote} and has the description. If the {@link AssignableRolePlace place} is already setup, this will
* try to update the message: adding the field and the reaction. This might not always work e.g. the reaction limit was reached.
* If the update is successful, it will also store the updates in the database.
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is present
* @param placeName The key of the {@link AssignableRolePlace place}
* @param role The {@link ARole role} which should be awarded when reacting with the given {@link FullEmote emote}
* @param emote The {@link FullEmote emote} which should be placed on the {@link Message message}
* to react to and identify the {@link AssignableRole}
* for this place
* @param description The description which will be displayed in the {@link Message message}
* which has the reactions
* @throws dev.sheldan.abstracto.core.exception.EmoteNotUsableException in case the {@link net.dv8tion.jda.api.entities.Emote emote}
* cannot be used by the current user. This might be an issue, if its from an external {@link net.dv8tion.jda.api.entities.Guild}
* the user is not a part of.
* @return A {@link CompletableFuture future} when the {@link Message message} has been updated
* and the {@link MessageReaction reaction} has been added. Only tries to execute this, in case there
* {@link AssignableRolePlacePost posts} known.
*/
CompletableFuture<Void> addRoleToAssignableRolePlace(AServer server, String placeName, ARole role, FullEmote emote, String description);
/**
* Removes the given {@link AssignableRole role} from the {@link AssignableRolePlace place}
* identified by the {@link AServer server} and the key. The {@link AssignableRole role} is identified
* by the {@link FullEmote emote} which is associated to it. If there are already {@link AssignableRolePlacePost posts}
* for this {@link AssignableRolePlace place} this will remove the {@link MessageReaction reaction} and
* edit the {@link Message message}. If not, the method returns immediately. If the update
* was successful or was not necessary, the data will be updated in the database as well.
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
* @param placeName The key of the {@link AssignableRolePlace place} to remove an {@link AssignableRole role}
* from
* @param emote The {@link FullEmote fullEmote} which has an {@link AEmote emote} to identify the {@link AssignableRole role}
* to remove
* @return A {@link CompletableFuture future} which completes when the {@link MessageReaction reaction}
* was removed and the {@link Message message} updated and the database updated, or, if no post is present, only if the database was updated
*/
CompletableFuture<Void> removeRoleFromAssignableRolePlace(AServer server, String placeName, FullEmote emote);
/**
* This method is used to setup the {@link AssignableRolePlacePost} for an
* {@link AssignableRolePlace place}. If there are previous {@link AssignableRolePlacePost posts},
* this method will delete them first. This method does not do the rendering, but is only the entry point for the process.
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
* @param name The key which identifies the {@link AssignableRolePlace place} within the {@link AServer server}
* @return A {@link CompletableFuture future} which completes if the complete setup is finished successfully.
*/
CompletableFuture<Void> setupAssignableRolePlace(AServer server, String name);
/**
* This method is used to update the {@link AssignableRolePlacePost posts}
* of the {@link AssignableRolePlace place} identified by the {@link AServer server} and the key. This
* effectively re-renders the template for an {@link AssignableRolePlace place} and updates the existing
* {@link AssignableRolePlacePost posts} accordingly. In case there are no posts, this method returns immediately.
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
* @param name The key of the {@link AssignableRolePlace place}
* @throws ChannelNotInGuildException if the channel which contained the posts does not exist anymore
* @return A {@link CompletableFuture future} which completes successfully if *every* update was successful.
*/
CompletableFuture<Void> refreshAssignablePlacePosts(AServer server, String name);
/**
* This method is used to update the {@link AssignableRolePlacePost posts}
* of the {@link AssignableRolePlace place}. This effectively re-renders the template for an
* {@link AssignableRolePlace place} and updates the existing {@link AssignableRolePlacePost posts} accordingly.
* In case there are no posts, this method returns immediately.
* @param place The {@link AssignableRolePlace place} which should have their {@link Message messages} were updated
* @throws ChannelNotInGuildException if the channel which contained the posts does not exist anymore
* @return A {@link CompletableFuture future} which completes successfully if *every* update was successful.
*/
CompletableFuture<Void> refreshAssignablePlacePosts(AssignableRolePlace place);
/**
* This method updates the first {@link AssignableRolePlacePost posts} which contains the description of the
* {@link AssignableRolePlace place}. If there are no posts, this method will return immediately
* @param place The {@link AssignableRolePlace place} to update the
* @throws ChannelNotInGuildException if the channel which contained the post does not exist anymore
* @return A {@link CompletableFuture future} which completes when the update of the {@link Message message}
* was completed
*/
CompletableFuture<Void> refreshTextFromPlace(AssignableRolePlace place);
/**
* Sets the active attribute of the {@link AssignableRolePlace place} identified by {@link AServer server}
* and the key
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
* @param name The key of the {@link AssignableRolePlace place}
* @param newValue The new vale of the active attribute
*/
void setAssignablePlaceActiveTo(AServer server, String name, Boolean newValue);
/**
* Activates the {@link AssignableRolePlace place} identified by {@link AServer server}
* and the key
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
* @param name The key of the {@link AssignableRolePlace place} to activate
*/
void activateAssignableRolePlace(AServer server, String name);
/**
* Activates the {@link AssignableRolePlace place}, which means that the activate attribute will be set to true
* @param place The {@link AssignableRolePlace place} to activate
*/
void activateAssignableRolePlace(AssignableRolePlace place);
/**
* De-activates the {@link AssignableRolePlace place} identified by {@link AServer server}
* and the key
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
* @param name The key of the {@link AssignableRolePlace place} to de-activate
*/
void deactivateAssignableRolePlace(AServer server, String name);
/**
* De-activates the {@link AssignableRolePlace place}, which means that the activate attribute will be set to false
* @param place The {@link AssignableRolePlace place} to de-activate
*/
void deactivateAssignableRolePlace(AssignableRolePlace place);
// inline attribute
/**
* Sets the inline attribute of the {@link AssignableRolePlace place} identified by {@link AServer server}
* and the key. This method will update any existing {@link AssignableRolePlacePost posts} of the place, if there
* are any.
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
* @param name The key of the {@link AssignableRolePlace place}
* @param newValue The new vale of the inline attribute
*/
CompletableFuture<Void> setAssignablePlaceInlineTo(AServer server, String name, Boolean newValue);
/**
* Sets the inline attribute of the {@link AssignableRolePlace place} identified by {@link AServer server}
* and the key to true. This method will update any existing {@link AssignableRolePlacePost posts} of the place, if there
* are any.
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
* @param name The key of the {@link AssignableRolePlace place} to inline
*/
CompletableFuture<Void> inlineAssignableRolePlace(AServer server, String name);
/**
* Sets the inline attribute of the {@link AssignableRolePlace place} to true. This method will update any existing
* {@link AssignableRolePlacePost posts} of the place, if there are any.
* @param place The {@link AssignableRolePlace place} to inline
*/
CompletableFuture<Void> inlineAssignableRolePlace(AssignableRolePlace place);
/**
* Sets the inline attribute of the {@link AssignableRolePlace place} identified by {@link AServer server}
* and the key to false. This method will update any existing {@link AssignableRolePlacePost posts} of the place, if there
* are any.
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
* @param name The key of the {@link AssignableRolePlace place} to spread
*/
CompletableFuture<Void> spreadAssignableRolePlace(AServer server, String name);
/**
* Sets the inline attribute of the {@link AssignableRolePlace place} to false. This method will update any existing
* {@link AssignableRolePlacePost posts} of the place, if there are any.
* @param place The {@link AssignableRolePlace place} to spread
*/
CompletableFuture<Void> spreadAssignableRolePlace(AssignableRolePlace place);
// unique attribute
/**
* Sets the unique attribute of the {@link AssignableRolePlace place} identified by {@link AServer server}
* and the key.
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
* @param name The key of the {@link AssignableRolePlace place}
* @param newValue The new vale of the unique attribute
*/
void setAssignablePlaceUniqueTo(AServer server, String name, Boolean newValue);
/**
* Sets the unique attribute of the {@link AssignableRolePlace place} identified by {@link AServer server}
* and the key to true.
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
* @param name The key of the {@link AssignableRolePlace place} to activate unique role handling
*/
void uniqueAssignableRolePlace(AServer server, String name);
/**
* Sets the unique attribute of the {@link AssignableRolePlace place} to true.
* @param place The {@link AssignableRolePlace place} to activate unique role handling
*/
void uniqueAssignableRolePlace(AssignableRolePlace place);
/**
* Sets the unique attribute of the {@link AssignableRolePlace place} identified by {@link AServer server}
* and the key to false.
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
* @param name The key of the {@link AssignableRolePlace place} to disable unique role handling
*/
void multipleAssignableRolePlace(AServer server, String name);
/**
* Sets the unique attribute of the {@link AssignableRolePlace place} to false.
* @param place The {@link AssignableRolePlace place} to disable unique role handling
*/
void multipleAssignableRolePlace(AssignableRolePlace place);
// auto remove attribute
/**
* Sets the auto-remove attribute of the {@link AssignableRolePlace place} identified by {@link AServer server}
* and the key.
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
* @param name The key of the {@link AssignableRolePlace place}
* @param newValue The new vale of the auto-remove attribute
*/
void setAssignablePlaceAutoRemoveTo(AServer server, String name, Boolean newValue);
/**
* Sets the auto-remove attribute of the {@link AssignableRolePlace place} identified by {@link AServer server}
* and the key to true.
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
* @param name The key of the {@link AssignableRolePlace place} to activate the automatic removal of reactions
*/
void autoRemoveAssignableRolePlace(AServer server, String name);
/**
* Sets the auto-remove attribute of the {@link AssignableRolePlace place} to true.
* @param place The {@link AssignableRolePlace place} to activate the automatic removal of reactions
*/
void autoRemoveAssignableRolePlace(AssignableRolePlace place);
/**
* Sets the auto-remove attribute of the {@link AssignableRolePlace place} identified by {@link AServer server}
* and the key to false.
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
* @param name The key of the {@link AssignableRolePlace place} to keep reactions
*/
void keepReactionsAssignableRolePlace(AServer server, String name);
/**
* Sets the auto-remove attribute of the {@link AssignableRolePlace place} to false.
* @param place The {@link AssignableRolePlace place} to keep reactions
*/
void keepReactionsAssignableRolePlace(AssignableRolePlace place);
/**
* Swaps the positions of the two {@link AssignableRole roles} identified by the respective
* {@link FullEmote emote}. This will only update the it in the database, and require a new setup. The
* two {@link FullEmote emotes} are assumed to be different
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
* @param name The key of the {@link AssignableRolePlace place}
* @param firstEmote The {@link FullEmote emote} which identifies the first {@link AssignableRole role} to swap
* @param secondEmote The {@link FullEmote emote} which identifies the second {@link AssignableRole role} to swap
* @throws EmoteNotInAssignableRolePlaceException if either one of them is not part of the {@link AssignableRolePlace place}
*
*/
void swapPositions(AServer server, String name, FullEmote firstEmote, FullEmote secondEmote);
/**
* This method renders the {@link AssignableRolePlace place} and post the created {@link MessageToSend messageToSend}
* in the current channel.
* @param server The {@link AServer server} of the {@link AssignableRolePlace place} to test
* @param name The key of the {@link AssignableRolePlace place}
* @param channel The {@link TextChannel channel} in which the resulting {@link MessageToSend messageToSend}
* should be posted in
* @return A {@link CompletableFuture future} which completes when all {@link MessageToSend messageToSend}
* have been sent
*/
CompletableFuture<Void> testAssignableRolePlace(AServer server, String name, TextChannel channel);
void showAssignablePlaceConfig(AServer server, String name, TextChannel channel);
void moveAssignableRolePlace(AServer server, String name, TextChannel newChannel);
void changeAssignablePlaceDescription(AServer server, String name, String newDescription);
/**
* This method renders the configuration of the {@link AssignableRolePlace place} identified by {@link AServer server}
* and key into an {@link MessageToSend messageToSend} and sends a message to the given {@link TextChannel channel}.
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
* @param name The key of the {@link AssignableRolePlace place}
* @param channel The {@link TextChannel channel} in which the resulting {@link MessageToSend messageToSend} should be posted in
* @return A {@link CompletableFuture future} which completes when the {@link MessageToSend} has been sent
*/
CompletableFuture<Void> showAssignablePlaceConfig(AServer server, String name, TextChannel channel);
/**
* Changes the {@link AChannel channel} of the {@link AssignableRole place} identified by {@link AServer server}
* and key to the given {@link TextChannel channel}. This only changes the configuration and does not impact
* any currently posted {@link AssignableRolePlacePost posts}
* @param name The key of the {@link AssignableRolePlace place}
* @param newChannel The {@link TextChannel channel} where the {@link AssignableRolePlace place} should be posted to.
*/
void moveAssignableRolePlace(String name, TextChannel newChannel);
/**
* Deletes the {@link AssignableRolePlace place} identified by {@link AServer server} and key. This method will first
* delete all the {@link AssignableRolePlacePost posts} and then remove the references from the database.
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
* @param name The key of the {@link AssignableRolePlace place}
* @return A {@link CompletableFuture future} which completes after all posts have been deleted
*/
CompletableFuture<Void> deleteAssignableRolePlace(AServer server, String name);
CompletableFuture<Void> changeText(AServer server, String name, String newText);
/**
* Changes the text of an {@link AssignableRolePlace place} in the database only.
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
* @param name The key of the {@link AssignableRolePlace place}
* @param newText The new value for the text attribute displayed in the first {@link AssignableRolePlacePost post}
*/
void changeText(AServer server, String name, String newText);
/**
* Changes the text of an {@link AssignableRolePlace place} in the database, and updates the first
* {@link AssignableRolePlacePost post}. The update of the post happens after the change in the database.
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
* @param name The key of the {@link AssignableRolePlace place}
* @param newText The new value for the text attribute displayed in the first {@link AssignableRolePlacePost post}
*/
CompletableFuture<Void> changeTextAsync(AServer server, String name, String newText);
/**
* Removes the reactions and the roles from the user from the place, this does not touch the stored data
* @param place The {@link AssignableRolePlace} to which remove the existing reactions and roles from
* @param user The {@link AssignedRoleUser} to the remove *all* reactions and assigned roles from
* @return A {@link CompletableFuture} which completes when both of these actions have been done for all {@link dev.sheldan.abstracto.assignableroles.models.database.AssignableRole}
* @param place The {@link AssignableRolePlace place} to which remove the existing reactions and roles from
* @param user The {@link AssignedRoleUser user} to the remove *all* reactions and assigned roles from
* @return A {@link CompletableFuture future} which completes when both of these actions have been done for all {@link AssignableRole assignableRoles}
*/
CompletableFuture<Void> removeExistingReactionsAndRoles(AssignableRolePlace place, AssignedRoleUser user);
/**
* Changes the configuration of the given {@link AssignableRolePlaceParameterKey key} to the given value of the
* {@link AssignableRolePlace place} identified by {@link AServer server} and key. If it can be updated immediately,
* this will update the {@link AssignableRolePlacePost posts} and the return {@link CompletableFuture future}
* will return afterwards. This is the case for {@link AssignableRolePlaceParameterKey#INLINE}. The rest of the
* keys will only update the configuration in the database, and the place needs a refresh at a later point.
* @param server The {@link AServer server} in which the {@link AssignableRolePlace place} is
* @param name The key of the {@link AssignableRolePlace place}
* @param keyToChange The {@link AssignableRolePlaceParameterKey key} to change
* @param newValue The new value of the attribute, but be able to convert to a boolean via {@link org.apache.commons.lang3.BooleanUtils#toBooleanObject(String)}
* @return A {@link CompletableFuture future} which completes when the configuration has been completed
*/
CompletableFuture<Void> changeConfiguration(AServer server, String name, AssignableRolePlaceParameterKey keyToChange, Object newValue);
/**
* Retrieves all {@link AssignableRolePlace places}, renders them into {@link MessageToSend messageToSend} and sends
* this message to the given {@link TextChannel channel}.
* @param server The {@link AServer server} for which the {@link AssignableRolePlace places} should be shown for
* @param channel The {@link TextChannel channel} to send the {@link MessageToSend messageToSend} in
* @return A {@link CompletableFuture future} which completes when the message has been sent
*/
CompletableFuture<Void> showAllAssignableRolePlaces(AServer server, TextChannel channel);
}

View File

@@ -8,17 +8,107 @@ import net.dv8tion.jda.api.entities.Member;
import java.util.concurrent.CompletableFuture;
/**
* Service responsible to manage actions on an {@link AssignableRole assignableRole}
*/
public interface AssignableRoleService {
CompletableFuture<Void> assignAssignableRoleToUser(Long assignableRoleId, Member toAdd);
/**
* Adds the given {@link AssignableRole assignableRole} to the given {@link Member member}
* @param assignableRoleId The ID of the {@link AssignableRole} to add
* @param member The {@link Member member} who should receive the {@link AssignableRole role}
* @return A {@link CompletableFuture future} which completes when the {@link net.dv8tion.jda.api.entities.Role role} was added to the {@link Member member}
*/
CompletableFuture<Void> assignAssignableRoleToUser(Long assignableRoleId, Member member);
/**
* Adds the given {@link AssignableRole assignableRole} to the given {@link ServerUser serverUser}
* @param assignableRoleId The ID of the {@link AssignableRole} to add
* @param serverUser The {@link ServerUser serverUser} who should receive the {@link AssignableRole role}
* @return A {@link CompletableFuture future} which completes when the {@link net.dv8tion.jda.api.entities.Role role} was added to the {@link ServerUser serverUser}
*/
CompletableFuture<Void> assignAssignableRoleToUser(Long assignableRoleId, ServerUser serverUser);
/**
* Clears all {@link AssignableRole assignableRoles} which are currently given to the {@link AUserInAServer user} of a certain
* {@link AssignableRolePlace place}
* @param place The {@link AssignableRolePlace place} from which all {@link AssignableRole roles} from an {@link AUserInAServer user} should be removed of
* @param user The {@link AUserInAServer user} to remove the {@link AssignableRole assignableRoles} of
*/
void clearAllRolesOfUserInPlace(AssignableRolePlace place, AUserInAServer user);
/**
* Assigns the given {@link AssignableRole role} to the {@link Member member} and stores the assignment as a
* {@link dev.sheldan.abstracto.assignableroles.models.database.AssignedRoleUser}
* @param assignableRoleId The ID of an {@link AssignableRole assignableRole} to be added to the {@link Member member}
* @param toAdd The {@link Member member} to add the role to
* @return A {@link CompletableFuture future} which completes when the {@link net.dv8tion.jda.api.entities.Role role} has
* been added and the {@link dev.sheldan.abstracto.assignableroles.models.database.AssignedRoleUser user} has been persisted
*/
CompletableFuture<Void> fullyAssignAssignableRoleToUser(Long assignableRoleId, Member toAdd);
/**
* Removes the {@link AssignableRole role} from the given {@link Member member}
* @param assignableRole The {@link AssignableRole role} to remove
* @param member The {@link Member member} to remove the {@link AssignableRole role} from
* @return A {@link CompletableFuture future} which completes when the {@link net.dv8tion.jda.api.entities.Role role}
* has been removed from the {@link Member member}
*/
CompletableFuture<Void> removeAssignableRoleFromUser(AssignableRole assignableRole, Member member);
/**
* Removes the {@link AssignableRole role} from the given {@link Member member}
* @param assignableRoleId The ID of an {@link AssignableRole role} to remove
* @param member The {@link Member member} to remove the {@link AssignableRole role} from
* @return A {@link CompletableFuture future} which completes when the {@link net.dv8tion.jda.api.entities.Role role}
* has been removed from the {@link Member member}
*/
CompletableFuture<Void> removeAssignableRoleFromUser(Long assignableRoleId, Member member);
/**
* Removes the {@link AssignableRole role} from the given {@link AUserInAServer aUserInAServer}
* @param assignableRole The {@link AssignableRole role} to remove
* @param aUserInAServer The {@link AUserInAServer aUserInAServer} to remove the {@link AssignableRole role} from
* @return A {@link CompletableFuture future} which completes when the {@link net.dv8tion.jda.api.entities.Role role}
* has been removed from the {@link AUserInAServer aUserInAServer}
*/
CompletableFuture<Void> removeAssignableRoleFromUser(AssignableRole assignableRole, AUserInAServer aUserInAServer);
/**
* Removes the given {@link AssignableRole role} from the {@link ServerUser serverUser} and stores the assignment as a
* {@link dev.sheldan.abstracto.assignableroles.models.database.AssignedRoleUser}
* @param assignableRole The {@link AssignableRole assignableRole} to be removed from the {@link ServerUser serverUser}
* @param serverUser The {@link ServerUser serverUser} to remove the role from
* @return A {@link CompletableFuture future} which completes when the {@link net.dv8tion.jda.api.entities.Role role} has
* been removed and the {@link dev.sheldan.abstracto.assignableroles.models.database.AssignedRoleUser user} has been persisted
*/
CompletableFuture<Void> fullyRemoveAssignableRoleFromUser(AssignableRole assignableRole, ServerUser serverUser);
/**
* Adds the {@link AssignableRole assignableRole} to the given {@link AUserInAServer userInAServer} in the database
* @param assignableRoleId The ID of the {@link AssignableRole role} to be added
* @param aUserInAServer The {@link AUserInAServer user} to get the {@link AssignableRole role}
*/
void addRoleToUser(Long assignableRoleId, AUserInAServer aUserInAServer);
/**
* Adds the {@link AssignableRole assignableRole} to the given {@link AUserInAServer userInAServer} in the database
* @param assignableRole The {@link AssignableRole role} to be added
* @param aUserInAServer The {@link AUserInAServer user} to get the {@link AssignableRole role}
*/
void addRoleToUser(AssignableRole assignableRole, AUserInAServer aUserInAServer);
/**
* Removes the {@link AssignableRole assignableRole} from the given {@link AUserInAServer userInAServer} in the database
* @param assignableRole The {@link AssignableRole role} to be removed
* @param aUserInAServer The {@link AUserInAServer user} to get the {@link AssignableRole role} removed
*/
void removeRoleFromUser(AssignableRole assignableRole, AUserInAServer aUserInAServer);
/**
* Removes the {@link AssignableRole assignableRole} from the given {@link AUserInAServer userInAServer} in the database
* @param assignableRoleId The ID of the {@link AssignableRole role} to be removed
* @param aUserInAServer The {@link AUserInAServer user} to get the {@link AssignableRole role} removed
*/
void removeRoleFromUser(Long assignableRoleId, AUserInAServer aUserInAServer);
}

View File

@@ -6,13 +6,62 @@ import dev.sheldan.abstracto.assignableroles.models.database.AssignableRolePlace
import dev.sheldan.abstracto.core.models.cache.CachedEmote;
import dev.sheldan.abstracto.core.models.database.AEmote;
import dev.sheldan.abstracto.core.models.database.ARole;
import net.dv8tion.jda.api.entities.MessageReaction;
/**
* Management service for the table of {@link AssignableRole assignableRoles}
*/
public interface AssignableRoleManagementService {
/**
* Adds the given {@link ARole role} to the {@link AssignableRolePlace place} to be identified with the given {@link AEmote emote}
* and displayed with the given description. An optional {@link AssignableRolePlacePost post} can be provided, if the
* place has already been setup.
* @param place The {@link AssignableRolePlace place} to add the the {@link ARole role} to
* @param emote The {@link AEmote emote} which is used as an reaction on the {@link AssignableRolePlacePost post}
* @param role The {@link ARole role} which should be given to the {@link dev.sheldan.abstracto.core.models.database.AUserInAServer user} placing a reaction
* @param description The description which should be displayed in the field for the given {@link ARole role}
* @param post If a {@link AssignableRolePlacePost post} already exists, it can be provided to link the newly created {@link AssignableRole directly}
* @return The created instance of the {@link AssignableRole assignableRole} according to the given parameters
*/
AssignableRole addRoleToPlace(AssignableRolePlace place, AEmote emote, ARole role, String description, AssignableRolePlacePost post);
/**
* Adds the {@link ARole role} (identified by its ID) to the {@link AssignableRolePlace place} (identified by its ID),
* which in turn is identified by the given {@link AEmote emote} (identified by its ID) and displayed with the given description.
* An optional {@link AssignableRolePlacePost post} can be provided (identified by the ID of the {@link net.dv8tion.jda.api.entities.Message}), if
* it already exists
* @param placeId The ID of the {@link AssignableRolePlace} to add an {@link AssignableRole assignableRole} to
* @param emoteId The ID of the {@link AEmote emote} which should be used as an reaction on the {@link AssignableRolePlacePost post}
* @param roleId The ID of the {@link ARole role} which should be given to the {@link dev.sheldan.abstracto.core.models.database.AUserInAServer user} placing a reaction
* @param description The description which should be displayed in the field for the given {@link ARole role}
* @param messageId If provided, this message ID will be used to identify the {@link AssignableRolePlacePost post} which already exists
* @return The created instance of the {@link AssignableRole assignableRole} according to the given parameters
*/
AssignableRole addRoleToPlace(Long placeId, Integer emoteId, Long roleId, String description, Long messageId);
/**
* Adds the {@link ARole role} (identified by its ID) to the {@link AssignableRolePlace place} (identified by its ID),
* which in turn is identified by the given {@link AEmote emote} (identified by its ID) and displayed with the given description.
* @param placeId The ID of the {@link AssignableRolePlace} to add an {@link AssignableRole assignableRole} to
* @param emoteId The ID of the {@link AEmote emote} which should be used as an reaction on the {@link AssignableRolePlacePost post}
* @param roleId The ID of the {@link ARole role} which should be given to the {@link dev.sheldan.abstracto.core.models.database.AUserInAServer user} placing a reaction
* @param description The description which should be displayed in the field for the given {@link ARole role}
* @return The created instance of the {@link AssignableRole assignableRole} according to the given parameters
*/
AssignableRole addRoleToPlace(Long placeId, Integer emoteId, Long roleId, String description);
/**
* Finds the {@link AssignableRole} given by the ID and returns it if found. Throws an exception otherwise.
* @param assignableRoleId The ID Of the {@link AssignableRole assignableRole} to find
* @return An instance of {@link AssignableRole assignableRole} if it exists for the given ID
*/
AssignableRole getByAssignableRoleId(Long assignableRoleId);
AssignableRole getRoleForReactionEmote(MessageReaction.ReactionEmote emote, AssignableRolePlace assignableRolePlace);
/**
* Returns the respective {@link AssignableRole assignableRole} for the {@link CachedEmote emote} which is part of the
* {@link AssignableRolePlace place}. It will throw an exception, if the {@link CachedEmote emote} is not used.
* @param cachedEmote
* @param assignableRolePlace
* @return
*/
AssignableRole getRoleForReactionEmote(CachedEmote cachedEmote, AssignableRolePlace assignableRolePlace);
}

View File

@@ -7,15 +7,82 @@ import dev.sheldan.abstracto.core.models.database.AServer;
import java.util.List;
import java.util.Optional;
/**
* Management service for {@link AssignableRolePlace place} table
*/
public interface AssignableRolePlaceManagementService {
AssignableRolePlace createPlace(AServer server, String name, AChannel channel, String text);
/**
* Creates an {@link AssignableRolePlace place} with the given attributes
* @param name The key of the {@link AssignableRolePlace place} to identify it with
* @param channel The {@link AChannel channel} in which the {@link dev.sheldan.abstracto.assignableroles.models.database.AssignableRolePlacePost posts}
* should be created in
* @param text The text which should be shown in the description
* @return The {@link AssignableRolePlace place} which was created
*/
AssignableRolePlace createPlace(String name, AChannel channel, String text);
/**
* Whether or not a place with the key exists in the given {@link AServer server}
* @param server The {@link AServer server} in which it should be searched
* @param name The key of an {@link AssignableRolePlace place} which should be searched
* @return Whether or not an {@link AssignableRolePlace place} with the key exists in the {@link AServer server}
*/
boolean doesPlaceExist(AServer server, String name);
/**
* Retrieves an {@link AssignableRolePlace place} identified by the given key in the {@link AServer server}
* @param server The {@link AServer server} to search in
* @param name The key of the {@link AssignableRolePlace place} to search for
* @throws dev.sheldan.abstracto.assignableroles.exceptions.AssignableRolePlaceNotFoundException if not found
* @return Returns an instance of {@link AssignableRolePlace place}, if it was found
*/
AssignableRolePlace findByServerAndKey(AServer server, String name);
/**
* Retrieves an {@link AssignableRolePlace place} via its ID in an {@link Optional optional}
* @param id The ID to search for
* @return Returns an {@link Optional optional} with an instance of {@link AssignableRolePlace place}, if it was found
* and empty otherwise
*/
Optional<AssignableRolePlace> findByPlaceIdOptional(Long id);
/**
* Retrieves an {@link AssignableRolePlace place} via its ID
* @param id The ID to search for
* @throws dev.sheldan.abstracto.assignableroles.exceptions.AssignableRolePlaceNotFoundException if not found
* @return Returns an {@link AssignableRolePlace place} if one was found with this ID
*/
AssignableRolePlace findByPlaceId(Long id);
void moveAssignableRolePlace(AServer server, String name, AChannel newChannel);
/**
* Changes the {@link AChannel channel} in which a {@link AssignableRolePlace place} should be posted towards
* when being setup.
* @param name The key of the {@link AssignableRolePlace place} to move
* @param newChannel The new {@link AChannel channel} where the place should be moved to, used to determine in which {@link AServer server}
* the {@link AssignableRolePlace place} is
*/
void moveAssignableRolePlace(String name, AChannel newChannel);
/**
* Changes the {@link AssignableRolePlace#text description} of an assignable role place
* @param server The {@link AServer server} in which to look for the place
* @param name The key of the {@link AssignableRolePlace place} to change the descripiont for
* @param newDescription The description value which should be used from now on
*/
void changeAssignableRolePlaceDescription(AServer server, String name, String newDescription);
/**
* Deletes the {@link AssignableRolePlace place}
* @param place The {@link AssignableRolePlace place} to remove
*/
void deleteAssignablePlace(AssignableRolePlace place);
/**
* Retrieves all {@link AssignableRolePlace assignableRolePlaces} for the given {@link AServer server}
* @param server The {@link AServer server} for whom the places should be retrieved for
* @return All {@link AssignableRolePlace assignableRolePlaces} in the given {@link AServer server}
*/
List<AssignableRolePlace> findAllByServer(AServer server);
}

View File

@@ -1,12 +1,37 @@
package dev.sheldan.abstracto.assignableroles.service.management;
import dev.sheldan.abstracto.assignableroles.exceptions.AssignableRolePlacePostNotFoundException;
import dev.sheldan.abstracto.assignableroles.models.database.AssignableRolePlace;
import dev.sheldan.abstracto.assignableroles.models.database.AssignableRolePlacePost;
import java.util.Optional;
/**
* Management service for {@link AssignableRolePlacePost post} table
*/
public interface AssignableRolePlacePostManagementService {
/**
* Finds a {@link AssignableRolePlacePost post} via the ID of the {@link net.dv8tion.jda.api.entities.Message} it was
* posted
* @param messageId The ID of the {@link net.dv8tion.jda.api.entities.Message} in which the
* @return An {@link Optional optional} containing the {@link AssignableRolePlacePost post}, if one was found, empty otherwise
*/
Optional<AssignableRolePlacePost> findByMessageIdOptional(Long messageId);
/**
* Finds a {@link AssignableRolePlacePost post} via the ID of the {@link net.dv8tion.jda.api.entities.Message} it was
* posted
* @param messageId The ID of the {@link net.dv8tion.jda.api.entities.Message} in which the
* @throws AssignableRolePlacePostNotFoundException if it was not found
* @return The {@link AssignableRolePlacePost post} if one existed with this ID
*/
AssignableRolePlacePost findByMessageId(Long messageId);
/**
* Creates an {@link AssignableRolePlacePost post} for the given {@link AssignableRolePlace place} in the given message ID
* @param updatedPlace The {@link AssignableRolePlace place} this post should be part of
* @param messageId The ID of the message in which the post exists
* @return
*/
AssignableRolePlacePost createAssignableRolePlacePost(AssignableRolePlace updatedPlace, Long messageId);
}

View File

@@ -1,5 +1,6 @@
package dev.sheldan.abstracto.assignableroles.service.management;
import dev.sheldan.abstracto.assignableroles.exceptions.AssignedUserNotFoundException;
import dev.sheldan.abstracto.assignableroles.models.database.AssignableRole;
import dev.sheldan.abstracto.assignableroles.models.database.AssignedRoleUser;
import dev.sheldan.abstracto.core.models.ServerUser;
@@ -7,14 +8,60 @@ import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import java.util.Optional;
/**
* Management service for {@link AssignedRoleUser assignedRoleUser} table
*/
public interface AssignedRoleUserManagementService {
/**
* Adds the given {@link AssignableRole assignableRole} to the given {@link AUserInAServer user}.
* @param assignableRole The {@link AssignableRole assignableRole} to add
* @param aUserInAServer The {@link AUserInAServer user} who should get the {@link AssignableRole role}
*/
void addAssignedRoleToUser(AssignableRole assignableRole, AUserInAServer aUserInAServer);
/**
* Removes the given {@link AssignableRole assignableFrom} from the given {@link AUserInAServer user}.
* @param assignableRole The {@link AssignableRole assignableRole} to remove
* @param aUserInAServer The {@link AUserInAServer user} from whom the {@link AssignableRole role} should be removed
*/
void removeAssignedRoleFromUser(AssignableRole assignableRole, AUserInAServer aUserInAServer);
/**
* Removes the given {@link AssignableRole assignableFrom} from the given {@link AssignedRoleUser user}.
* @param assignableRole The {@link AssignableRole assignableRole} to remove
* @param user The {@link AssignedRoleUser user} from whom the {@link AssignableRole role} should be removed
*/
void removeAssignedRoleFromUser(AssignableRole assignableRole, AssignedRoleUser user);
/**
* Creating an {@link AssignedRoleUser assignedRoleUser} from the given {@link AUserInAServer user}
* @param aUserInAServer The {@link AUserInAServer user} to create it for
* @return The created instance of {@link AssignedRoleUser assignedRoleUser}
*/
AssignedRoleUser createAssignedRoleUser(AUserInAServer aUserInAServer);
void clearAllAssignedRolesOfUser(AUserInAServer userInAServer);
boolean doesAssignedRoleUserExist(AUserInAServer aUserInAServer);
/**
* Tries to retrieve a {@link AssignedRoleUser assignedRoleUser} from an {@link AUserInAServer userInAServer},
* and returns it as an {@link Optional optional}, if it exists. Empty otherwise.
* @param aUserInAServer The {@link AUserInAServer user} to search for
* @return An {@link Optional optional} containing the {@link AssignedRoleUser user}
*/
Optional<AssignedRoleUser> findByUserInServerOptional(AUserInAServer aUserInAServer);
/**
* Tries to retrieve a {@link AssignedRoleUser assignedRoleUser} from an {@link AUserInAServer userInAServer},
* and returns it as an {@link Optional optional}, if it exists. Empty otherwise.
* @param serverUser The {@link ServerUser user} to search for
* @return An {@link Optional optional} containing the {@link AssignedRoleUser user}
*/
Optional<AssignedRoleUser> findByUserInServerOptional(ServerUser serverUser);
/**
* Tries to retrieve a {@link AssignedRoleUser assignedRoleUser} from an {@link AUserInAServer userInAServer},
* and returns it if it exists. Throws an exception otherwise.
* @param aUserInAServer The {@link AUserInAServer user} to search for
* @throws AssignedUserNotFoundException if it doesnt find any
* @return The {@link AssignedRoleUser user} if it exists
*/
AssignedRoleUser findByUserInServer(AUserInAServer aUserInAServer);
}