[AB-xxx] upgrading to JDA 6.2.0

changing how assignable role places change their buttons
This commit is contained in:
Sheldan
2025-12-28 19:17:58 +01:00
parent cf9e5f67f6
commit 4180a07243
24 changed files with 117 additions and 173 deletions

View File

@@ -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

View File

@@ -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));
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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()));

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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>