Skip to content

Commit f219060

Browse files
authored
RM-250: Fix join ticket does not update for per panel thread mode (#130)
RM-250: Fix join Ticket does not update for per panel thread mode Prefer a panel's TicketNotificationChannel over the guild default when updating thread join/notification messages. Update SwitchPanelCommand and thread members listener to choose the correct notification channel and only attempt message edits when a channel is set. Remove the join-message update logic and unused imports from the join-thread button handler. This avoids nil channel edits and centralizes notification channel selection.
1 parent 05c9790 commit f219060

3 files changed

Lines changed: 27 additions & 50 deletions

File tree

bot/button/handlers/jointhread.go

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@ import (
77
"strings"
88
"time"
99

10-
"github.com/TicketsBot-cloud/common/sentry"
11-
"github.com/TicketsBot-cloud/database"
1210
"github.com/TicketsBot-cloud/worker/bot/button/registry"
1311
"github.com/TicketsBot-cloud/worker/bot/button/registry/matcher"
1412
"github.com/TicketsBot-cloud/worker/bot/command/context"
1513
"github.com/TicketsBot-cloud/worker/bot/customisation"
1614
"github.com/TicketsBot-cloud/worker/bot/dbclient"
17-
"github.com/TicketsBot-cloud/worker/bot/errorcontext"
1815
"github.com/TicketsBot-cloud/worker/bot/logic"
1916
"github.com/TicketsBot-cloud/worker/i18n"
2017
)
@@ -96,41 +93,5 @@ func (h *JoinThreadHandler) Execute(ctx *context.ButtonContext) {
9693
return
9794
}
9895

99-
// Update ticket's member count
100-
if ticket.JoinMessageId != nil {
101-
var panel *database.Panel
102-
if ticket.PanelId != nil {
103-
tmp, err := dbclient.Client.Panel.GetById(ctx, *ticket.PanelId)
104-
if err != nil {
105-
ctx.HandleError(err)
106-
return
107-
}
108-
109-
if tmp.PanelId != 0 && ctx.GuildId() == tmp.GuildId {
110-
panel = &tmp
111-
}
112-
}
113-
114-
threadStaff, err := logic.GetStaffInThread(ctx, ctx.Worker(), ticket, *ticket.ChannelId)
115-
if err != nil {
116-
ctx.HandleError(err)
117-
return
118-
}
119-
120-
settings, err := dbclient.Client.Settings.Get(ctx, ctx.GuildId())
121-
if err != nil {
122-
ctx.HandleError(err)
123-
return
124-
}
125-
126-
if settings.TicketNotificationChannel != nil {
127-
name, _ := logic.GenerateChannelName(ctx, ctx.Worker(), panel, ticket.GuildId, ticket.Id, ticket.UserId, nil)
128-
data := logic.BuildJoinThreadMessage(ctx, ctx.Worker(), ticket.GuildId, ticket.UserId, name, ticket.Id, panel, threadStaff, ctx.PremiumTier())
129-
if _, err := ctx.Worker().EditMessage(*settings.TicketNotificationChannel, *ticket.JoinMessageId, data.IntoEditMessageData()); err != nil {
130-
sentry.ErrorWithContext(err, errorcontext.WorkerErrorContext{Guild: ctx.GuildId()})
131-
}
132-
}
133-
}
134-
13596
ctx.Reply(customisation.Green, i18n.Success, i18n.MessageJoinThreadSuccess, *ticket.ChannelId)
13697
}

bot/command/impl/tickets/switchpanel.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,17 +243,26 @@ func (SwitchPanelCommand) Execute(ctx *cmdcontext.SlashCommandContext, panelId i
243243
ctx.ReplyRaw(customisation.Green, "Success", fmt.Sprintf("This ticket has been switched to the panel **%s**.\n\nNote: As this is a thread, the permissions could not be bulk updated.", newPanel.Title))
244244

245245
// Modify join message
246-
if ticket.JoinMessageId != nil && settings.TicketNotificationChannel != nil {
247-
threadStaff, err := logic.GetStaffInThread(ctx.Context, ctx.Worker(), ticket, *ticket.ChannelId)
248-
if err != nil {
249-
sentry.ErrorWithContext(err, ctx.ToErrorContext()) // Only log
250-
return
246+
if ticket.JoinMessageId != nil {
247+
var notificationChannel *uint64
248+
if newPanel.TicketNotificationChannel != nil {
249+
notificationChannel = newPanel.TicketNotificationChannel
250+
} else if settings.TicketNotificationChannel != nil {
251+
notificationChannel = settings.TicketNotificationChannel
251252
}
252253

253-
msg := logic.BuildJoinThreadMessage(ctx.Context, ctx.Worker(), ctx.GuildId(), ticket.UserId, newChannelName, ticket.Id, &newPanel, threadStaff, ctx.PremiumTier())
254-
if _, err := ctx.Worker().EditMessage(*settings.TicketNotificationChannel, *ticket.JoinMessageId, msg.IntoEditMessageData()); err != nil {
255-
sentry.ErrorWithContext(err, ctx.ToErrorContext()) // Only log
256-
return
254+
if notificationChannel != nil {
255+
threadStaff, err := logic.GetStaffInThread(ctx.Context, ctx.Worker(), ticket, *ticket.ChannelId)
256+
if err != nil {
257+
sentry.ErrorWithContext(err, ctx.ToErrorContext()) // Only log
258+
return
259+
}
260+
261+
msg := logic.BuildJoinThreadMessage(ctx.Context, ctx.Worker(), ctx.GuildId(), ticket.UserId, newChannelName, ticket.Id, &newPanel, threadStaff, ctx.PremiumTier())
262+
if _, err := ctx.Worker().EditMessage(*notificationChannel, *ticket.JoinMessageId, msg.IntoEditMessageData()); err != nil {
263+
sentry.ErrorWithContext(err, ctx.ToErrorContext()) // Only log
264+
return
265+
}
257266
}
258267
}
259268

bot/listeners/threadmembersupdate.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,17 @@ func OnThreadMembersUpdate(worker *worker.Context, e events.ThreadMembersUpdate)
6060
return
6161
}
6262

63-
if settings.TicketNotificationChannel != nil {
63+
var notificationChannel *uint64
64+
if panel != nil && panel.TicketNotificationChannel != nil {
65+
notificationChannel = panel.TicketNotificationChannel
66+
} else if settings.TicketNotificationChannel != nil {
67+
notificationChannel = settings.TicketNotificationChannel
68+
}
69+
70+
if notificationChannel != nil {
6471
name, _ := logic.GenerateChannelName(ctx, worker, panel, ticket.GuildId, ticket.Id, ticket.UserId, nil)
6572
data := logic.BuildJoinThreadMessage(ctx, worker, ticket.GuildId, ticket.UserId, name, ticket.Id, panel, threadStaff, premiumTier)
66-
if _, err := worker.EditMessage(*settings.TicketNotificationChannel, *ticket.JoinMessageId, data.IntoEditMessageData()); err != nil {
73+
if _, err := worker.EditMessage(*notificationChannel, *ticket.JoinMessageId, data.IntoEditMessageData()); err != nil {
6774
sentry.ErrorWithContext(err, errorcontext.WorkerErrorContext{Guild: e.GuildId})
6875
}
6976
}

0 commit comments

Comments
 (0)