fix(discord): require thread ID for forum channels to prevent broadcast#522
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request introduces a guard in the Discord broker's Publish method to prevent sending messages directly to forum and media channels without a thread ID, returning an error instead. It also adds a helper method isForumChannel to identify these channel types and includes comprehensive unit tests. Feedback was provided to add a nil check on the channel object returned from the Discord session API call to prevent a potential nil pointer dereference panic.
| ch, err = session.Channel(channelID) | ||
| if err != nil { | ||
| return false | ||
| } |
There was a problem hiding this comment.
To prevent a potential nil pointer dereference panic, defensively check if ch is nil after calling session.Channel(channelID) before accessing ch.Type.
| ch, err = session.Channel(channelID) | |
| if err != nil { | |
| return false | |
| } | |
| ch, err = session.Channel(channelID) | |
| if err != nil || ch == nil { | |
| return false | |
| } |
Discord forum (type 15) and media (type 16) channels are thread-only containers that cannot receive messages directly. When a message was routed to one of these channels without a thread ID, the broker would attempt to send to the container channel itself, which could broadcast unintentionally. Now the Publish method detects forum/media channel targets and returns a clear error asking the caller to specify a thread ID. Also fixes an incorrect comment that labeled GuildNewsThread as type 15 (it is type 10; type 15 is GuildForum). Closes #290
After calling session.Channel(channelID), ch could be nil even without an error. Add nil check to prevent panic when accessing ch.Type.
257e6f4 to
7f85e68
Compare
Fixes : Discord forum channels were broadcasting messages to all threads when thread ID was omitted. Now validates channel type and requires thread ID for forum channels.