Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions bot/listeners/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/TicketsBot-cloud/common/sentry"
"github.com/TicketsBot-cloud/database"
"github.com/TicketsBot-cloud/gdl/gateway/payloads/events"
"github.com/TicketsBot-cloud/gdl/objects/channel/message"
"github.com/TicketsBot-cloud/worker"
"github.com/TicketsBot-cloud/worker/bot/dbclient"
"github.com/TicketsBot-cloud/worker/bot/metrics/prometheus"
Expand Down Expand Up @@ -45,6 +46,16 @@ func OnMessage(worker *worker.Context, e events.MessageCreate) {
return
}

// Delete pin notification messages in ticket channels
if isTicket && ticket.Id != 0 && e.Type == message.MessageTypeDefault && e.Author.Id == worker.BotId && e.Content == "" && e.MessageReference.MessageId != 0 && !e.Pinned {
sentry.WithSpan0(span.Context(), "Delete pin notification", func(span *sentry.Span) {
if err := worker.DeleteMessage(e.ChannelId, e.Id); err != nil {
sentry.ErrorWithContext(err, utils.MessageCreateErrorContext(e))
}
})
return
}

// ensure valid ticket channel
if !isTicket || ticket.Id == 0 {
return
Expand Down
23 changes: 1 addition & 22 deletions bot/logic/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,28 +636,7 @@ func OpenTicket(ctx context.Context, cmd registry.InteractionContext, panel *dat
span = sentry.StartSpan(rootSpan.Context(), "Pin welcome message")
channelId := *ticket.ChannelId

if err := cmd.Worker().AddPinnedChannelMessage(channelId, welcomeMessageId); err == nil {
// Delete the system pin notification message
span2 := sentry.StartSpan(rootSpan.Context(), "Delete pin notification")

// Fetch recent messages to find the system pin notification
messages, err := cmd.Worker().GetChannelMessages(channelId, rest.GetChannelMessagesData{
Limit: 3,
})

if err == nil {
// Find and delete the system pin notification message
for _, msg := range messages {
// Pin notification has MessageReference pointing to the pinned message, but is not the pinned message itself
if msg.MessageReference.MessageId == welcomeMessageId && msg.Id != welcomeMessageId {
_ = cmd.Worker().DeleteMessage(channelId, msg.Id)
break
}
}
}

span2.Finish()
}
_ = cmd.Worker().AddPinnedChannelMessage(channelId, welcomeMessageId)
span.Finish()
}

Expand Down