Skip to content

Decouple forum post creation from TransferQuestionCommand into a more accessible space #1307

@discorddioxin

Description

@discorddioxin

Motivation

Forum Channels are common on Discord. By having a centralized API to perform forum actions, developers would be more encouraged to make use of forum posting for bot actions. The API could be scaled to include utility which eases the use of forums in code, as well as to help ease migration-based breakage.

This new Forum Posting API will start extremely lightweight & streamlined, but could be used as a foundation for improvement (such as acting as a facade for complex forum-based operations)

Goals

  • Allow access to a forum post creation system, which currently lives in TransferQuestionCommand
  • Centralize forum posting, allowing for cross-cutting management over forums (JDA API breakage, styling, etc..)

Risks and Assumptions

  • Increasing visibility of an API can bloat the API of the code base
  • Any changes to a code base could encounter problems if not properly assessed/tested

Alternatives

  • Use non-forum based channels for bot posting
  • Manually write-out the forum post creation code each time forum post creation needed

Potential Usage

Creating a new post

var forumChannel = ...; // could use channel or channelId (in String form)
var forumTitle = "My First Post";
var messageData = MessageCreateData.fromContent("Hello world!");

ForumPoster.using(jda)
    .createPost(forumChannel, forumTitle, messageData)
    .setTags(...) // access to ForumPostAction methods
    .addFiles(...)
    .queue();

Sending a message to a forum thread

var threadChannel = ...; // could use channel or channelId (in String form)
var messageData = MessageCreateData.fromContent("How's it going?");

ForumPoster.using(jda)
    .sendPost(threadChannel, messageData)
    .addFiles(...)  // access to MessageCreateAction methods
    .queue();

Usage in TransferQuestionCommand (Low Impact)

From

        return questionsForum.createForumPost(forumTitle, forumMessage)
            .setTags(ForumTagSnowflake.fromId(tag.getId()))
            .map(createdPost -> new ForumPostData(createdPost, originalUser));

To

        return ForumPoster.using(jda).createPost(forumTitle, forumMessage)
            .setTags(ForumTagSnowflake.fromId(tag.getId()))
            .map(createdPost -> new ForumPostData(createdPost, originalUser));

API Benefits

This API, in it's current state, won't prevent all breakage of forum posting. The benefits exist in it's ability to be scaled to mitigate breakage during migration, as well as provide an easy-to-use/hard-to-misuse interface for developers to use.

Code Breakage Mitigation

Migrations typically lead to breaking changes. JDA is known for moving packages around between versions.

By having developers rely on our API, there won't be worry about updating code they've pushed to production. Instead, only the forum posting API would need to be updated. It would reduce the worry about introducing forum-based features into the server.

var id = ...;
var title = ...;
MessageCreateData messageData = ...;

ForumPoster.using(jda).createPost(id, title, messageData);

Details such as ForumChannel, ForumPostAction, etc.. are hidden from the user. If JDA decides to move them, any code involved in making forum posts would not have to be updated - only the API responsible for forum posts.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions