mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-05 09:00:24 +00:00
[AB-358] upgrading to JDA 5
removal of jda-utils adding message context commands [AB-360] fixing confirmation buttons being triggered by somebody not the author
This commit is contained in:
@@ -7,10 +7,7 @@ import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -18,7 +15,7 @@ import java.util.List;
|
||||
@Getter
|
||||
@Setter
|
||||
public class CommandContext {
|
||||
private TextChannel channel;
|
||||
private GuildMessageChannel channel;
|
||||
private Guild guild;
|
||||
private Member author;
|
||||
private Message message;
|
||||
|
||||
@@ -7,13 +7,12 @@ import dev.sheldan.abstracto.core.listener.async.jda.ButtonClickedListener;
|
||||
import dev.sheldan.abstracto.core.models.listener.ButtonClickedListenerModel;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
public interface ExceptionService {
|
||||
CommandResult reportExceptionToContext(Throwable exception, CommandContext context, Command command);
|
||||
void reportExceptionToInteraction(Throwable exception, ButtonClickedListenerModel interActionContext, ButtonClickedListener executedListener);
|
||||
void reportExceptionToGuildMessageReceivedContext(Throwable exception, GuildMessageReceivedEvent event);
|
||||
void reportExceptionToPrivateMessageReceivedContext(Throwable exception, PrivateMessageReceivedEvent event);
|
||||
void reportExceptionToGuildMessageReceivedContext(Throwable exception, MessageReceivedEvent event);
|
||||
void reportExceptionToPrivateMessageReceivedContext(Throwable exception, MessageReceivedEvent event);
|
||||
void reportExceptionToChannel(Throwable exception, MessageChannel channel, Member member);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package dev.sheldan.abstracto.core.interaction;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public class MessageContextConfig {
|
||||
private String name;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.sheldan.abstracto.core.interactive;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.listener.MessageReceivedModel;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
||||
import lombok.Getter;
|
||||
@@ -7,6 +8,8 @@ import lombok.Setter;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public abstract class AbstractConfigSetupStep implements SetupStep {
|
||||
@@ -26,8 +29,8 @@ public abstract class AbstractConfigSetupStep implements SetupStep {
|
||||
private InteractiveUtils interactiveUtils;
|
||||
|
||||
|
||||
protected Runnable getTimeoutRunnable(Long serverId, Long channelId) {
|
||||
return () -> interactiveUtils.sendTimeoutMessage(serverId, channelId);
|
||||
protected Consumer<MessageReceivedModel> getTimeoutConsumer(Long serverId, Long channelId) {
|
||||
return (messageReceivedModel) -> interactiveUtils.sendTimeoutMessage(serverId, channelId);
|
||||
}
|
||||
|
||||
protected boolean checkForExit(Message message) {
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package dev.sheldan.abstracto.core.interactive;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class DelayedActionConfigContainer {
|
||||
private Class type;
|
||||
private DelayedActionConfig object;
|
||||
private String config;
|
||||
}
|
||||
@@ -2,13 +2,12 @@ package dev.sheldan.abstracto.core.interactive;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.models.listener.MessageReceivedModel;
|
||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public interface InteractiveService {
|
||||
void createMessageWithResponse(String templateKey, AUserInAServer responder, AChannel channel, Long messageId, Consumer<MessageReceivedEvent> action, Runnable finalAction);
|
||||
void createMessageWithResponse(MessageToSend messageToSend, AUserInAServer responder, AChannel channel, Long messageId, Consumer<MessageReceivedEvent> action, Runnable finalAction);
|
||||
void createMessageWithConfirmation(String text, AUserInAServer responder, AChannel channel, Long messageId, Consumer<Void> confirmation, Consumer<Void> denial, Runnable finalAction);
|
||||
void createMessageWithResponse(String templateKey, AUserInAServer responder, AChannel channel, Consumer<MessageReceivedModel> action, Consumer<MessageReceivedModel> finalAction);
|
||||
void createMessageWithResponse(MessageToSend messageToSend, AUserInAServer responder, AChannel channel, Consumer<MessageReceivedModel> action, Consumer<MessageReceivedModel> finalAction);
|
||||
}
|
||||
|
||||
@@ -2,13 +2,11 @@ package dev.sheldan.abstracto.core.interactive;
|
||||
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
public class InteractiveUtils {
|
||||
|
||||
@@ -21,7 +19,7 @@ public class InteractiveUtils {
|
||||
@Transactional
|
||||
public void sendTimeoutMessage(Long serverId, Long channelId) {
|
||||
String s = templateService.renderSimpleTemplate("feature_setup_configuration_timeout", serverId);
|
||||
Optional<TextChannel> channelOptional = channelService.getTextChannelFromServerOptional(serverId, channelId);
|
||||
channelOptional.ifPresent(channel -> channelService.sendTextToChannelNotAsync(s, channel));
|
||||
GuildMessageChannel channelOptional = channelService.getMessageChannelFromServer(serverId, channelId);
|
||||
channelService.sendTextToChannelNotAsync(s, channelOptional);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,10 +10,14 @@ import java.util.List;
|
||||
@Setter
|
||||
@Builder
|
||||
public class SetupStepResult {
|
||||
private List<DelayedActionConfig> delayedActionConfigList;
|
||||
private List<DelayedActionConfigContainer> delayedActionConfigList;
|
||||
private SetupStepResultType result;
|
||||
|
||||
public static SetupStepResult fromCancelled() {
|
||||
return SetupStepResult.builder().result(SetupStepResultType.CANCELLED).build();
|
||||
}
|
||||
|
||||
public static SetupStepResult fromSuccess() {
|
||||
return SetupStepResult.builder().result(SetupStepResultType.SUCCESS).build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package dev.sheldan.abstracto.core.listener.async;
|
||||
|
||||
import dev.sheldan.abstracto.core.interaction.MessageContextConfig;
|
||||
import dev.sheldan.abstracto.core.listener.DefaultListenerResult;
|
||||
import dev.sheldan.abstracto.core.listener.FeatureAwareListener;
|
||||
import dev.sheldan.abstracto.core.models.listener.interaction.MessageContextInteractionModel;
|
||||
|
||||
public interface MessageContextCommandListener extends FeatureAwareListener<MessageContextInteractionModel, DefaultListenerResult> {
|
||||
MessageContextConfig getConfig();
|
||||
Boolean handlesEvent(MessageContextInteractionModel model);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package dev.sheldan.abstracto.core.listener.async.entity;
|
||||
|
||||
import dev.sheldan.abstracto.core.listener.AbstractoListener;
|
||||
import dev.sheldan.abstracto.core.listener.DefaultListenerResult;
|
||||
import dev.sheldan.abstracto.core.models.listener.FeatureActivationListenerModel;
|
||||
|
||||
public interface FeatureActivationListener extends AbstractoListener<FeatureActivationListenerModel, DefaultListenerResult> {
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package dev.sheldan.abstracto.core.listener.async.entity;
|
||||
|
||||
import dev.sheldan.abstracto.core.listener.AbstractoListener;
|
||||
import dev.sheldan.abstracto.core.listener.DefaultListenerResult;
|
||||
import dev.sheldan.abstracto.core.models.listener.FeatureDeactivationListenerModel;
|
||||
|
||||
public interface FeatureDeactivationListener extends AbstractoListener<FeatureDeactivationListenerModel, DefaultListenerResult> {
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.Channel;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.io.Serializable;
|
||||
@Builder
|
||||
public class FullChannel implements Serializable {
|
||||
private AChannel channel;
|
||||
private transient TextChannel serverChannel;
|
||||
private transient Channel serverChannel;
|
||||
|
||||
public String getChannelRepr() {
|
||||
if(serverChannel != null) {
|
||||
|
||||
@@ -3,15 +3,13 @@ package dev.sheldan.abstracto.core.models;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.*;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class GuildChannelMember {
|
||||
public Guild guild;
|
||||
private TextChannel textChannel;
|
||||
private Guild guild;
|
||||
private GuildChannel textChannel;
|
||||
private Member member;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package dev.sheldan.abstracto.core.models;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.dv8tion.jda.api.entities.*;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class GuildMemberMessageChannel {
|
||||
private Guild guild;
|
||||
private GuildMessageChannel guildChannel;
|
||||
private Member member;
|
||||
private Message message;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.sheldan.abstracto.core.models.context;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
@@ -11,6 +12,7 @@ import net.dv8tion.jda.api.entities.MessageChannel;
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@SuperBuilder
|
||||
public class UserInitiatedServerContext extends ServerContext {
|
||||
private MessageChannel messageChannel;
|
||||
|
||||
@@ -31,6 +31,12 @@ public class AChannel implements SnowFlake, Serializable {
|
||||
@JoinColumn(name = "server_id", nullable = false)
|
||||
private AServer server;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@Getter
|
||||
@Setter
|
||||
@JoinColumn(name = "related_channel_id")
|
||||
private AChannel relatedChannel;
|
||||
|
||||
@Getter
|
||||
@Enumerated(EnumType.STRING)
|
||||
private AChannelType type;
|
||||
|
||||
@@ -3,15 +3,24 @@ package dev.sheldan.abstracto.core.models.database;
|
||||
import net.dv8tion.jda.api.entities.ChannelType;
|
||||
|
||||
public enum AChannelType {
|
||||
TEXT, DM, VOICE, NEWS, CATEGORY, UNKNOWN;
|
||||
TEXT, DM, VOICE, NEWS, CATEGORY, UNKNOWN, NEWS_THREAD, PUBLIC_THREAD, PRIVATE_THREAD, STAGE;
|
||||
|
||||
public static AChannelType getAChannelType(ChannelType type) {
|
||||
switch (type) {
|
||||
case TEXT: return AChannelType.TEXT;
|
||||
case PRIVATE: return AChannelType.DM;
|
||||
case VOICE: return AChannelType.VOICE;
|
||||
case STAGE: return AChannelType.STAGE;
|
||||
case NEWS: return AChannelType.NEWS;
|
||||
case CATEGORY: return AChannelType.CATEGORY;
|
||||
case GUILD_NEWS_THREAD: return AChannelType.NEWS_THREAD;
|
||||
case GUILD_PRIVATE_THREAD: return AChannelType.PRIVATE_THREAD;
|
||||
case GUILD_PUBLIC_THREAD: return AChannelType.PUBLIC_THREAD;
|
||||
default: return AChannelType.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isThread() {
|
||||
return this == PUBLIC_THREAD || this == PRIVATE_THREAD || this == NEWS_THREAD;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public class ComponentPayload {
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@Getter
|
||||
@Setter
|
||||
@JoinColumn(name = "server_id", nullable = false)
|
||||
@JoinColumn(name = "server_id")
|
||||
private AServer server;
|
||||
|
||||
@Lob
|
||||
|
||||
@@ -5,20 +5,20 @@ import dev.sheldan.abstracto.core.models.template.button.ButtonPayload;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.dv8tion.jda.api.events.interaction.ButtonClickEvent;
|
||||
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class ButtonClickedListenerModel implements FeatureAwareListenerModel {
|
||||
|
||||
private ButtonClickEvent event;
|
||||
private ButtonInteractionEvent event;
|
||||
private String payload;
|
||||
private String origin;
|
||||
private ButtonPayload deserializedPayload;
|
||||
|
||||
@Override
|
||||
public Long getServerId() {
|
||||
return event.getGuild().getIdLong();
|
||||
return event.isFromGuild() ? event.getGuild().getIdLong() : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package dev.sheldan.abstracto.core.models.listener;
|
||||
|
||||
import dev.sheldan.abstracto.core.listener.ListenerModel;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public class FeatureActivationListenerModel implements ListenerModel {
|
||||
private String featureName;
|
||||
private Long serverId;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package dev.sheldan.abstracto.core.models.listener;
|
||||
|
||||
import dev.sheldan.abstracto.core.listener.ListenerModel;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public class FeatureDeactivationListenerModel implements ListenerModel {
|
||||
private String featureName;
|
||||
private Long serverId;
|
||||
}
|
||||
|
||||
@@ -5,17 +5,18 @@ import dev.sheldan.abstracto.core.models.cache.CachedMessage;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.Channel;
|
||||
import net.dv8tion.jda.api.entities.GuildChannel;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class ReactionClearedModel implements FeatureAwareListenerModel {
|
||||
private CachedMessage message;
|
||||
private TextChannel channel;
|
||||
private Channel channel;
|
||||
|
||||
@Override
|
||||
public Long getServerId() {
|
||||
return channel.getGuild().getIdLong();
|
||||
return channel instanceof GuildChannel ? ((GuildChannel) channel).getGuild().getIdLong() : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,16 +4,17 @@ import dev.sheldan.abstracto.core.listener.FeatureAwareListenerModel;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.Channel;
|
||||
import net.dv8tion.jda.api.entities.GuildChannel;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class TextChannelCreatedModel implements FeatureAwareListenerModel {
|
||||
private TextChannel channel;
|
||||
private Channel channel;
|
||||
|
||||
@Override
|
||||
public Long getServerId() {
|
||||
return channel.getGuild().getIdLong();
|
||||
return channel instanceof GuildChannel ? ((GuildChannel)channel).getGuild().getIdLong() : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,16 +4,17 @@ import dev.sheldan.abstracto.core.listener.FeatureAwareListenerModel;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.Channel;
|
||||
import net.dv8tion.jda.api.entities.GuildChannel;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class TextChannelDeletedModel implements FeatureAwareListenerModel {
|
||||
private TextChannel channel;
|
||||
private Channel channel;
|
||||
|
||||
@Override
|
||||
public Long getServerId() {
|
||||
return channel.getGuild().getIdLong();
|
||||
return channel instanceof GuildChannel ? ((GuildChannel) channel).getGuild().getIdLong() : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ import dev.sheldan.abstracto.core.listener.FeatureAwareListenerModel;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.dv8tion.jda.api.entities.AudioChannel;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.VoiceChannel;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@@ -13,7 +13,7 @@ import net.dv8tion.jda.api.entities.VoiceChannel;
|
||||
public class VoiceChannelJoinedModel implements FeatureAwareListenerModel {
|
||||
|
||||
private Member member;
|
||||
private VoiceChannel channel;
|
||||
private AudioChannel channel;
|
||||
|
||||
@Override
|
||||
public Long getServerId() {
|
||||
|
||||
@@ -4,8 +4,8 @@ import dev.sheldan.abstracto.core.listener.FeatureAwareListenerModel;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.dv8tion.jda.api.entities.AudioChannel;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.VoiceChannel;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@@ -13,7 +13,7 @@ import net.dv8tion.jda.api.entities.VoiceChannel;
|
||||
public class VoiceChannelLeftModel implements FeatureAwareListenerModel {
|
||||
|
||||
private Member member;
|
||||
private VoiceChannel channel;
|
||||
private AudioChannel channel;
|
||||
|
||||
@Override
|
||||
public Long getServerId() {
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package dev.sheldan.abstracto.core.models.listener.interaction;
|
||||
|
||||
import dev.sheldan.abstracto.core.listener.FeatureAwareListenerModel;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.dv8tion.jda.api.events.interaction.command.MessageContextInteractionEvent;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class MessageContextInteractionModel implements FeatureAwareListenerModel {
|
||||
private MessageContextInteractionEvent event;
|
||||
|
||||
@Override
|
||||
public Long getServerId() {
|
||||
return event.isFromGuild() ? event.getGuild().getIdLong() : null;
|
||||
}
|
||||
}
|
||||
@@ -4,12 +4,12 @@ import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class ChannelGroupChannelModel {
|
||||
private AChannel channel;
|
||||
private TextChannel discordChannel;
|
||||
private MessageChannel discordChannel;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package dev.sheldan.abstracto.core.models.template.commands;
|
||||
|
||||
import dev.sheldan.abstracto.core.utils.ChannelUtils;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@@ -11,5 +11,8 @@ import net.dv8tion.jda.api.entities.TextChannel;
|
||||
public class PostTargetActionModel {
|
||||
private String postTargetKey;
|
||||
private Long channelId;
|
||||
private TextChannel channel;
|
||||
|
||||
public String getChannelAsMention() {
|
||||
return ChannelUtils.getAsMention(this.channelId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,13 +4,13 @@ import dev.sheldan.abstracto.core.models.database.PostTarget;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class PostTargetModelEntry {
|
||||
private PostTarget postTarget;
|
||||
private TextChannel channel;
|
||||
private MessageChannel channel;
|
||||
private Boolean disabled;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package dev.sheldan.abstracto.core.models.template.commands;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -9,5 +8,5 @@ import lombok.Setter;
|
||||
@Setter
|
||||
@Builder
|
||||
public class SetupCompletedNotificationModel {
|
||||
private FeatureConfig featureConfig;
|
||||
private String featureKey;
|
||||
}
|
||||
|
||||
@@ -3,12 +3,12 @@ package dev.sheldan.abstracto.core.models.template.commands;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class SetupPostTargetMessageModel {
|
||||
private String postTargetKey;
|
||||
private TextChannel currentTextChannel;
|
||||
private MessageChannel currentTextChannel;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package dev.sheldan.abstracto.core.models.template.commands;
|
||||
|
||||
import dev.sheldan.abstracto.core.interactive.DelayedActionConfig;
|
||||
import dev.sheldan.abstracto.core.interactive.DelayedActionConfigContainer;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -11,5 +11,7 @@ import java.util.List;
|
||||
@Setter
|
||||
@Builder
|
||||
public class SetupSummaryModel {
|
||||
private List<DelayedActionConfig> actionConfigs;
|
||||
private List<DelayedActionConfigContainer> actionConfigs;
|
||||
private String confirmButtonId;
|
||||
private String cancelButtonId;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package dev.sheldan.abstracto.core.models.template.display;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
|
||||
@Getter
|
||||
@@ -22,4 +23,14 @@ public class ChannelDisplay {
|
||||
.channelMention(channel.getAsMention())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
public static ChannelDisplay fromChannel(GuildMessageChannel channel) {
|
||||
if(channel == null) {
|
||||
return null;
|
||||
}
|
||||
return ChannelDisplay
|
||||
.builder()
|
||||
.name(channel.getName())
|
||||
.channelMention(channel.getAsMention())
|
||||
.build();
|
||||
}}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package dev.sheldan.abstracto.core.service;
|
||||
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public interface ApplicationCommandService {
|
||||
CompletableFuture<Void> deleteGuildCommand(Guild guild, Long commandId);
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||
import net.dv8tion.jda.api.entities.*;
|
||||
import net.dv8tion.jda.api.requests.RestAction;
|
||||
import net.dv8tion.jda.api.requests.restaction.MessageAction;
|
||||
|
||||
import java.util.List;
|
||||
@@ -16,7 +15,7 @@ public interface ChannelService {
|
||||
void sendTextToChannelNotAsync(String text, MessageChannel channel);
|
||||
CompletableFuture<Message> sendTextToAChannel(String text, AChannel channel);
|
||||
CompletableFuture<Message> sendMessageToAChannel(Message message, AChannel channel);
|
||||
CompletableFuture<Message> sendMessageToChannel(Message message, MessageChannel channel);
|
||||
CompletableFuture<Message> sendMessageToChannel(Message message, GuildMessageChannel channel);
|
||||
CompletableFuture<Message> sendTextToChannel(String text, MessageChannel channel);
|
||||
CompletableFuture<Message> sendEmbedToAChannel(MessageEmbed embed, AChannel channel);
|
||||
CompletableFuture<Message> sendEmbedToChannel(MessageEmbed embed, MessageChannel channel);
|
||||
@@ -34,7 +33,7 @@ public interface ChannelService {
|
||||
* @param textChannel The {@link MessageChannel} to send the messages to
|
||||
* @return A list of {@link CompletableFuture} representing each potential message sent
|
||||
*/
|
||||
List<CompletableFuture<Message>> sendMessageToSendToChannel(MessageToSend messageToSend, MessageChannel textChannel);
|
||||
List<CompletableFuture<Message>> sendMessageToSendToChannel(MessageToSend messageToSend, MessageChannel messageChannel);
|
||||
void editMessageInAChannel(MessageToSend messageToSend, AChannel channel, Long messageId);
|
||||
void editMessageInAChannel(MessageToSend messageToSend, MessageChannel channel, Long messageId);
|
||||
CompletableFuture<Message> editMessageInAChannelFuture(MessageToSend messageToSend, MessageChannel channel, Long messageId);
|
||||
@@ -47,23 +46,32 @@ public interface ChannelService {
|
||||
CompletableFuture<Message> removeFieldFromMessage(MessageChannel channel, Long messageId, Integer index, Integer embedIndex);
|
||||
CompletableFuture<Void> deleteTextChannel(AChannel channel);
|
||||
CompletableFuture<Void> deleteTextChannel(Long serverId, Long channelId);
|
||||
List<CompletableFuture<Message>> sendEmbedTemplateInTextChannelList(String templateKey, Object model, TextChannel channel);
|
||||
List<CompletableFuture<Message>> sendEmbedTemplateInTextChannelList(String templateKey, Object model, MessageChannel channel);
|
||||
List<CompletableFuture<Message>> sendEmbedTemplateInMessageChannelList(String templateKey, Object model, MessageChannel channel);
|
||||
CompletableFuture<Message> sendTextTemplateInTextChannel(String templateKey, Object model, TextChannel channel);
|
||||
CompletableFuture<Message> sendTextTemplateInTextChannel(String templateKey, Object model, MessageChannel channel);
|
||||
CompletableFuture<Message> sendTextTemplateInMessageChannel(String templateKey, Object model, MessageChannel channel);
|
||||
RestAction<Void> deleteMessagesInChannel(TextChannel textChannel, List<Message> messages);
|
||||
CompletableFuture<Void> deleteMessagesInChannel(MessageChannel messageChannel, List<Message> messages);
|
||||
|
||||
CompletableFuture<TextChannel> createTextChannel(String name, AServer server, Long categoryId);
|
||||
Optional<TextChannel> getChannelFromAChannel(AChannel channel);
|
||||
AChannel getFakeChannelFromTextChannel(TextChannel textChannel);
|
||||
Optional<GuildChannel> getChannelFromAChannel(AChannel channel);
|
||||
Optional<GuildMessageChannel> getGuildMessageChannelFromAChannelOptional(AChannel channel);
|
||||
GuildMessageChannel getGuildMessageChannelFromAChannel(AChannel channel);
|
||||
AChannel getFakeChannelFromTextChannel(MessageChannel messageChannel);
|
||||
CompletableFuture<Message> sendSimpleTemplateToChannel(Long serverId, Long channelId, String template);
|
||||
CompletableFuture<MessageHistory> getHistoryOfChannel(TextChannel channel, Long startMessageId, Integer amount);
|
||||
Optional<TextChannel> getTextChannelFromServerOptional(Guild serverId, Long textChannelId);
|
||||
TextChannel getTextChannelFromServer(Guild guild, Long textChannelId);
|
||||
TextChannel getTextChannelFromServerNullable(Guild guild, Long textChannelId);
|
||||
CompletableFuture<MessageHistory> getHistoryOfChannel(MessageChannel channel, Long startMessageId, Integer amount);
|
||||
Optional<GuildChannel> getGuildChannelFromServerOptional(Guild serverId, Long textChannelId);
|
||||
GuildMessageChannel getMessageChannelFromServer(Guild guild, Long textChannelId);
|
||||
|
||||
GuildMessageChannel getMessageChannelFromServer(Long serverId, Long textChannelId);
|
||||
Optional<GuildMessageChannel> getMessageChannelFromServerOptional(Long serverId, Long textChannelId);
|
||||
|
||||
GuildMessageChannel getMessageChannelFromServerNullable(Guild guild, Long textChannelId);
|
||||
Optional<GuildChannel> getGuildChannelFromServerOptional(Long serverId, Long textChannelId);
|
||||
|
||||
GuildChannel getGuildChannelFromServer(Long serverId, Long channelId);
|
||||
|
||||
Optional<TextChannel> getTextChannelFromServerOptional(Long serverId, Long textChannelId);
|
||||
TextChannel getTextChannelFromServer(Long serverId, Long textChannelId);
|
||||
CompletableFuture<Void> setSlowModeInChannel(TextChannel textChannel, Integer seconds);
|
||||
List<CompletableFuture<Message>> sendFileToChannel(String fileContent, String fileNameTemplate, String messageTemplate, Object model, TextChannel channel);
|
||||
List<CompletableFuture<Message>> sendFileToChannel(String fileContent, String fileName, TextChannel channel);
|
||||
List<CompletableFuture<Message>> sendFileToChannel(String fileContent, String fileNameTemplate, String messageTemplate, Object model, MessageChannel channel);
|
||||
List<CompletableFuture<Message>> sendFileToChannel(String fileContent, String fileName, MessageChannel channel);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package dev.sheldan.abstracto.core.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.template.button.ButtonConfigModel;
|
||||
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.interactions.components.ActionComponent;
|
||||
import net.dv8tion.jda.api.interactions.components.ActionRow;
|
||||
import net.dv8tion.jda.api.interactions.components.ButtonStyle;
|
||||
import net.dv8tion.jda.api.interactions.components.Component;
|
||||
import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -15,12 +16,12 @@ public interface ComponentService {
|
||||
Integer MAX_BUTTONS_PER_ROW = Component.Type.BUTTON.getMaxPerRow();
|
||||
String generateComponentId(Long serverId);
|
||||
String generateComponentId();
|
||||
CompletableFuture<Message> addButtonToMessage(Long messageId, TextChannel textChannel, String buttonId, String description, String emoteMarkdown, ButtonStyle style);
|
||||
CompletableFuture<Message> addButtonToMessage(Long messageId, GuildMessageChannel textChannel, String buttonId, String description, String emoteMarkdown, ButtonStyle style);
|
||||
CompletableFuture<Void> clearButtons(Message message);
|
||||
CompletableFuture<Void> disableAllButtons(Message message);
|
||||
CompletableFuture<Void> enableAllButtons(Message message);
|
||||
CompletableFuture<Void> removeComponentWithId(Message message, String componentId);
|
||||
CompletableFuture<Void> removeComponentWithId(Message message, String componentId, Boolean rearrange);
|
||||
List<ActionRow> splitIntoActionRowsMax(List<Component> components);
|
||||
List<ActionRow> splitIntoActionRowsMax(List<ActionComponent> components);
|
||||
ButtonConfigModel createButtonConfigModel();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package dev.sheldan.abstracto.core.service;
|
||||
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.interactions.commands.Command;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public interface ContextCommandService {
|
||||
CompletableFuture<Command> upsertGuildMessageContextCommand(Guild guild, String name);
|
||||
CompletableFuture<Void> deleteGuildContextCommand(Guild guild, Long commandId);
|
||||
CompletableFuture<Void> deleteGuildContextCommandByName(Guild guild, String commandName);
|
||||
}
|
||||
@@ -4,6 +4,9 @@ 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.core.listener.FeatureAwareListener;
|
||||
import dev.sheldan.abstracto.core.listener.FeatureAwareListenerModel;
|
||||
import dev.sheldan.abstracto.core.listener.ListenerExecutionResult;
|
||||
import dev.sheldan.abstracto.core.models.FeatureValidationResult;
|
||||
import dev.sheldan.abstracto.core.models.database.AFeature;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
@@ -25,4 +28,5 @@ public interface FeatureConfigService {
|
||||
FeatureMode getFeatureModeByKey(FeatureConfig featureConfig, String key);
|
||||
FeatureConfig getFeatureConfigForFeature(AFeature feature);
|
||||
boolean isModeValid(String featureName, String modeName);
|
||||
<T extends FeatureAwareListenerModel, R extends ListenerExecutionResult> boolean isFeatureAwareEnabled(FeatureAwareListener<T, R> listener, Long serverId);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package dev.sheldan.abstracto.core.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
||||
import dev.sheldan.abstracto.core.interactive.DelayedActionConfig;
|
||||
import dev.sheldan.abstracto.core.interactive.DelayedActionConfigContainer;
|
||||
import dev.sheldan.abstracto.core.interactive.SetupExecution;
|
||||
import dev.sheldan.abstracto.core.models.AServerChannelUserId;
|
||||
|
||||
@@ -10,5 +10,5 @@ import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public interface FeatureSetupService {
|
||||
CompletableFuture<Void> performFeatureSetup(FeatureConfig featureConfig, AServerChannelUserId user, Long initialMessageId);
|
||||
CompletableFuture<Void> executeFeatureSetup(FeatureConfig featureConfig, List<SetupExecution> steps, AServerChannelUserId user, List<DelayedActionConfig> delayedActionConfigs);
|
||||
CompletableFuture<Void> executeFeatureSetup(FeatureConfig featureConfig, List<SetupExecution> steps, AServerChannelUserId user, List<DelayedActionConfigContainer> delayedActionConfigs);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package dev.sheldan.abstracto.core.service;
|
||||
|
||||
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public interface PaginatorService {
|
||||
CompletableFuture<Void> createPaginatorFromTemplate(String templateKey, Object model, TextChannel textChannel, Long userId);
|
||||
CompletableFuture<Void> createPaginatorFromTemplate(String templateKey, Object model, GuildMessageChannel textChannel, Long userId);
|
||||
}
|
||||
|
||||
@@ -3,15 +3,16 @@ package dev.sheldan.abstracto.core.service.management;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannelType;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.Channel;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface ChannelManagementService {
|
||||
Optional<AChannel> loadChannelOptional(Long id);
|
||||
AChannel loadChannel(Long id);
|
||||
AChannel loadChannel(TextChannel textChannel);
|
||||
AChannel loadChannel(Channel textChannel);
|
||||
AChannel createChannel(Long id, AChannelType type, AServer server);
|
||||
AChannel createThread(Long id, AChannelType type, AServer server, AChannel parentChannel);
|
||||
AChannel markAsDeleted(Long id);
|
||||
boolean channelExists(Long id);
|
||||
void removeChannel(Long id);
|
||||
|
||||
@@ -9,4 +9,8 @@ public class ChannelUtils {
|
||||
public static String buildChannelUrl(Long serverId, Long channelId) {
|
||||
return String.format("https://discord.com/channels/%s/%s/", serverId, channelId);
|
||||
}
|
||||
|
||||
public static String getAsMention(Long channelId) {
|
||||
return "<#" + channelId + '>';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import dev.sheldan.abstracto.core.service.MemberService;
|
||||
import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.GuildMessageChannel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -36,7 +37,7 @@ public class ContextUtils {
|
||||
return builder
|
||||
.member(guildChannelMember.getMember())
|
||||
.guild(guildChannelMember.getGuild())
|
||||
.messageChannel(guildChannelMember.getTextChannel())
|
||||
.messageChannel((GuildMessageChannel) guildChannelMember.getTextChannel())
|
||||
.build();
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||
log.error("Failed to execute builder method", e);
|
||||
|
||||
Reference in New Issue
Block a user