Use a dropdown and a Create ticket button on the ticket panel, in orange

The panel is now one category dropdown and a Create ticket button
instead of a button per category. Discord doesn't send the dropdown's
value with a button click, so each member's pick is remembered in
memory for 15 minutes (per guild and member, capped). Panels posted
before keep working until they're reposted. Every ticket embed is
orange, closed tickets included.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
FernandoJVideiraandClaude Opus 5.5 committed 2026-10-21 11:58:19 +01:00
1 parent e453a9ba94
commit e10e1f7a86
8 files changed
+178 -50

No files matched your search

+61 -10
View File
@@ -74,26 +74,77 @@ func TestBuildPanel(t *testing.T) {
{ID: 2, Name: "Appeal", Emoji: "<a:party:123>"},
}
embed, comps := BuildPanel(s, cats)
row := comps[0].(discordgo.ActionsRow)
b1, b2 := row.Components[0].(discordgo.Button), row.Components[1].(discordgo.Button)
if embed.Title != "Help" || b1.CustomID != "tickets:open:1" || b1.Emoji.Name != "🛟" {
t.Errorf("first button wrong: %+v", b1)
if embed.Title != "Help" || embed.Color != 0xf97316 {
t.Errorf("panel embed wrong: %+v", embed)
}
if b2.Emoji.ID != "123" || b2.Emoji.Name != "party" || !b2.Emoji.Animated {
t.Errorf("custom emoji not parsed: %+v", b2.Emoji)
if len(comps) != 2 {
t.Fatalf("want a dropdown row and a button row, got %d rows", len(comps))
}
menu := comps[0].(discordgo.ActionsRow).Components[0].(discordgo.SelectMenu)
if menu.CustomID != "tickets:select" || len(menu.Options) != 2 || menu.Options[0].Value != "1" || menu.Options[0].Emoji.Name != "🛟" {
t.Errorf("dropdown wrong: %+v", menu)
}
if e := menu.Options[1].Emoji; e.ID != "123" || e.Name != "party" || !e.Animated {
t.Errorf("custom emoji not parsed: %+v", e)
}
button := comps[1].(discordgo.ActionsRow).Components[0].(discordgo.Button)
if button.CustomID != "tickets:create" || button.Label != "Create ticket" {
t.Errorf("create button wrong: %+v", button)
}
if len(embed.Fields) != 1 || embed.Fields[0].Value != "General help" {
t.Errorf("descriptions belong in the embed: %+v", embed.Fields)
}
var many []ticketrepo.Category
for i := 1; i <= 7; i++ {
for i := 1; i <= 30; i++ {
many = append(many, ticketrepo.Category{ID: int64(i), Name: fmt.Sprint("Cat ", i)})
}
_, comps = BuildPanel(s, many)
menu := comps[0].(discordgo.ActionsRow).Components[0].(discordgo.SelectMenu)
if menu.CustomID != "tickets:select" || len(menu.Options) != 7 || menu.Options[6].Value != "7" {
t.Errorf("more than 5 categories should use a dropdown: %+v", menu)
if n := len(comps[0].(discordgo.ActionsRow).Components[0].(discordgo.SelectMenu).Options); n != 25 {
t.Errorf("a dropdown holds at most 25 options, got %d", n)
}
}
func TestPicks(t *testing.T) {
clock := time.Date(2026, 10, 21, 12, 0, 0, 0, time.UTC)
now = func() time.Time { return clock }
t.Cleanup(func() { now = time.Now; picks = map[pickKey]pick{} })
if _, ok := PickedCategory(guild, 5); ok {
t.Error("nothing picked yet")
}
RememberPick(guild, 5, 3)
RememberPick(guild, 5, 4)
RememberPick(guild, 6, 9)
if c, ok := PickedCategory(guild, 5); !ok || c != 4 {
t.Errorf("the latest pick wins: %d %v", c, ok)
}
if _, ok := PickedCategory(guild+1, 5); ok {
t.Error("picks are per guild")
}
clock = clock.Add(pickTTL + time.Second)
if _, ok := PickedCategory(guild, 5); ok {
t.Error("a pick expires")
}
// Full: new members can't add more, but expired ones make room.
picks = map[pickKey]pick{}
for i := 0; i < maxPicks; i++ {
picks[pickKey{guild + 100, int64(i)}] = pick{1, clock}
}
RememberPick(guild, 7, 1)
if _, ok := PickedCategory(guild, 7); ok {
t.Error("a full map takes no new members")
}
RememberPick(guild+100, 0, 2)
if c, _ := PickedCategory(guild+100, 0); c != 2 {
t.Error("someone already in the map can still change their pick")
}
clock = clock.Add(pickTTL + time.Second)
RememberPick(guild, 7, 1)
if _, ok := PickedCategory(guild, 7); !ok {
t.Error("expired picks should be cleared to make room")
}
}