Skip to content

fix inability to read embeds in helper threads #915

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

Merged
merged 5 commits into from
Oct 23, 2023
Merged
Changes from all commits
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 @@ -4,6 +4,7 @@
import com.github.benmanes.caffeine.cache.Caffeine;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
import net.dv8tion.jda.api.entities.channel.forums.ForumTag;
Expand All @@ -25,6 +26,7 @@
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
* Listens for new help threads being created. That is, a user posted a question in the help forum.
Expand Down Expand Up @@ -92,7 +94,7 @@ private RestAction<Message> createAIResponse(ThreadChannel threadChannel) {
RestAction<Message> originalQuestion =
threadChannel.retrieveMessageById(threadChannel.getIdLong());
return originalQuestion.flatMap(message -> helper.constructChatGptAttempt(threadChannel,
message.getContentRaw(), componentIdInteractor));
getMessageContent(message), componentIdInteractor));
}

private RestAction<Void> pinOriginalQuestion(ThreadChannel threadChannel) {
Expand Down Expand Up @@ -126,6 +128,17 @@ private RestAction<Message> sendHelperHeadsUp(ThreadChannel threadChannel) {
.flatMap(message -> message.editMessage(headsUpWithRole));
}

private String getMessageContent(Message message) {
if (message.getEmbeds().isEmpty()) {
return message.getContentRaw();
}

return message.getEmbeds()
.stream()
.map(MessageEmbed::getDescription)
.collect(Collectors.joining("\n"));
}

@Override
public String getName() {
return "chatpgt-answer";
Expand Down