v0.2
This commit is contained in:
+53
-18
@@ -29,9 +29,9 @@ func NewManager(cfg *config.Provider, repo *db.TicketRepo, claims *db.ClaimMessa
|
||||
}
|
||||
}
|
||||
|
||||
// StartTicket posts the initial claim message and starts the re-up goroutine.
|
||||
// StartTicket posts the initial claim message (with staff ping) and starts the re-up goroutine.
|
||||
func (m *Manager) StartTicket(ctx context.Context, s *discordgo.Session, ticket *db.Ticket) {
|
||||
msgID, err := m.postClaim(ctx, s, ticket, false)
|
||||
msgID, err := m.postClaim(ctx, s, ticket, true)
|
||||
if err != nil {
|
||||
slog.Error("claim: post initial message", "ticket_id", ticket.ID, "err", err)
|
||||
} else {
|
||||
@@ -146,18 +146,41 @@ func (m *Manager) postClaim(ctx context.Context, s *discordgo.Session, ticket *d
|
||||
return "", fmt.Errorf("claim_channel not configured")
|
||||
}
|
||||
|
||||
elapsed := time.Since(ticket.OpenedAt).Round(time.Second)
|
||||
// Determine embed color from type config, fallback to blurple
|
||||
embedColor := 0x5865f2
|
||||
var staffRoleID string
|
||||
if panel, ok := cfg.Panels[ticket.Panel]; ok {
|
||||
if t, ok := panel.Types[ticket.Type]; ok {
|
||||
if c := parseHexColor(t.EmbedColor); c != 0 {
|
||||
embedColor = c
|
||||
}
|
||||
staffRoleID = t.StaffRole
|
||||
}
|
||||
}
|
||||
|
||||
fields := []*discordgo.MessageEmbedField{
|
||||
{Name: "Auteur", Value: fmt.Sprintf("<@%s>", ticket.UserID), Inline: true},
|
||||
{Name: "Numéro", Value: fmt.Sprintf("#%04d", ticket.TicketNumber), Inline: true},
|
||||
{Name: "Salon", Value: fmt.Sprintf("<#%s>", ticket.ChannelID), Inline: true},
|
||||
}
|
||||
|
||||
if ticket.TicketTitle.Valid && ticket.TicketTitle.String != "" {
|
||||
fields = append(fields, &discordgo.MessageEmbedField{Name: "Titre", Value: ticket.TicketTitle.String, Inline: false})
|
||||
}
|
||||
if ticket.TicketDescription.Valid && ticket.TicketDescription.String != "" {
|
||||
desc := ticket.TicketDescription.String
|
||||
if len([]rune(desc)) > 500 {
|
||||
runes := []rune(desc)
|
||||
desc = string(runes[:497]) + "..."
|
||||
}
|
||||
fields = append(fields, &discordgo.MessageEmbedField{Name: "Description", Value: desc, Inline: false})
|
||||
}
|
||||
|
||||
embed := &discordgo.MessageEmbed{
|
||||
Title: "Nouveau ticket à claim",
|
||||
Color: 0x5865f2,
|
||||
Fields: []*discordgo.MessageEmbedField{
|
||||
{Name: "Type", Value: ticket.Type, Inline: true},
|
||||
{Name: "Panel", Value: ticket.Panel, Inline: true},
|
||||
{Name: "Utilisateur", Value: fmt.Sprintf("<@%s>", ticket.UserID), Inline: true},
|
||||
{Name: "Numéro", Value: fmt.Sprintf("%04d", ticket.TicketNumber), Inline: true},
|
||||
{Name: "Channel", Value: fmt.Sprintf("<#%s>", ticket.ChannelID), Inline: true},
|
||||
{Name: "Ouvert il y a", Value: elapsed.String(), Inline: true},
|
||||
},
|
||||
Title: fmt.Sprintf("Nouveau ticket — %s", ticket.Type),
|
||||
Color: embedColor,
|
||||
Fields: fields,
|
||||
Timestamp: ticket.OpenedAt.UTC().Format(time.RFC3339),
|
||||
}
|
||||
|
||||
customID := fmt.Sprintf("claim:take:%d", ticket.ID)
|
||||
@@ -174,11 +197,11 @@ func (m *Manager) postClaim(ctx context.Context, s *discordgo.Session, ticket *d
|
||||
},
|
||||
}
|
||||
|
||||
if withPing {
|
||||
if panel, ok := cfg.Panels[ticket.Panel]; ok {
|
||||
if t, ok := panel.Types[ticket.Type]; ok && t.StaffRole != "" {
|
||||
send.Content = fmt.Sprintf("<@&%s>", t.StaffRole)
|
||||
}
|
||||
// Always ping staff role
|
||||
if withPing && staffRoleID != "" {
|
||||
send.Content = fmt.Sprintf("<@&%s>", staffRoleID)
|
||||
send.AllowedMentions = &discordgo.MessageAllowedMentions{
|
||||
Roles: []string{staffRoleID},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,3 +211,15 @@ func (m *Manager) postClaim(ctx context.Context, s *discordgo.Session, ticket *d
|
||||
}
|
||||
return msg.ID, nil
|
||||
}
|
||||
|
||||
func parseHexColor(hex string) int {
|
||||
if len(hex) > 0 && hex[0] == '#' {
|
||||
hex = hex[1:]
|
||||
}
|
||||
if len(hex) == 0 {
|
||||
return 0
|
||||
}
|
||||
var v int64
|
||||
fmt.Sscanf(hex, "%x", &v)
|
||||
return int(v)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user