Skip to content

Commit f5f9e1e

Browse files
committed
Revert "Move pin notification messages deletion to event listener (#74)"
This reverts commit f660468.
1 parent 88d57eb commit f5f9e1e

2 files changed

Lines changed: 22 additions & 12 deletions

File tree

bot/listeners/message.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"github.com/TicketsBot-cloud/common/sentry"
1313
"github.com/TicketsBot-cloud/database"
1414
"github.com/TicketsBot-cloud/gdl/gateway/payloads/events"
15-
"github.com/TicketsBot-cloud/gdl/objects/channel/message"
1615
"github.com/TicketsBot-cloud/worker"
1716
"github.com/TicketsBot-cloud/worker/bot/dbclient"
1817
"github.com/TicketsBot-cloud/worker/bot/metrics/prometheus"
@@ -46,16 +45,6 @@ func OnMessage(worker *worker.Context, e events.MessageCreate) {
4645
return
4746
}
4847

49-
// Delete pin notification messages in ticket channels
50-
if isTicket && ticket.Id != 0 && e.Type == message.MessageTypeDefault && e.Author.Id == worker.BotId && e.Content == "" && e.MessageReference.MessageId != 0 && !e.Pinned {
51-
sentry.WithSpan0(span.Context(), "Delete pin notification", func(span *sentry.Span) {
52-
if err := worker.DeleteMessage(e.ChannelId, e.Id); err != nil {
53-
sentry.ErrorWithContext(err, utils.MessageCreateErrorContext(e))
54-
}
55-
})
56-
return
57-
}
58-
5948
// ensure valid ticket channel
6049
if !isTicket || ticket.Id == 0 {
6150
return

bot/logic/open.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,28 @@ func OpenTicket(ctx context.Context, cmd registry.InteractionContext, panel *dat
636636
span = sentry.StartSpan(rootSpan.Context(), "Pin welcome message")
637637
channelId := *ticket.ChannelId
638638

639-
_ = cmd.Worker().AddPinnedChannelMessage(channelId, welcomeMessageId)
639+
if err := cmd.Worker().AddPinnedChannelMessage(channelId, welcomeMessageId); err == nil {
640+
// Delete the system pin notification message
641+
span2 := sentry.StartSpan(rootSpan.Context(), "Delete pin notification")
642+
643+
// Fetch recent messages to find the system pin notification
644+
messages, err := cmd.Worker().GetChannelMessages(channelId, rest.GetChannelMessagesData{
645+
Limit: 3,
646+
})
647+
648+
if err == nil {
649+
// Find and delete the system pin notification message
650+
for _, msg := range messages {
651+
// Pin notification has MessageReference pointing to the pinned message, but is not the pinned message itself
652+
if msg.MessageReference.MessageId == welcomeMessageId && msg.Id != welcomeMessageId {
653+
_ = cmd.Worker().DeleteMessage(channelId, msg.Id)
654+
break
655+
}
656+
}
657+
}
658+
659+
span2.Finish()
660+
}
640661
span.Finish()
641662
}
642663

0 commit comments

Comments
 (0)