v0.2.1
This commit is contained in:
@@ -70,6 +70,49 @@ func (m *Manager) DeleteClaimMessage(ctx context.Context, s *discordgo.Session,
|
|||||||
m.claims.Delete(ctx, ticketID) //nolint
|
m.claims.Delete(ctx, ticketID) //nolint
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MarkClaimed edits the claim channel message to show the claimed state (green embed, no button,
|
||||||
|
// no ping) and removes it from tracking so the close flow leaves it untouched.
|
||||||
|
func (m *Manager) MarkClaimed(ctx context.Context, s *discordgo.Session, ticket *db.Ticket, staffID string) {
|
||||||
|
cm, err := m.claims.Get(ctx, ticket.ID)
|
||||||
|
if err != nil || cm == nil {
|
||||||
|
m.claims.Delete(ctx, ticket.ID) //nolint
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cfg := m.cfg.Get()
|
||||||
|
claimChannelID := cfg.Bot.ClaimChannel
|
||||||
|
if claimChannelID == "" {
|
||||||
|
m.claims.Delete(ctx, ticket.ID) //nolint
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
claimedEmbed := &discordgo.MessageEmbed{
|
||||||
|
Title: "Ticket pris en charge",
|
||||||
|
Color: 0x57f287,
|
||||||
|
Fields: []*discordgo.MessageEmbedField{
|
||||||
|
{Name: "Numéro", Value: fmt.Sprintf("#%04d", ticket.TicketNumber), Inline: true},
|
||||||
|
{Name: "Type", Value: ticket.Type, Inline: true},
|
||||||
|
{Name: "Auteur", Value: fmt.Sprintf("<@%s>", ticket.UserID), Inline: true},
|
||||||
|
{Name: "Pris par", Value: fmt.Sprintf("<@%s>", staffID), Inline: true},
|
||||||
|
{Name: "Salon", Value: fmt.Sprintf("<#%s>", ticket.ChannelID), Inline: true},
|
||||||
|
},
|
||||||
|
Timestamp: time.Now().UTC().Format(time.RFC3339),
|
||||||
|
}
|
||||||
|
|
||||||
|
content := ""
|
||||||
|
emptyComponents := []discordgo.MessageComponent{}
|
||||||
|
if _, editErr := s.ChannelMessageEditComplex(&discordgo.MessageEdit{
|
||||||
|
Channel: claimChannelID,
|
||||||
|
ID: cm.MessageID,
|
||||||
|
Content: &content,
|
||||||
|
Embeds: &[]*discordgo.MessageEmbed{claimedEmbed},
|
||||||
|
Components: &emptyComponents,
|
||||||
|
}); editErr != nil {
|
||||||
|
slog.Warn("claim: edit message to claimed", "ticket_id", ticket.ID, "err", editErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
m.claims.Delete(ctx, ticket.ID) //nolint
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Manager) startReupLoop(s *discordgo.Session, ticket *db.Ticket, lastReupAt time.Time) {
|
func (m *Manager) startReupLoop(s *discordgo.Session, ticket *db.Ticket, lastReupAt time.Time) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
m.mu.Lock()
|
m.mu.Lock()
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ func (c *PanelComponent) HandleModalSubmit(s *discordgo.Session, i *discordgo.In
|
|||||||
}
|
}
|
||||||
|
|
||||||
// b) Webhook impersonation message
|
// 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) Claim channel message (includes title + description)
|
||||||
c.ClaimMgr.StartTicket(ctx, s, ticket)
|
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
|
// postImpersonationMessage creates a temporary webhook on the ticket channel and posts
|
||||||
// the user's title+description as if it came from the user themselves.
|
// 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, color int, guildID string) {
|
func postImpersonationMessage(s *discordgo.Session, ticket *db.Ticket, userID, title, description string, guildID string) {
|
||||||
member, err := s.GuildMember(guildID, userID)
|
member, err := s.GuildMember(guildID, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Warn("impersonation: get member", "user_id", userID, "err", err)
|
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
|
return
|
||||||
}
|
}
|
||||||
user := member.User
|
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", "")
|
wh, err := s.WebhookCreate(ticket.ChannelID, "ticket-impersonation", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Warn("impersonation: create webhook", "channel_id", ticket.ChannelID, "err", err)
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
content := fmt.Sprintf("**%s**\n%s", title, description)
|
||||||
_, execErr := s.WebhookExecute(wh.ID, wh.Token, true, &discordgo.WebhookParams{
|
_, execErr := s.WebhookExecute(wh.ID, wh.Token, true, &discordgo.WebhookParams{
|
||||||
Username: displayName,
|
Username: displayName,
|
||||||
AvatarURL: avatarURL,
|
AvatarURL: avatarURL,
|
||||||
Embeds: []*discordgo.MessageEmbed{
|
Content: content,
|
||||||
{
|
AllowedMentions: &discordgo.MessageAllowedMentions{
|
||||||
Title: title,
|
Parse: []discordgo.AllowedMentionType{},
|
||||||
Description: description,
|
|
||||||
Color: color,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if execErr != nil {
|
if execErr != nil {
|
||||||
slog.Warn("impersonation: execute webhook", "err", execErr)
|
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
|
// 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) {
|
func postImpersonationFallback(s *discordgo.Session, channelID, userID, title, description string) {
|
||||||
s.ChannelMessageSendComplex(channelID, &discordgo.MessageSend{ //nolint
|
content := fmt.Sprintf("**%s**\n%s\n*(par <@%s>)*", title, description, userID)
|
||||||
Embeds: []*discordgo.MessageEmbed{
|
s.ChannelMessageSend(channelID, content) //nolint
|
||||||
{
|
|
||||||
Title: title,
|
|
||||||
Description: description,
|
|
||||||
Color: color,
|
|
||||||
Author: &discordgo.MessageEmbedAuthor{Name: fmt.Sprintf("Demande de <@%s>", userID)},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -174,9 +174,9 @@ func (c *TicketComponent) HandleClaim(s *discordgo.Session, i *discordgo.Interac
|
|||||||
}
|
}
|
||||||
ticket.Status = "claimed"
|
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.Stop(ticketID)
|
||||||
c.ClaimMgr.DeleteClaimMessage(ctx, s, ticketID)
|
c.ClaimMgr.MarkClaimed(ctx, s, ticket, staffID)
|
||||||
|
|
||||||
// Add staff to ticket channel
|
// Add staff to ticket channel
|
||||||
if err := c.TicketSvc.AddMember(ctx, ticket.ChannelID, staffID); err != nil {
|
if err := c.TicketSvc.AddMember(ctx, ticket.ChannelID, staffID); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user