@@ -26,8 +26,8 @@ import (
2626const freePanelLimit = 3
2727
2828type panelBody struct {
29- ChannelId uint64 `json:"channel_id,string"`
30- MessageId uint64 `json:"message_id,string"`
29+ ChannelId * uint64 `json:"channel_id,string"`
30+ MessageId * uint64 `json:"message_id,string"`
3131 Title string `json:"title"`
3232 Content string `json:"content"`
3333 Colour uint32 `json:"colour"`
@@ -52,9 +52,13 @@ type panelBody struct {
5252 UseThreads bool `json:"use_threads"`
5353}
5454
55- func (p * panelBody ) IntoPanelMessageData (customId string , isPremium bool ) panelMessageData {
56- return panelMessageData {
57- ChannelId : p .ChannelId ,
55+ func (p * panelBody ) IntoPanelMessageData (customId string , isPremium bool ) * panelMessageData {
56+ if p .ChannelId == nil {
57+ // This should never happen due to earlier validation
58+ return nil
59+ }
60+ return & panelMessageData {
61+ ChannelId : * p .ChannelId ,
5862 Title : p .Title ,
5963 Content : p .Content ,
6064 CustomId : customId ,
@@ -87,7 +91,7 @@ func CreatePanel(c *gin.Context) {
8791 return
8892 }
8993
90- data .MessageId = 0
94+ data .MessageId = nil
9195
9296 // Check panel quota
9397 premiumTier , err := rpc .PremiumClient .GetTierByGuildId (c , guildId , false , botContext .Token , botContext .RateLimiter )
@@ -168,20 +172,24 @@ func CreatePanel(c *gin.Context) {
168172 }
169173
170174 messageData := data .IntoPanelMessageData (customId , premiumTier > premium .None )
171- msgId , err := messageData .send (botContext )
172- if err != nil {
173- var unwrapped request.RestError
174- if errors .As (err , & unwrapped ) {
175- if unwrapped .StatusCode == http .StatusForbidden {
176- c .JSON (400 , utils .ErrorStr ("Bot does not have permission to send messages in channel %d" , data .ChannelId ))
175+ var newMsgId * uint64
176+ if data .MessageId != nil {
177+ msgId , err := messageData .send (botContext )
178+ if err != nil {
179+ var unwrapped request.RestError
180+ if errors .As (err , & unwrapped ) {
181+ if unwrapped .StatusCode == http .StatusForbidden {
182+ c .JSON (400 , utils .ErrorStr ("Bot does not have permission to send messages in channel %d" , data .ChannelId ))
183+ } else {
184+ c .JSON (400 , utils .ErrorStr ("Failed to send panel message to channel %d: %s" , data .ChannelId , unwrapped .ApiError .Message ))
185+ }
177186 } else {
178- c . JSON ( 400 , utils . ErrorStr ( "Failed to send panel message to channel %d: %s" , data . ChannelId , unwrapped . ApiError . Message ))
187+ _ = c . AbortWithError ( http . StatusInternalServerError , app . NewError ( err , "Failed to send panel message to Discord" ))
179188 }
180- } else {
181- _ = c .AbortWithError (http .StatusInternalServerError , app .NewError (err , "Failed to send panel message to Discord" ))
182- }
183189
184- return
190+ return
191+ }
192+ newMsgId = & msgId
185193 }
186194
187195 var emojiId * uint64
@@ -214,7 +222,7 @@ func CreatePanel(c *gin.Context) {
214222
215223 // Store in DB
216224 panel := database.Panel {
217- MessageId : msgId ,
225+ MessageId : newMsgId ,
218226 ChannelId : data .ChannelId ,
219227 GuildId : guildId ,
220228 Title : data .Title ,
0 commit comments