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

feat: stickies for forum posts which get posted on forum post create #384

Merged
merged 5 commits into from
Dec 19, 2022

Conversation

pdellaert
Copy link
Collaborator

@pdellaert pdellaert commented Nov 27, 2022

feat: stickies for forum posts which get posted on forum post create

TL;DR

With the introduction of Forum Channels, there is a need for an automated message posted by the bot every time someone creates a new post. This is especially important for Support channels.

This PR introduces the possibility to configure a message for a Forum Channel that will get posted every time a Forum Post is created.

See the Video in Test Evidence for a breakdown

Description

Use Case & Requirements

With the introduction of Forum Channels, there is a need for an automated message posted by the bot every time someone creates a new post. This is especially important for Support channels.

Summary of requirements:

  • Manage a (single) message per channel that gets posted in every new Forum Post created in that channel.
  • The message can contain multiple lines
  • The message can contain basic markdown (bold, italic, underline, lists, links, emojis, ...)
  • The message can contain an external image
  • It must be possible to update and delete a message
  • It must be possible to get information of the configuration per channel

Solution

Instead of making a new type of message that is stored in the database, the ongoing work for stickies is re-used for this requirements.

In general, stickies are messages, configured per channel (one per channel) that get posted to the channel whenever certain conditions are met. They only get posted to the channel if a new message is posted by a user, and only when the sticky hasn't been posted in the last amount of or .

In this case, the sticky should not be posted on activity in the Forum Post, but only once on the creation of the Forum Post. Everything else is the same: The message is customizable and needs to be configured for the Forum Channel.

Implementation

Discord.js version

Because this change has to manage Forum Channels, a new version of discord.js (14.3.0+) is needed, as the currently used version (14.0.3) does not support Forum Channels (ForumChannel).

This PR has an updated package-lock.json file which only has discord.js and its dependencies updated by doing an npm update discord.js.

Forum Channels and Forum Posts

ForumChannels are in essence similar to TextChannels, with the difference that you can't post message to them directly.

However, Forum Posts are nothing more than regular Discord Threads (ThreadChannel). The only difference between a regular TextChannel thread and ForumChannel thread is that the parent of the ThreadChannel refers to a ForumChannel.

Sticky DB Object

A new database object has been added to introduce a sticky message. It contains the following properties:

  • channelId: Contains the channel to which the message belongs. A channel can only contain a single message, so it is set to be unique.
  • message: The actual message content
  • imageUrl: An optional URL to an image which will be included in the sticky message
  • timeInterval: Indicates the minimum time that has to have passed before a sticky can be posted again (This is not used in the Forum Post message as it only posts it on Forum Post Creation)
  • messageCount: Indicates the minimum amount of posts that have to be posted in the channel before a sticky can be posted again (This is not used in the Forum Post message as it only posts it on Forum Post Creation)
  • moderator: The moderator that last made a change to the sticky
  • updatedTimestamp: The last time the sticky was updated
  • lastPostedId: The ID of the message when the sticky was last posted. (This is not used in the Forum Post message as it only posts it on Forum Post Creation)

Sticky Management command (.sticky)

To manage stickies, a new command is introduced which can be executed with the .sticky command.

This command has the following help:

Screen Shot 2022-11-26 at 9 02 11 PM

It has the following sub-commands.
For all sub-commands, a channel id can optionally be provided. If it is not provided, the channel in which the .sticky command is executed is used as the channel to manage.

  • set: Configure the sticky message for a channel
  • image: Configure an image for a channel
  • count: Configure the minimum message count
  • time: Configure the minimum time interval (This is not relevant in the Forum Post message as it only posts it on Forum Post Creation)
  • unset: Delete the sticky message for a channel (This is not relevant in the Forum Post message as it only posts it on Forum Post Creation)
  • info: Shows information about the sticky for a channel

Thread Create handler (Forum Post Handler)

A new handler is introduced that is executed whenever a new ThreadChannel is created.

This handler will first check if the ThreadChannel is actually a Forum Post by checking if the parent of the thread is of the type GUILD_FORUM.

If so, it will check if there's a sticky for that parent configured and post it to the Forum Post.

Note: There is no real stickies handler yet, which would be on the messageCreate event, but this code is ready & tested in another branch. It will be implemented once the bots are split and a separate Sticky bot exists. This thread create handler will also move to the sticky bot.

Test Results

FBW Discord Bot - Respond on Forum Post Create

Discord Username

straks#7240

@pdellaert pdellaert force-pushed the stickies_forum-channels branch from 63264a3 to 5381c03 Compare December 10, 2022 19:25
@pdellaert pdellaert force-pushed the stickies_forum-channels branch from 5381c03 to 0f3a0ad Compare December 14, 2022 06:06
@benw202 benw202 merged commit 001c0eb into flybywiresim:staging Dec 19, 2022
@pdellaert pdellaert deleted the stickies_forum-channels branch December 19, 2022 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants