Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,19 @@ public void onModalSubmitted(ModalInteractionEvent event, List<String> args) {
String authorId = args.get(0);
String messageId = args.get(1);
String channelId = args.get(2);
ForumChannel helperForum = getHelperForum(event.getJDA());
TextChannel sourceChannel = event.getChannel().asTextChannel();

// to avoid race condition, when multiple users do the transfer.
// message is retrieved, already transferred messages are deleted.
event.getChannel()
.retrieveMessageById(messageId)
.queue(notHandled -> transferFlow(event, channelId, authorId, messageId),
handled -> alreadyHandled(sourceChannel, helperForum));
}

private void transferFlow(ModalInteractionEvent event, String channelId, String authorId,
String messageId) {

event.getJDA()
.retrieveUserById(authorId)
Expand All @@ -135,6 +148,13 @@ public void onModalSubmitted(ModalInteractionEvent event, List<String> args) {
.queue();
}

private void alreadyHandled(TextChannel sourceChannel, ForumChannel helperForum) {
sourceChannel.sendMessage(
"The question has been already forwarded to the helper forum for assistance. Kindly review %s for more information."
.formatted(helperForum.getAsMention()))
.queue();
}

private static String createTitle(String message) {
if (message.length() >= TITLE_MAX_LENGTH) {
int lastWordEnd = message.lastIndexOf(' ', TITLE_MAX_LENGTH);
Expand Down