mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-01-01 15:28:35 +00:00
[AB-xxx] upgrading to JDA 6.2.0
changing how assignable role places change their buttons
This commit is contained in:
@@ -31,7 +31,6 @@ import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
|
||||
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
|
||||
import net.dv8tion.jda.api.entities.emoji.Emoji;
|
||||
import net.dv8tion.jda.api.components.buttons.ButtonStyle;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -60,9 +59,6 @@ public class AssignableRolePlaceServiceBean implements AssignableRolePlaceServic
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
@Autowired
|
||||
private GuildService guildService;
|
||||
|
||||
@Autowired
|
||||
private EmoteService emoteService;
|
||||
|
||||
@@ -131,9 +127,18 @@ public class AssignableRolePlaceServiceBean implements AssignableRolePlaceServic
|
||||
String buttonId = componentService.generateComponentId();
|
||||
String emoteMarkdown = emoji != null ? emoji.getFormatted() : null;
|
||||
if (assignableRolePlace.getMessageId() != null) {
|
||||
AssignablePostMessage model = prepareAssignablePostMessageModel(assignableRolePlace);
|
||||
model.getRoles().add(AssignablePostRole
|
||||
.builder()
|
||||
.componentId(buttonId)
|
||||
.emoteMarkDown(emoteMarkdown)
|
||||
.description(description)
|
||||
.build());
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate(ASSIGNABLE_ROLES_POST_TEMPLATE_KEY, model, assignableRolePlace.getServer().getId());
|
||||
log.debug("Assignable role place {} has already message post with ID {} - updating.", assignableRolePlace.getId(), assignableRolePlace.getMessageId());
|
||||
return componentService.addButtonToMessage(assignableRolePlace.getMessageId(), textChannel, buttonId, description, emoteMarkdown, ButtonStyle.SECONDARY)
|
||||
.thenAccept(message -> self.persistAssignableRoleAddition(placeId, role, description, emoji, buttonId));
|
||||
return messageService.editMessageInChannel(textChannel, messageToSend, assignableRolePlace.getMessageId()).thenAccept(unused -> {
|
||||
self.persistAssignableRoleAddition(placeId, role, description, emoji, buttonId);
|
||||
});
|
||||
} else {
|
||||
log.info("Assignable role place {} is not yet setup - only adding role to the database.", assignableRolePlace.getId());
|
||||
self.persistAssignableRoleAddition(placeId, role, description, emoji, buttonId);
|
||||
@@ -174,7 +179,7 @@ public class AssignableRolePlaceServiceBean implements AssignableRolePlaceServic
|
||||
return channelService.retrieveMessageInChannel(assignableRolePlace.getServer().getId(), assignableRolePlace.getChannel().getId(), assignableRolePlace.getMessageId())
|
||||
.thenCompose(message -> {
|
||||
log.debug("Updating message {} to remove component with ID {}.", message.getIdLong(), componentId);
|
||||
return componentService.removeComponentWithId(message, componentId, true);
|
||||
return componentService.removeComponentById(message, componentId).thenAccept(message1 -> {});
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -269,8 +274,8 @@ public class AssignableRolePlaceServiceBean implements AssignableRolePlaceServic
|
||||
log.info("Deactivating assignable role place {} in server {}", place.getId(), place.getServer().getId());
|
||||
return channelService.retrieveMessageInChannel(place.getServer().getId(), place.getChannel().getId(), place.getMessageId())
|
||||
.thenCompose(message ->
|
||||
componentService.disableAllButtons(message)
|
||||
);
|
||||
componentService.disableAllComponents(message)
|
||||
).thenAccept(message -> {});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -283,8 +288,8 @@ public class AssignableRolePlaceServiceBean implements AssignableRolePlaceServic
|
||||
log.info("Activating assignable role place {} in server {}", place.getId(), place.getServer().getId());
|
||||
return channelService.retrieveMessageInChannel(place.getServer().getId(), place.getChannel().getId(), place.getMessageId())
|
||||
.thenCompose(message ->
|
||||
componentService.enableAllButtons(message)
|
||||
);
|
||||
componentService.enableAllComponents(message)
|
||||
).thenAccept(message -> {});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -200,8 +200,8 @@ public class EntertainmentServiceBean implements EntertainmentService {
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendMessageEmbedToSendToAChannel(messageToSend, pressF.getPressFChannel()))
|
||||
.thenCompose(unused -> messageService.loadMessage(serverId, channelId, messageId).thenCompose(message -> {
|
||||
log.info("Clearing buttons from pressF {} in with message {} in channel {} in server {}.", pressFId, pressFId, channelId, serverId);
|
||||
return componentService.clearButtons(message);
|
||||
}));
|
||||
return componentService.clearComponents(message);
|
||||
})).thenAccept(message -> {});
|
||||
} else {
|
||||
throw new AbstractoRunTimeException(String.format("PressF with id %s not found.", pressFId));
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class BanModerationActionModalListener implements ModalInteractionListene
|
||||
.getEvent()
|
||||
.getValues()
|
||||
.stream()
|
||||
.filter(modalMapping -> modalMapping.getId().equals(payload.getDurationInputId()))
|
||||
.filter(modalMapping -> modalMapping.getCustomId().equals(payload.getDurationInputId()))
|
||||
.map(ModalMapping::getAsString)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
@@ -76,7 +76,7 @@ public class BanModerationActionModalListener implements ModalInteractionListene
|
||||
.getEvent()
|
||||
.getValues()
|
||||
.stream()
|
||||
.filter(modalMapping -> modalMapping.getId().equals(payload.getReasonInputId()))
|
||||
.filter(modalMapping -> modalMapping.getCustomId().equals(payload.getReasonInputId()))
|
||||
.map(ModalMapping::getAsString)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
@@ -51,7 +51,7 @@ public class KickModerationActionModalListener implements ModalInteractionListen
|
||||
.getEvent()
|
||||
.getValues()
|
||||
.stream()
|
||||
.filter(modalMapping -> modalMapping.getId().equals(payload.getReasonInputId()))
|
||||
.filter(modalMapping -> modalMapping.getCustomId().equals(payload.getReasonInputId()))
|
||||
.map(ModalMapping::getAsString)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
@@ -59,7 +59,7 @@ public class MuteModerationActionModalListener implements ModalInteractionListen
|
||||
.getEvent()
|
||||
.getValues()
|
||||
.stream()
|
||||
.filter(modalMapping -> modalMapping.getId().equals(payload.getReasonInputId()))
|
||||
.filter(modalMapping -> modalMapping.getCustomId().equals(payload.getReasonInputId()))
|
||||
.map(ModalMapping::getAsString)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
@@ -68,7 +68,7 @@ public class MuteModerationActionModalListener implements ModalInteractionListen
|
||||
.getEvent()
|
||||
.getValues()
|
||||
.stream()
|
||||
.filter(modalMapping -> modalMapping.getId().equals(payload.getDurationInputId()))
|
||||
.filter(modalMapping -> modalMapping.getCustomId().equals(payload.getDurationInputId()))
|
||||
.map(ModalMapping::getAsString)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
@@ -60,7 +60,7 @@ public class WarnModerationActionModalListener implements ModalInteractionListen
|
||||
.getEvent()
|
||||
.getValues()
|
||||
.stream()
|
||||
.filter(modalMapping -> modalMapping.getId().equals(payload.getReasonInputId()))
|
||||
.filter(modalMapping -> modalMapping.getCustomId().equals(payload.getReasonInputId()))
|
||||
.map(ModalMapping::getAsString)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
@@ -43,7 +43,7 @@ public class ReportContextModalListener implements ModalInteractionListener {
|
||||
.getEvent()
|
||||
.getValues()
|
||||
.stream()
|
||||
.filter(modalMapping -> modalMapping.getId().equals(payload.getTextInputId()))
|
||||
.filter(modalMapping -> modalMapping.getCustomId().equals(payload.getTextInputId()))
|
||||
.map(ModalMapping::getAsString)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
@@ -61,7 +61,9 @@ public class KickServiceBean implements KickService {
|
||||
public CompletableFuture<Void> kickMember(Member kickedMember, Member kickingMember, String reason) {
|
||||
Guild guild = kickedMember.getGuild();
|
||||
log.info("Kicking user {} from guild {}", kickedMember.getUser().getIdLong(), guild.getIdLong());
|
||||
CompletableFuture<Void> kickFuture = guild.kick(kickedMember, reason).submit();
|
||||
CompletableFuture<Void> kickFuture = guild.kick(kickedMember)
|
||||
.reason(reason)
|
||||
.submit();
|
||||
CompletableFuture<Message> logFuture = sendKickLog(kickedMember.getUser(), ServerUser.fromMember(kickedMember), kickingMember.getUser(), ServerUser.fromMember(kickingMember), reason, guild.getIdLong());
|
||||
return CompletableFuture.allOf(kickFuture, logFuture)
|
||||
.thenAccept(unused -> self.storeInfraction(kickedMember, kickingMember, reason, logFuture.join(), guild.getIdLong()));
|
||||
|
||||
@@ -48,7 +48,7 @@ public class ServerPollAddOptionModalListener implements ModalInteractionListene
|
||||
.getEvent()
|
||||
.getValues()
|
||||
.stream()
|
||||
.filter(modalMapping -> modalMapping.getId().equals(payload.getLabelInputComponentId()))
|
||||
.filter(modalMapping -> modalMapping.getCustomId().equals(payload.getLabelInputComponentId()))
|
||||
.map(ModalMapping::getAsString)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
@@ -62,7 +62,7 @@ public class ServerPollAddOptionModalListener implements ModalInteractionListene
|
||||
.getEvent()
|
||||
.getValues()
|
||||
.stream()
|
||||
.filter(modalMapping -> modalMapping.getId().equals(payload.getDescriptionInputComponentId()))
|
||||
.filter(modalMapping -> modalMapping.getCustomId().equals(payload.getDescriptionInputComponentId()))
|
||||
.map(ModalMapping::getAsString)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
@@ -381,8 +381,8 @@ public class SuggestionServiceBean implements SuggestionService {
|
||||
if(useButtons) {
|
||||
return messageService.loadMessage(serverId, channelId, messageId).thenCompose(message -> {
|
||||
log.info("Clearing buttons from suggestion {} in with message {} in channel {} in server {}.", suggestionId, message, channelId, serverId);
|
||||
return componentService.clearButtons(message);
|
||||
});
|
||||
return componentService.clearComponents(message);
|
||||
}).thenAccept(message -> {});
|
||||
} else {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
<artifactId>twitch</artifactId>
|
||||
<version>1.6.19-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>twitch-int</artifactId>
|
||||
@@ -14,11 +15,10 @@
|
||||
<groupId>com.github.twitch4j</groupId>
|
||||
<artifactId>twitch4j</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.apollographql.apollo</groupId>
|
||||
<artifactId>apollo-runtime</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -84,7 +84,7 @@
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.github.freya022</groupId>
|
||||
<groupId>net.dv8tion</groupId>
|
||||
<artifactId>JDA</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
|
||||
@@ -1,32 +1,21 @@
|
||||
package dev.sheldan.abstracto.core.interaction;
|
||||
|
||||
import dev.sheldan.abstracto.core.interaction.button.ButtonConfigModel;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.service.MessageService;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
|
||||
import net.dv8tion.jda.api.entities.emoji.Emoji;
|
||||
import net.dv8tion.jda.api.components.ActionComponent;
|
||||
import net.dv8tion.jda.api.components.actionrow.ActionRow;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import net.dv8tion.jda.api.components.buttons.Button;
|
||||
import net.dv8tion.jda.api.components.buttons.ButtonStyle;
|
||||
import org.apache.commons.collections4.ListUtils;
|
||||
import net.dv8tion.jda.api.components.tree.MessageComponentTree;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
public class ComponentServiceBean implements ComponentService {
|
||||
|
||||
@Autowired
|
||||
private MessageService messageService;
|
||||
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
@Override
|
||||
public String generateComponentId(Long serverId) {
|
||||
return generateComponentId();
|
||||
@@ -38,95 +27,48 @@ public class ComponentServiceBean implements ComponentService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Message> addButtonToMessage(Long messageId, GuildMessageChannel textChannel, String buttonId, String description, String emoteMarkdown, ButtonStyle style) {
|
||||
return channelService.retrieveMessageInChannel(textChannel, messageId).thenCompose(message -> {
|
||||
Button button = Button.of(style, buttonId, description);
|
||||
if(emoteMarkdown != null) {
|
||||
button = button.withEmoji(Emoji.fromFormatted(emoteMarkdown));
|
||||
}
|
||||
List<ActionRow> actionRows;
|
||||
if(message.getActionRows().isEmpty()) {
|
||||
actionRows = Arrays.asList(ActionRow.of(button));
|
||||
public CompletableFuture<Message> clearComponents(Message message) {
|
||||
MessageComponentTree tree = message.getComponentTree().replace(oldComponent -> null);
|
||||
return messageService.editMessage(message, tree);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Message> disableAllComponents(Message message) {
|
||||
return setAllComponentStatesTo(message, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Message> enableAllComponents(Message message) {
|
||||
return setAllComponentStatesTo(message, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Message> removeComponentById(Message message, String componentId) {
|
||||
MessageComponentTree tree;
|
||||
tree = message.getComponentTree().replace(oldComponent -> {
|
||||
if (oldComponent instanceof Button && componentId.equals(((Button) oldComponent).getCustomId())) {
|
||||
return null;
|
||||
} else {
|
||||
ActionRow lastRow = message.getActionRows().get(message.getActionRows().size() - 1);
|
||||
if(lastRow.getComponents().size() < MAX_BUTTONS_PER_ROW) {
|
||||
lastRow.getButtons().add(button);
|
||||
actionRows = message.getActionRows();
|
||||
} else {
|
||||
List<ActionRow> currentActionRows = new ArrayList<>(message.getActionRows());
|
||||
currentActionRows.add(ActionRow.of(button));
|
||||
actionRows = currentActionRows;
|
||||
}
|
||||
return oldComponent;
|
||||
}
|
||||
return messageService.editMessageWithActionRowsMessage(message, actionRows);
|
||||
});
|
||||
return messageService.editMessage(message, tree);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> clearButtons(Message message) {
|
||||
return messageService.editMessageWithActionRows(message, new ArrayList<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> disableAllButtons(Message message) {
|
||||
return setAllButtonStatesTo(message, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> enableAllButtons(Message message) {
|
||||
return setAllButtonStatesTo(message, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> removeComponentWithId(Message message, String componentId) {
|
||||
return removeComponentWithId(message, componentId, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> removeComponentWithId(Message message, String componentId, Boolean rearrange) {
|
||||
List<ActionRow> actionRows = new ArrayList<>();
|
||||
if(Boolean.TRUE.equals(rearrange)) {
|
||||
List<net.dv8tion.jda.api.components.ActionComponent> components = new ArrayList<>();
|
||||
message.getActionRows().forEach(row ->
|
||||
row
|
||||
.getComponents()
|
||||
.stream()
|
||||
.filter(ActionComponent.class::isInstance)
|
||||
.map(ActionComponent.class::cast)
|
||||
.filter(component -> component.getId() == null || !component.getId().equals(componentId))
|
||||
.forEach(components::add));
|
||||
actionRows = splitIntoActionRowsMax(components);
|
||||
} else {
|
||||
for (ActionRow row : message.getActionRows()) {
|
||||
actionRows.add(ActionRow.of(
|
||||
row
|
||||
.getComponents()
|
||||
.stream()
|
||||
.filter(ActionComponent.class::isInstance)
|
||||
.map(ActionComponent.class::cast)
|
||||
.filter(component -> component.getId() == null || !component.getId().equals(componentId))
|
||||
.collect(Collectors.toList())));
|
||||
}
|
||||
}
|
||||
return messageService.editMessageWithActionRows(message, actionRows);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ActionRow> splitIntoActionRowsMax(List<net.dv8tion.jda.api.components.ActionComponent> allComponents) {
|
||||
List<List<net.dv8tion.jda.api.components.ActionComponent>> actionRows = ListUtils.partition(allComponents, MAX_BUTTONS_PER_ROW);
|
||||
return actionRows.stream().map(ActionRow::of).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ButtonConfigModel createButtonConfigModel() {
|
||||
return ButtonConfigModel.builder().buttonId(generateComponentId()).build();
|
||||
}
|
||||
|
||||
private CompletableFuture<Void> setAllButtonStatesTo(Message message, Boolean disabled) {
|
||||
List<ActionRow> actionRows = new ArrayList<>();
|
||||
|
||||
message.getActionRows().forEach(row -> actionRows.add(row.withDisabled(disabled)));
|
||||
return messageService.editMessageWithActionRows(message, actionRows);
|
||||
private CompletableFuture<Message> setAllComponentStatesTo(Message message, Boolean disabled) {
|
||||
MessageComponentTree tree;
|
||||
if(disabled) {
|
||||
tree = message.getComponentTree().asDisabled();
|
||||
} else {
|
||||
tree = message.getComponentTree().asEnabled();
|
||||
}
|
||||
return messageService.editMessage(message, tree);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -94,9 +94,9 @@ public class InteractionServiceBean implements InteractionService {
|
||||
if(!actionRows.isEmpty()) {
|
||||
AServer server = serverManagementService.loadServer(interactionHook.getInteraction().getGuild());
|
||||
allMessageActions.set(0, allMessageActions.get(0).addComponents(actionRows));
|
||||
actionRows.forEach(components -> components.forEach(component -> {
|
||||
actionRows.forEach(components -> components.getComponents().forEach(component -> {
|
||||
if(component instanceof ActionComponent) {
|
||||
String id = ((ActionComponent)component).getId();
|
||||
String id = ((ActionComponent)component).getCustomId();
|
||||
MessageToSend.ComponentConfig payload = messageToSend.getComponentPayloads().get(id);
|
||||
if(payload != null && payload.getPersistCallback()) {
|
||||
componentPayloadManagementService.createPayload(id, payload.getPayload(), payload.getPayloadType(), payload.getComponentOrigin(), server, payload.getComponentType());
|
||||
@@ -228,9 +228,9 @@ public class InteractionServiceBean implements InteractionService {
|
||||
server = serverManagementService.loadServer(serverId);
|
||||
} else {
|
||||
server = null; }
|
||||
actionRows.forEach(components -> components.forEach(component -> {
|
||||
actionRows.forEach(components -> components.getComponents().forEach(component -> {
|
||||
if(component instanceof ActionComponent) {
|
||||
String id = ((ActionComponent)component).getId();
|
||||
String id = ((ActionComponent)component).getCustomId();
|
||||
MessageToSend.ComponentConfig payload = messageToSend.getComponentPayloads().get(id);
|
||||
if(payload != null && payload.getPersistCallback()) {
|
||||
componentPayloadManagementService.createPayload(id, payload.getPayload(), payload.getPayloadType(), payload.getComponentOrigin(), server, payload.getComponentType());
|
||||
@@ -301,9 +301,9 @@ public class InteractionServiceBean implements InteractionService {
|
||||
} else {
|
||||
server = null;
|
||||
}
|
||||
actionRows.forEach(components -> components.forEach(component -> {
|
||||
actionRows.forEach(components -> components.getComponents().forEach(component -> {
|
||||
if(component instanceof ActionComponent) {
|
||||
String id = ((ActionComponent)component).getId();
|
||||
String id = ((ActionComponent)component).getCustomId();
|
||||
MessageToSend.ComponentConfig payload = messageToSend.getComponentPayloads().get(id);
|
||||
if(payload != null && payload.getPersistCallback()) {
|
||||
componentPayloadManagementService.createPayload(id, payload.getPayload(), payload.getPayloadType(), payload.getComponentOrigin(), server, payload.getComponentType());
|
||||
|
||||
@@ -6,12 +6,12 @@ import dev.sheldan.abstracto.core.interaction.modal.config.ModalConfig;
|
||||
import dev.sheldan.abstracto.core.interaction.modal.config.TextInputComponent;
|
||||
import dev.sheldan.abstracto.core.interaction.modal.config.TextInputComponentStyle;
|
||||
import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
||||
import net.dv8tion.jda.api.components.ModalTopLevelComponent;
|
||||
import net.dv8tion.jda.api.components.label.Label;
|
||||
import net.dv8tion.jda.api.events.interaction.command.GenericCommandInteractionEvent;
|
||||
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
|
||||
import net.dv8tion.jda.api.components.actionrow.ActionRow;
|
||||
import net.dv8tion.jda.api.interactions.components.ItemComponent;
|
||||
import net.dv8tion.jda.api.components.textinput.TextInput;
|
||||
import net.dv8tion.jda.api.interactions.modals.Modal;
|
||||
import net.dv8tion.jda.api.modals.Modal;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -55,29 +55,27 @@ public class ModalServiceBean implements ModalService {
|
||||
.build();
|
||||
}
|
||||
|
||||
private List<ActionRow> convertToActionRows(List<ModalComponent> components) {
|
||||
private List<ModalTopLevelComponent> convertToActionRows(List<ModalComponent> components) {
|
||||
return components
|
||||
.stream()
|
||||
.map(this::convertComponent)
|
||||
.map(ActionRow::of)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private ItemComponent convertComponent(ModalComponent component) {
|
||||
private ModalTopLevelComponent convertComponent(ModalComponent component) {
|
||||
if(component instanceof TextInputComponent) {
|
||||
TextInputComponent tic = (TextInputComponent) component;
|
||||
TextInput.Builder builder = TextInput
|
||||
.create(tic.getId(), tic.getLabel(), TextInputComponentStyle.getStyle(tic.getStyle()));
|
||||
TextInput.Builder tiBuilder = TextInput.create(tic.getId(), TextInputComponentStyle.getStyle(tic.getStyle()));
|
||||
if(tic.getMinLength() != null) {
|
||||
builder.setMinLength(tic.getMinLength());
|
||||
tiBuilder.setMinLength(tic.getMinLength());
|
||||
}
|
||||
if(tic.getMaxLength() != null) {
|
||||
builder.setMaxLength(tic.getMaxLength());
|
||||
tiBuilder.setMaxLength(tic.getMaxLength());
|
||||
}
|
||||
if(tic.getRequired() != null) {
|
||||
builder.setRequired(tic.getRequired());
|
||||
tiBuilder.setRequired(tic.getRequired());
|
||||
}
|
||||
return builder.build();
|
||||
return Label.of(tic.getLabel(), tiBuilder.build());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class BotServiceBean implements BotService {
|
||||
@Autowired
|
||||
private OkHttpLogger okHttpLogger;
|
||||
|
||||
@Value("${abstracto.intents:GUILD_VOICE_STATES,GUILD_MODERATION,MESSAGE_CONTENT,GUILD_EMOJIS_AND_STICKERS,GUILD_MEMBERS,GUILD_MESSAGES,GUILD_MESSAGE_REACTIONS,DIRECT_MESSAGES,GUILD_PRESENCES}")
|
||||
@Value("${abstracto.intents:GUILD_VOICE_STATES,GUILD_MODERATION,MESSAGE_CONTENT,GUILD_EXPRESSIONS,GUILD_MEMBERS,GUILD_MESSAGES,GUILD_MESSAGE_REACTIONS,DIRECT_MESSAGES,GUILD_PRESENCES}")
|
||||
private String[] intents;
|
||||
|
||||
@Value("${abstracto.cacheFlags:ACTIVITY,ONLINE_STATUS,VOICE_STATE}")
|
||||
|
||||
@@ -279,9 +279,9 @@ public class ChannelServiceBean implements ChannelService {
|
||||
server = serverManagementService.loadServer(channel.getGuild());
|
||||
}
|
||||
for (ActionRow row : actionRows) {
|
||||
for (ActionRowChildComponent component : row) {
|
||||
for (ActionRowChildComponent component : row.getComponents()) {
|
||||
if (component instanceof ActionComponent) {
|
||||
String id = ((ActionComponent) component).getId();
|
||||
String id = ((ActionComponent) component).getCustomId();
|
||||
MessageToSend.ComponentConfig payload = messageToSend.getComponentPayloads().get(id);
|
||||
if (payload != null && payload.getPersistCallback()) {
|
||||
componentPayloadManagementService.createPayload(id, payload.getPayload(), payload.getPayloadType(), payload.getComponentOrigin(), server, payload.getComponentType());
|
||||
|
||||
@@ -12,11 +12,11 @@ import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.components.tree.MessageComponentTree;
|
||||
import net.dv8tion.jda.api.entities.*;
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.PrivateChannel;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||
import net.dv8tion.jda.api.components.actionrow.ActionRow;
|
||||
import net.dv8tion.jda.api.requests.restaction.AuditableRestAction;
|
||||
import net.dv8tion.jda.api.requests.restaction.MessageEditAction;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -267,14 +267,9 @@ public class MessageServiceBean implements MessageService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> editMessageWithActionRows(Message message, List<ActionRow> rows) {
|
||||
return editMessageWithActionRowsMessage(message, rows).thenApply(message1 -> null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Message> editMessageWithActionRowsMessage(Message message, List<ActionRow> rows) {
|
||||
public CompletableFuture<Message> editMessage(Message message, MessageComponentTree componentTree) {
|
||||
metricService.incrementCounter(MESSAGE_EDIT_METRIC);
|
||||
return message.editMessageComponents(rows).submit();
|
||||
return message.editMessageComponents(componentTree.getComponents()).submit();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -47,6 +47,7 @@ import net.dv8tion.jda.api.components.mediagallery.MediaGalleryItem;
|
||||
import net.dv8tion.jda.api.components.section.Section;
|
||||
import net.dv8tion.jda.api.components.section.SectionAccessoryComponent;
|
||||
import net.dv8tion.jda.api.components.section.SectionContentComponent;
|
||||
import net.dv8tion.jda.api.components.selections.SelectMenu;
|
||||
import net.dv8tion.jda.api.components.separator.Separator;
|
||||
import net.dv8tion.jda.api.components.textdisplay.TextDisplay;
|
||||
import net.dv8tion.jda.api.components.thumbnail.Thumbnail;
|
||||
@@ -54,7 +55,6 @@ import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||
import net.dv8tion.jda.api.entities.channel.ChannelType;
|
||||
import net.dv8tion.jda.api.components.actionrow.ActionRow;
|
||||
import net.dv8tion.jda.api.interactions.components.ItemComponent;
|
||||
import net.dv8tion.jda.api.components.buttons.Button;
|
||||
import net.dv8tion.jda.api.components.selections.EntitySelectMenu;
|
||||
import net.dv8tion.jda.api.components.selections.SelectOption;
|
||||
@@ -449,7 +449,7 @@ public class TemplateServiceBean implements TemplateService {
|
||||
}
|
||||
|
||||
private void addSelectionMenu(List<ActionRow> actionRows, SelectionMenuConfig selectionMenuConfig) {
|
||||
ItemComponent selectionMenu;
|
||||
SelectMenu selectionMenu;
|
||||
if (selectionMenuConfig.getType() == SelectionMenuType.STRING) {
|
||||
List<SelectOption> selectOptions = selectionMenuConfig.getMenuEntries().stream().map(selectionMenuEntry -> {
|
||||
SelectOption option = SelectOption.of(selectionMenuEntry.getLabel(), selectionMenuEntry.getValue());
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.freya022</groupId>
|
||||
<groupId>net.dv8tion</groupId>
|
||||
<artifactId>JDA</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -3,25 +3,20 @@ package dev.sheldan.abstracto.core.interaction;
|
||||
import dev.sheldan.abstracto.core.interaction.button.ButtonConfigModel;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
|
||||
import net.dv8tion.jda.api.components.ActionComponent;
|
||||
import net.dv8tion.jda.api.components.actionrow.ActionRow;
|
||||
import net.dv8tion.jda.api.components.Component;
|
||||
import net.dv8tion.jda.api.components.buttons.ButtonStyle;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public interface ComponentService {
|
||||
|
||||
Integer MAX_BUTTONS_PER_ROW = Component.Type.BUTTON.getMaxPerRow();
|
||||
Integer MAX_BUTTONS_PER_ROW = ActionRow.getMaxAllowed(Component.Type.BUTTON);
|
||||
String generateComponentId(Long serverId);
|
||||
String generateComponentId();
|
||||
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<ActionComponent> components);
|
||||
CompletableFuture<Message> clearComponents(Message message);
|
||||
CompletableFuture<Message> disableAllComponents(Message message);
|
||||
CompletableFuture<Message> enableAllComponents(Message message);
|
||||
CompletableFuture<Message> removeComponentById(Message message, String componentId);
|
||||
ButtonConfigModel createButtonConfigModel();
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@ package dev.sheldan.abstracto.core.interaction.modal;
|
||||
|
||||
import net.dv8tion.jda.api.events.interaction.command.GenericCommandInteractionEvent;
|
||||
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
|
||||
import net.dv8tion.jda.api.interactions.modals.Modal;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import net.dv8tion.jda.api.modals.Modal;
|
||||
|
||||
public interface ModalService {
|
||||
CompletableFuture<Void> replyModal(GenericCommandInteractionEvent event, String templateKey, Object model);
|
||||
|
||||
@@ -6,11 +6,11 @@ import dev.sheldan.abstracto.core.models.cache.CachedMessage;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||
import net.dv8tion.jda.api.components.tree.MessageComponentTree;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||
import net.dv8tion.jda.api.components.actionrow.ActionRow;
|
||||
import net.dv8tion.jda.api.requests.restaction.AuditableRestAction;
|
||||
import net.dv8tion.jda.api.requests.restaction.MessageEditAction;
|
||||
|
||||
@@ -45,7 +45,6 @@ public interface MessageService {
|
||||
MessageEditAction editMessage(Message message, String text, MessageEmbed messageEmbed);
|
||||
AuditableRestAction<Void> deleteMessageWithAction(Message message);
|
||||
CompletableFuture<Void> deleteMessage(Message message);
|
||||
CompletableFuture<Void> editMessageWithActionRows(Message message, List<ActionRow> rows);
|
||||
CompletableFuture<Message> editMessageWithActionRowsMessage(Message message, List<ActionRow> rows);
|
||||
CompletableFuture<Message> editMessage(Message message, MessageComponentTree componentTree);
|
||||
CompletableFuture<Void> pinMessage(Message message);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
|
||||
<properties>
|
||||
<maven.build.timestamp.format>yyyy/MM/dd HH:mm</maven.build.timestamp.format>
|
||||
<jda.version>92f4c2d210</jda.version>
|
||||
<jda.version>6.2.0</jda.version>
|
||||
<asciidoctor.maven.plugin.version>2.2.6</asciidoctor.maven.plugin.version>
|
||||
<asciidoctorj.pdf.version>1.5.3</asciidoctorj.pdf.version>
|
||||
<asciidoctorj.version>2.3.0</asciidoctorj.version>
|
||||
@@ -75,9 +75,11 @@
|
||||
<google-api-client.version>1.31.3</google-api-client.version>
|
||||
<google-api-youtube.version>v3-rev222-1.25.0</google-api-youtube.version>
|
||||
<everit-json-schema.version>1.12.2</everit-json-schema.version>
|
||||
<twitch4j.version>1.15.0</twitch4j.version>
|
||||
<twitch4j.version>1.25.0</twitch4j.version>
|
||||
<!-- required by twitch4j -->
|
||||
<jackson.version>2.15.2</jackson.version>
|
||||
<!-- force upgrade to get compatible okio version, because twitch4j graphql ships old version (we dont use graphql) -->
|
||||
<apollo-runtime.version>4.0.0</apollo-runtime.version>
|
||||
<ehcache.version>3.10.8</ehcache.version>
|
||||
<hibernate-jcache.version>6.2.5.Final</hibernate-jcache.version>
|
||||
<javax-annotation-api.version>1.3.2</javax-annotation-api.version>
|
||||
@@ -154,7 +156,7 @@
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.github.freya022</groupId>
|
||||
<groupId>net.dv8tion</groupId>
|
||||
<artifactId>JDA</artifactId>
|
||||
<version>${jda.version}</version>
|
||||
<exclusions>
|
||||
@@ -186,6 +188,12 @@
|
||||
<version>${twitch4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.apollographql.apollo</groupId>
|
||||
<artifactId>apollo-runtime</artifactId>
|
||||
<version>${apollo-runtime.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
|
||||
Reference in New Issue
Block a user