mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-20 13:26:50 +00:00
[AB-90] adding poll functionality
adding select menu functionality not automatically acknowledging button interactions adding ability to define positions for components adding method to remove components to channel service always replacing message contents with edit message in a channel adding ability to reply a modal to a button interaction moving post target specific methods from server management service to post target management
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package dev.sheldan.abstracto.suggestion.config;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.config.FeatureMode;
|
||||
import dev.sheldan.abstracto.core.config.PostTargetEnum;
|
||||
import dev.sheldan.abstracto.suggestion.service.PollService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class PollFeatureConfig implements FeatureConfig {
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return SuggestionFeatureDefinition.POLL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PostTargetEnum> getRequiredPostTargets() {
|
||||
return Arrays.asList(PollPostTarget.POLLS, PollPostTarget.POLL_REMINDER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getRequiredSystemConfigKeys() {
|
||||
return Arrays.asList(PollService.SERVER_POLL_DURATION_SECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FeatureMode> getAvailableModes() {
|
||||
return Arrays.asList(PollFeatureMode.POLL_AUTO_EVALUATE, PollFeatureMode.POLL_REMINDER);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package dev.sheldan.abstracto.suggestion.config;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureMode;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum PollFeatureMode implements FeatureMode {
|
||||
POLL_AUTO_EVALUATE("pollAutoEvaluate"),
|
||||
POLL_REMINDER("pollReminder");
|
||||
|
||||
private final String key;
|
||||
|
||||
PollFeatureMode(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package dev.sheldan.abstracto.suggestion.config;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.PostTargetEnum;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum PollPostTarget implements PostTargetEnum {
|
||||
POLLS("polls"), POLL_REMINDER("pollReminder");
|
||||
|
||||
private String key;
|
||||
|
||||
PollPostTarget(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
}
|
||||
@@ -37,13 +37,16 @@ public class SuggestionFeatureConfig implements FeatureConfig {
|
||||
SuggestionFeatureMode.SUGGESTION_REMINDER,
|
||||
SuggestionFeatureMode.SUGGESTION_BUTTONS,
|
||||
SuggestionFeatureMode.SUGGESTION_AUTO_EVALUATE,
|
||||
SuggestionFeatureMode.SUGGESTION_THREAD);
|
||||
SuggestionFeatureMode.SUGGESTION_THREAD
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getRequiredSystemConfigKeys() {
|
||||
return Arrays.asList(SuggestionService.SUGGESTION_REMINDER_DAYS_CONFIG_KEY,
|
||||
return Arrays.asList(
|
||||
SuggestionService.SUGGESTION_REMINDER_DAYS_CONFIG_KEY,
|
||||
SuggestionService.SUGGESTION_AUTO_EVALUATE_DAYS_CONFIG_KEY,
|
||||
SuggestionService.SUGGESTION_AUTO_EVALUATE_PERCENTAGE_CONFIG_KEY);
|
||||
SuggestionService.SUGGESTION_AUTO_EVALUATE_PERCENTAGE_CONFIG_KEY
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum SuggestionFeatureDefinition implements FeatureDefinition {
|
||||
SUGGEST("suggestion");
|
||||
SUGGEST("suggestion"), POLL("poll");
|
||||
|
||||
private String key;
|
||||
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
package dev.sheldan.abstracto.suggestion.config;
|
||||
|
||||
public class SuggestionSlashCommandNames {
|
||||
private SuggestionSlashCommandNames() {
|
||||
|
||||
}
|
||||
public static final String SUGGEST = "suggest";
|
||||
public static final String SUGGEST_PUBLIC = "suggestpublic";
|
||||
public static final String POLL_PUBLIC = "pollpublic";
|
||||
public static final String POLL = "poll";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package dev.sheldan.abstracto.suggestion.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.core.templating.Templatable;
|
||||
|
||||
public class PollCancellationNotPossibleException extends AbstractoRunTimeException implements Templatable {
|
||||
public PollCancellationNotPossibleException() {
|
||||
super("Not possible to cancel poll.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "poll_cancellation_not_possible_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
return new Object();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package dev.sheldan.abstracto.suggestion.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.core.templating.Templatable;
|
||||
import dev.sheldan.abstracto.suggestion.model.exception.PollNotFoundExceptionModel;
|
||||
|
||||
public class PollNotFoundException extends AbstractoRunTimeException implements Templatable {
|
||||
private final PollNotFoundExceptionModel model;
|
||||
|
||||
public PollNotFoundException(Long pollId) {
|
||||
super("Poll not found");
|
||||
this.model = PollNotFoundExceptionModel
|
||||
.builder()
|
||||
.pollId(pollId)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "poll_does_not_exist_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
return model;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package dev.sheldan.abstracto.suggestion.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.core.templating.Templatable;
|
||||
|
||||
public class PollOptionAlreadyExistsException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
public PollOptionAlreadyExistsException() {
|
||||
super("Poll option already exists.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "poll_option_already_exists_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
return new Object();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package dev.sheldan.abstracto.suggestion.model;
|
||||
|
||||
import dev.sheldan.abstracto.suggestion.model.database.PollType;
|
||||
import dev.sheldan.abstracto.suggestion.model.template.PollMessageOption;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class PollCreationRequest {
|
||||
private Long pollId;
|
||||
private String description;
|
||||
private List<PollMessageOption> options;
|
||||
private Boolean allowMultiple;
|
||||
private Boolean allowAddition;
|
||||
private Boolean showDecisions;
|
||||
private String evaluationJobTrigger;
|
||||
private String reminderJobTrigger;
|
||||
private String addOptionButtonId;
|
||||
private Instant targetDate;
|
||||
private String selectionMenuId;
|
||||
private Long serverId;
|
||||
@Setter
|
||||
private Long pollChannelId;
|
||||
private Long creatorId;
|
||||
@Setter
|
||||
private Long pollMessageId;
|
||||
private PollType type;
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package dev.sheldan.abstracto.suggestion.model.database;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
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;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Table(name="poll")
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
@EqualsAndHashCode
|
||||
public class Poll {
|
||||
|
||||
@Id
|
||||
@Column(name = "id", nullable = false)
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(name = "poll_id", nullable = false)
|
||||
private Long pollId;
|
||||
|
||||
@Column(name = "message_id", nullable = false)
|
||||
private Long messageId;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Column(name = "type", nullable = false)
|
||||
private PollType type;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "creator_user_in_server_id", nullable = false)
|
||||
private AUserInAServer creator;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "channel_id", nullable = false)
|
||||
private AChannel channel;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "server_id", nullable = false)
|
||||
private AServer server;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Column(name = "state", nullable = false)
|
||||
private PollState state;
|
||||
|
||||
@Column(name = "created", nullable = false, insertable = false, updatable = false)
|
||||
private Instant created;
|
||||
|
||||
@Column(name = "updated", insertable = false, updatable = false)
|
||||
private Instant updated;
|
||||
|
||||
@Column(name = "description", nullable = false)
|
||||
private String description;
|
||||
|
||||
@Column(name = "evaluation_job_trigger_key")
|
||||
private String evaluationJobTriggerKey;
|
||||
|
||||
@Column(name = "reminder_job_trigger_key")
|
||||
private String reminderJobTriggerKey;
|
||||
|
||||
@Column(name = "target_date")
|
||||
private Instant targetDate;
|
||||
|
||||
@Column(name = "allow_multiple")
|
||||
private Boolean allowMultiple;
|
||||
|
||||
@Column(name = "show_decisions")
|
||||
private Boolean showDecisions;
|
||||
|
||||
@Column(name = "allow_addition")
|
||||
private Boolean allowAddition;
|
||||
|
||||
@Column(name = "selection_menu_id")
|
||||
private String selectionMenuId;
|
||||
|
||||
@Column(name = "add_option_button_id")
|
||||
private String addOptionButtonId;
|
||||
|
||||
@OneToMany(
|
||||
fetch = FetchType.LAZY,
|
||||
cascade = {CascadeType.PERSIST, CascadeType.MERGE},
|
||||
mappedBy = "poll")
|
||||
@Builder.Default
|
||||
private List<PollOption> options = new ArrayList<>();
|
||||
|
||||
@OneToMany(
|
||||
fetch = FetchType.LAZY,
|
||||
cascade = {CascadeType.PERSIST, CascadeType.MERGE},
|
||||
mappedBy = "poll")
|
||||
@Builder.Default
|
||||
private List<PollUserDecision> decisions = new ArrayList<>();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package dev.sheldan.abstracto.suggestion.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="poll_option")
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
@EqualsAndHashCode
|
||||
public class PollOption {
|
||||
|
||||
@Id
|
||||
@Column(name = "id", nullable = false)
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "poll_id", nullable = false)
|
||||
private Poll poll;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "server_id", nullable = false)
|
||||
private AServer server;
|
||||
|
||||
@Column(name = "label", nullable = false)
|
||||
private String label;
|
||||
|
||||
@Column(name = "value", nullable = false)
|
||||
private String value;
|
||||
|
||||
@Column(name = "description", nullable = false)
|
||||
private String description;
|
||||
|
||||
@Getter
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "adder_user_in_server_id")
|
||||
private AUserInAServer adder;
|
||||
|
||||
@Column(name = "created", nullable = false, insertable = false, updatable = false)
|
||||
private Instant created;
|
||||
|
||||
@Column(name = "updated", insertable = false, updatable = false)
|
||||
private Instant updated;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package dev.sheldan.abstracto.suggestion.model.database;
|
||||
|
||||
public enum PollState {
|
||||
NEW, FINISHED, CANCELLED, VETOED
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package dev.sheldan.abstracto.suggestion.model.database;
|
||||
|
||||
public enum PollType {
|
||||
STANDARD, QUICK
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package dev.sheldan.abstracto.suggestion.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;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Table(name="poll_user_decision")
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
@EqualsAndHashCode
|
||||
public class PollUserDecision {
|
||||
|
||||
@Id
|
||||
@Column(name = "id", nullable = false)
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "user_in_server_id", nullable = false)
|
||||
private AUserInAServer voter;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "server_id", nullable = false)
|
||||
private AServer server;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "poll_id", nullable = false)
|
||||
private Poll poll;
|
||||
|
||||
@OneToMany(
|
||||
fetch = FetchType.LAZY,
|
||||
cascade = {CascadeType.PERSIST, CascadeType.MERGE},
|
||||
mappedBy = "decision", orphanRemoval = true)
|
||||
@Builder.Default
|
||||
private List<PollUserDecisionOption> options = new ArrayList<>();
|
||||
|
||||
@Column(name = "created", nullable = false, insertable = false, updatable = false)
|
||||
private Instant created;
|
||||
|
||||
@Column(name = "updated", insertable = false, updatable = false)
|
||||
private Instant updated;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package dev.sheldan.abstracto.suggestion.model.database;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.time.Instant;
|
||||
|
||||
@Entity
|
||||
@Table(name="poll_user_decision_option")
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
@EqualsAndHashCode
|
||||
public class PollUserDecisionOption {
|
||||
|
||||
@Id
|
||||
@Column(name = "id", nullable = false)
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "user_decision_id", nullable = false)
|
||||
private PollUserDecision decision;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "option_id", nullable = false)
|
||||
private PollOption pollOption;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "poll_id", nullable = false)
|
||||
private Poll poll;
|
||||
|
||||
@Column(name = "created", nullable = false, insertable = false, updatable = false)
|
||||
private Instant created;
|
||||
|
||||
@Column(name = "updated", insertable = false, updatable = false)
|
||||
private Instant updated;
|
||||
}
|
||||
@@ -9,6 +9,8 @@ import lombok.*;
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Table(name="suggestion")
|
||||
@@ -58,6 +60,13 @@ public class Suggestion implements Serializable {
|
||||
@Column(name = "suggestion_text", nullable = false)
|
||||
private String suggestionText;
|
||||
|
||||
@OneToMany(
|
||||
fetch = FetchType.LAZY,
|
||||
cascade = {CascadeType.PERSIST, CascadeType.MERGE},
|
||||
mappedBy = "suggestion")
|
||||
@Builder.Default
|
||||
private List<SuggestionVote> votes = new ArrayList<>();
|
||||
|
||||
@Getter
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "command_channel_id", nullable = false)
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package dev.sheldan.abstracto.suggestion.model.exception;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public class PollNotFoundExceptionModel implements Serializable {
|
||||
private final Long pollId;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package dev.sheldan.abstracto.suggestion.model.payload;
|
||||
|
||||
import dev.sheldan.abstracto.core.interaction.button.ButtonPayload;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class PollAddOptionButtonPayload implements ButtonPayload {
|
||||
private Long pollId;
|
||||
private Long serverId;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package dev.sheldan.abstracto.suggestion.model.payload;
|
||||
|
||||
import dev.sheldan.abstracto.core.interaction.modal.ModalPayload;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public class PollAddOptionModalPayload implements ModalPayload {
|
||||
private String modalId;
|
||||
private String labelInputComponentId;
|
||||
private String descriptionInputComponentId;
|
||||
private Long serverId;
|
||||
private Long pollId;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package dev.sheldan.abstracto.suggestion.model.payload;
|
||||
|
||||
import dev.sheldan.abstracto.core.interaction.menu.SelectMenuPayload;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class QuickPollSelectionMenuPayload implements SelectMenuPayload {
|
||||
private Long pollId;
|
||||
private Long serverId;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package dev.sheldan.abstracto.suggestion.model.payload;
|
||||
|
||||
import dev.sheldan.abstracto.core.interaction.menu.SelectMenuPayload;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class ServerPollSelectionMenuPayload implements SelectMenuPayload {
|
||||
private Long pollId;
|
||||
private Long serverId;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package dev.sheldan.abstracto.suggestion.model.template;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public class PollAddOptionModalModel {
|
||||
private String modalId;
|
||||
private String labelInputComponentId;
|
||||
private String descriptionInputComponentId;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package dev.sheldan.abstracto.suggestion.model.template;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.template.display.MemberNameDisplay;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class PollAddOptionNotificationModel {
|
||||
private String label;
|
||||
private String description;
|
||||
private String value;
|
||||
private Long pollId;
|
||||
private Long serverId;
|
||||
private MemberNameDisplay memberNameDisplay;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package dev.sheldan.abstracto.suggestion.model.template;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.template.display.MemberNameDisplay;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public class PollClosingMessageModel {
|
||||
private Long pollId;
|
||||
private Long serverId;
|
||||
private MemberNameDisplay cause;
|
||||
private String text;
|
||||
private Long pollMessageId;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package dev.sheldan.abstracto.suggestion.model.template;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.template.display.MemberNameDisplay;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class PollDecisionNotificationModel {
|
||||
private List<String> chosenValues;
|
||||
private Long pollId;
|
||||
private Long serverId;
|
||||
private MemberNameDisplay memberNameDisplay;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package dev.sheldan.abstracto.suggestion.model.template;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public class PollMessageOption {
|
||||
private String value;
|
||||
private String label;
|
||||
private String description;
|
||||
private Integer votes;
|
||||
private Float percentage;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package dev.sheldan.abstracto.suggestion.model.template;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class QuickPollEvaluationModel {
|
||||
private Long pollId;
|
||||
private String description;
|
||||
private Long pollMessageId;
|
||||
private List<PollMessageOption> topOptions;
|
||||
private List<PollMessageOption> options;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package dev.sheldan.abstracto.suggestion.model.template;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.template.display.MemberDisplay;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class QuickPollMessageModel {
|
||||
private MemberDisplay creator;
|
||||
private Long pollId;
|
||||
private String description;
|
||||
private String selectionMenuId;
|
||||
private String addOptionButtonId;
|
||||
private Boolean allowMultiple;
|
||||
private Instant endDate;
|
||||
private Boolean showDecisions;
|
||||
private List<PollMessageOption> options;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package dev.sheldan.abstracto.suggestion.model.template;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class ServerPollEvaluationModel {
|
||||
private Long pollId;
|
||||
private String description;
|
||||
private Long pollMessageId;
|
||||
private List<PollMessageOption> topOptions;
|
||||
private List<PollMessageOption> options;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package dev.sheldan.abstracto.suggestion.model.template;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.template.display.MemberDisplay;
|
||||
import dev.sheldan.abstracto.suggestion.model.database.Poll;
|
||||
import dev.sheldan.abstracto.suggestion.model.database.PollState;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class ServerPollMessageModel {
|
||||
private MemberDisplay creator;
|
||||
private Long pollId;
|
||||
private PollState state;
|
||||
private String description;
|
||||
private String selectionMenuId;
|
||||
private String addOptionButtonId;
|
||||
private Boolean allowMultiple;
|
||||
private Boolean showDecisions;
|
||||
private Boolean allowAdditions;
|
||||
private Instant endDate;
|
||||
private List<PollMessageOption> options;
|
||||
|
||||
public static ServerPollMessageModel fromPoll(Poll poll, List<PollMessageOption> options) {
|
||||
return ServerPollMessageModel
|
||||
.builder()
|
||||
.creator(MemberDisplay.fromAUserInAServer(poll.getCreator()))
|
||||
.description(poll.getDescription())
|
||||
.pollId(poll.getId())
|
||||
.state(poll.getState())
|
||||
.allowMultiple(poll.getAllowMultiple())
|
||||
.showDecisions(poll.getShowDecisions())
|
||||
.endDate(poll.getTargetDate())
|
||||
.allowAdditions(poll.getAllowAddition())
|
||||
.options(options)
|
||||
.addOptionButtonId(poll.getAddOptionButtonId())
|
||||
.selectionMenuId(poll.getSelectionMenuId())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package dev.sheldan.abstracto.suggestion.model.template;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class ServerPollReminderModel {
|
||||
private Long pollId;
|
||||
private String description;
|
||||
private String messageLink;
|
||||
private Long pollMessageId;
|
||||
private List<PollMessageOption> topOptions;
|
||||
private List<PollMessageOption> options;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package dev.sheldan.abstracto.suggestion.service;
|
||||
|
||||
import dev.sheldan.abstracto.suggestion.model.database.PollType;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.interactions.InteractionHook;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public interface PollService {
|
||||
|
||||
String SERVER_POLL_DURATION_SECONDS = "serverPollDurationSeconds";
|
||||
String QUICK_POLL_DURATION_SECONDS = "quickPollDurationSeconds";
|
||||
|
||||
CompletableFuture<Void> createServerPoll(Member creator, List<String> options, String description,
|
||||
Boolean allowMultiple, Boolean allowAddition, Boolean showDecisions, Duration duration);
|
||||
|
||||
CompletableFuture<Void> createQuickPoll(Member creator, List<String> options, String description,
|
||||
Boolean allowMultiple, Boolean showDecisions, InteractionHook interactionHook, Duration duration);
|
||||
|
||||
CompletableFuture<Void> setDecisionsInPollTo(Member voter, List<String> chosenValues, Long pollId, PollType pollType);
|
||||
CompletableFuture<Void> addOptionToServerPoll(Long pollId, Long serverId, Member adder, String label, String description);
|
||||
CompletableFuture<Void> evaluateServerPoll(Long pollId, Long serverId);
|
||||
CompletableFuture<Void> remindServerPoll(Long pollId, Long serverId);
|
||||
CompletableFuture<Void> evaluateQuickPoll(Long pollId, Long serverId);
|
||||
CompletableFuture<Void> closePoll(Long pollId, Long serverId, String text, Member cause);
|
||||
CompletableFuture<Void> cancelPoll(Long pollId, Long serverId, Member cause);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package dev.sheldan.abstracto.suggestion.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.suggestion.model.PollCreationRequest;
|
||||
import dev.sheldan.abstracto.suggestion.model.database.Poll;
|
||||
import dev.sheldan.abstracto.suggestion.model.database.PollType;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface PollManagementService {
|
||||
Poll createPoll(PollCreationRequest pollCreationRequest);
|
||||
Poll getPollByPollId(Long pollId, Long serverId, PollType pollType);
|
||||
Optional<Poll> getPollByPollIdOptional(Long pollId, Long serverId, PollType pollType);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package dev.sheldan.abstracto.suggestion.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.suggestion.model.PollCreationRequest;
|
||||
import dev.sheldan.abstracto.suggestion.model.database.Poll;
|
||||
import dev.sheldan.abstracto.suggestion.model.database.PollOption;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface PollOptionManagementService {
|
||||
void addOptionsToPoll(Poll poll, PollCreationRequest pollCreationRequest);
|
||||
void addOptionToPoll(Poll poll, String label, String description);
|
||||
Optional<PollOption> getPollOptionByName(Poll poll, String key);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package dev.sheldan.abstracto.suggestion.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.suggestion.model.database.Poll;
|
||||
import dev.sheldan.abstracto.suggestion.model.database.PollUserDecision;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface PollUserDecisionManagementService {
|
||||
PollUserDecision addUserDecision(Poll poll, AUserInAServer user);
|
||||
PollUserDecision createUserDecision(Poll poll, AUserInAServer user);
|
||||
Optional<PollUserDecision> getUserDecisionOptional(Poll poll, AUserInAServer user);
|
||||
PollUserDecision getUserDecision(Poll poll, AUserInAServer user);
|
||||
void savePollUserDecision(PollUserDecision pollUserDecision);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package dev.sheldan.abstracto.suggestion.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.suggestion.model.database.PollOption;
|
||||
import dev.sheldan.abstracto.suggestion.model.database.PollUserDecision;
|
||||
import dev.sheldan.abstracto.suggestion.model.database.PollUserDecisionOption;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PollUserDecisionOptionManagementService {
|
||||
PollUserDecisionOption addDecisionForUser(PollUserDecision decision, PollOption pollOption);
|
||||
void clearOptions(PollUserDecision pollUserDecision);
|
||||
void deleteDecisionOptions(PollUserDecision decision, List<PollUserDecisionOption> decisionOptionList);
|
||||
}
|
||||
Reference in New Issue
Block a user