Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor onModalSubmit in TransferQuestionCommand to handle multiple users submission #955

Merged
merged 4 commits into from
Nov 20, 2023
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));
Zabuzard marked this conversation as resolved.
Show resolved Hide resolved
}

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."
Zabuzard marked this conversation as resolved.
Show resolved Hide resolved
.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
Loading