-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add no longer needed button for weward
- Loading branch information
Showing
2 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...a/rsndiscord/spring/interaction/button/impl/weward/WewardNoLongerNeededButtonHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package fr.rakambda.rsndiscord.spring.interaction.button.impl.weward; | ||
|
||
import fr.rakambda.rsndiscord.spring.interaction.button.api.IExecutableButtonGuild; | ||
import fr.rakambda.rsndiscord.spring.interaction.exception.InvalidChannelTypeException; | ||
import fr.rakambda.rsndiscord.spring.jda.JDAWrappers; | ||
import lombok.extern.slf4j.Slf4j; | ||
import net.dv8tion.jda.api.entities.Guild; | ||
import net.dv8tion.jda.api.entities.Member; | ||
import net.dv8tion.jda.api.entities.channel.ChannelType; | ||
import net.dv8tion.jda.api.entities.emoji.Emoji; | ||
import net.dv8tion.jda.api.interactions.components.ItemComponent; | ||
import net.dv8tion.jda.api.interactions.components.buttons.Button; | ||
import net.dv8tion.jda.api.interactions.components.buttons.ButtonInteraction; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.springframework.stereotype.Component; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.function.Supplier; | ||
|
||
@Slf4j | ||
@Component | ||
public class WewardNoLongerNeededButtonHandler implements IExecutableButtonGuild{ | ||
private static final String COMPONENT_ID = "weward-no-longer-needed"; | ||
private static final ItemComponent[] BUTTONS_ORIGINAL = { | ||
WewardInterestButtonHandler.builder().get(), | ||
WewardDeleteButtonHandler.builder().get() | ||
}; | ||
|
||
@Override | ||
@NotNull | ||
public String getComponentId(){ | ||
return COMPONENT_ID; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public CompletableFuture<?> executeGuild(@NotNull ButtonInteraction event, @NotNull Guild guild, @NotNull Member member) throws InvalidChannelTypeException{ | ||
var channel = event.getChannel(); | ||
|
||
if(event.getChannelType() == ChannelType.GUILD_PUBLIC_THREAD){ | ||
var threadChannel = channel.asThreadChannel(); | ||
return event.deferReply(true).submit() | ||
.thenCompose(empty -> threadChannel.retrieveParentMessage().submit()) | ||
.thenCompose(message -> JDAWrappers.editComponents(message, BUTTONS_ORIGINAL).submit()) | ||
.thenCompose(empty -> JDAWrappers.delete(threadChannel).submit()); | ||
} | ||
|
||
throw new InvalidChannelTypeException(event.getChannelType()); | ||
} | ||
|
||
@NotNull | ||
public static Supplier<Button> builder(){ | ||
return () -> Button.secondary(COMPONENT_ID, "No longer needed").withEmoji(Emoji.fromUnicode("U+1F6D1")); | ||
} | ||
} |