This commit is contained in:
lfirmin
2026-05-02 03:30:08 +02:00
parent 181b8ed454
commit 50af2452b1
3 changed files with 58 additions and 25 deletions
+13 -23
View File
@@ -153,7 +153,7 @@ func (c *PanelComponent) HandleModalSubmit(s *discordgo.Session, i *discordgo.In
}
// b) Webhook impersonation message
postImpersonationMessage(s, ticket, uID, ticketTitle, ticketDescription, parseColor(embedColor), i.GuildID)
postImpersonationMessage(s, ticket, uID, ticketTitle, ticketDescription, i.GuildID)
// c) Claim channel message (includes title + description)
c.ClaimMgr.StartTicket(ctx, s, ticket)
@@ -164,12 +164,12 @@ func (c *PanelComponent) HandleModalSubmit(s *discordgo.Session, i *discordgo.In
}
// postImpersonationMessage creates a temporary webhook on the ticket channel and posts
// the user's title+description as if it came from the user themselves.
func postImpersonationMessage(s *discordgo.Session, ticket *db.Ticket, userID, title, description string, color int, guildID string) {
// the user's title+description as plain text, impersonating the user's avatar and display name.
func postImpersonationMessage(s *discordgo.Session, ticket *db.Ticket, userID, title, description string, guildID string) {
member, err := s.GuildMember(guildID, userID)
if err != nil {
slog.Warn("impersonation: get member", "user_id", userID, "err", err)
postImpersonationFallback(s, ticket.ChannelID, userID, title, description, color)
postImpersonationFallback(s, ticket.ChannelID, userID, title, description)
return
}
user := member.User
@@ -182,24 +182,22 @@ func postImpersonationMessage(s *discordgo.Session, ticket *db.Ticket, userID, t
wh, err := s.WebhookCreate(ticket.ChannelID, "ticket-impersonation", "")
if err != nil {
slog.Warn("impersonation: create webhook", "channel_id", ticket.ChannelID, "err", err)
postImpersonationFallback(s, ticket.ChannelID, userID, title, description, color)
postImpersonationFallback(s, ticket.ChannelID, userID, title, description)
return
}
content := fmt.Sprintf("**%s**\n%s", title, description)
_, execErr := s.WebhookExecute(wh.ID, wh.Token, true, &discordgo.WebhookParams{
Username: displayName,
AvatarURL: avatarURL,
Embeds: []*discordgo.MessageEmbed{
{
Title: title,
Description: description,
Color: color,
},
Content: content,
AllowedMentions: &discordgo.MessageAllowedMentions{
Parse: []discordgo.AllowedMentionType{},
},
})
if execErr != nil {
slog.Warn("impersonation: execute webhook", "err", execErr)
postImpersonationFallback(s, ticket.ChannelID, userID, title, description, color)
postImpersonationFallback(s, ticket.ChannelID, userID, title, description)
}
// Delete webhook — channel delete at close cleans up anyway, but we keep it tidy
@@ -208,15 +206,7 @@ func postImpersonationMessage(s *discordgo.Session, ticket *db.Ticket, userID, t
}
}
func postImpersonationFallback(s *discordgo.Session, channelID, userID, title, description string, color int) {
s.ChannelMessageSendComplex(channelID, &discordgo.MessageSend{ //nolint
Embeds: []*discordgo.MessageEmbed{
{
Title: title,
Description: description,
Color: color,
Author: &discordgo.MessageEmbedAuthor{Name: fmt.Sprintf("Demande de <@%s>", userID)},
},
},
})
func postImpersonationFallback(s *discordgo.Session, channelID, userID, title, description string) {
content := fmt.Sprintf("**%s**\n%s\n*(par <@%s>)*", title, description, userID)
s.ChannelMessageSend(channelID, content) //nolint
}
+2 -2
View File
@@ -174,9 +174,9 @@ func (c *TicketComponent) HandleClaim(s *discordgo.Session, i *discordgo.Interac
}
ticket.Status = "claimed"
// Stop re-up loop and delete claim message
// Stop re-up loop and edit claim message to claimed state
c.ClaimMgr.Stop(ticketID)
c.ClaimMgr.DeleteClaimMessage(ctx, s, ticketID)
c.ClaimMgr.MarkClaimed(ctx, s, ticket, staffID)
// Add staff to ticket channel
if err := c.TicketSvc.AddMember(ctx, ticket.ChannelID, staffID); err != nil {