-
-
Notifications
You must be signed in to change notification settings - Fork 96
Introduce Forum Management API #1308
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.togetherjava.tjbot.features.utils; | ||
|
||
import net.dv8tion.jda.api.JDA; | ||
import net.dv8tion.jda.api.entities.channel.concrete.ForumChannel; | ||
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; | ||
import net.dv8tion.jda.api.requests.restaction.ForumPostAction; | ||
import net.dv8tion.jda.api.requests.restaction.MessageCreateAction; | ||
import net.dv8tion.jda.api.utils.messages.MessageCreateData; | ||
|
||
import java.util.*; | ||
|
||
public final class ForumPoster { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (public classes and methods require meaningful/useful JavaDoc in this project) |
||
private final JDA jda; | ||
|
||
private ForumPoster(JDA jda) { | ||
this.jda = jda; | ||
} | ||
|
||
public static ForumPoster using(JDA jda) { | ||
return new ForumPoster(jda); | ||
} | ||
|
||
private ForumChannel findForumChannel(String channelId) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all these |
||
return Optional.ofNullable(jda.getForumChannelById(channelId)) | ||
.orElseThrow(() -> new IllegalArgumentException( | ||
"Did not find a forum channel with ID %s while trying to create a forum post. Make sure the config is setup properly.")); | ||
} | ||
|
||
private ThreadChannel findForumPost(String postId) { | ||
return Optional.ofNullable(jda.getThreadChannelById(postId)) | ||
.orElseThrow(() -> new IllegalArgumentException( | ||
"Did not find the forum post with ID %s while trying to reply to a post.")); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. empty line, can delete |
||
} | ||
Comment on lines
+24
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we want this to throw if not found or return |
||
|
||
public MessageCreateAction sendPost(String postId, MessageCreateData messageData) { | ||
return sendPost(findForumPost(postId), messageData); | ||
} | ||
Comment on lines
+36
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i dont quite understand this. does this reply to a given message? or is |
||
|
||
public MessageCreateAction sendPost(ThreadChannel post, MessageCreateData messageData) { | ||
return post.sendMessage(messageData); | ||
} | ||
|
||
public ForumPostAction createPost(String channelId, String title, MessageCreateData message) { | ||
return createPost(findForumChannel(channelId), title, message); | ||
} | ||
|
||
public ForumPostAction createPost(ForumChannel channel, String title, | ||
MessageCreateData message) { | ||
return channel.createForumPost(title, message); | ||
} | ||
Comment on lines
+40
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. potentially a more convenient API that also aligns more with what JDA already provides and all contributors are used to, would be to create an actual builder. so something where you can do ForumPost.using(jda)
.forum(channel)
.title(title)
.message(messageCreateData)
.post(); given that you need at least one object coming from JDA within this chain, you could even drop the |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i find the name of the class confusing. for quite some time it sounded to me like its referring to a person posting in the forum, i.e.
Poster
being something likeOP
, author of a post.but it is referring to this being an utility to post stuff in forums. i would probably have renamed it to
Forums
, but since the API is builder-like and wants to create instances, a more suitable name is perhapsForumPostBuilder
, also similar to JDAsMessageCreateBuilder
andMessageEditBuilder
that we are all used to.or alternatively
ForumPost
, since its not actually a builder in the classic sense.