Multiple meeting lobbies and beta-gated features (3.5.2)

- /meeting add-lobby, remove-lobby, lobbies: up to 10 lobbies per server, capped in the database
- Deleted voice channels are dropped from the lobbies
- Beta features: registered only in the beta server and usable only with the Beta Tester role (BETA_GUILD_ID, BETA_ROLE_ID); fails closed
- /beta (bot owner only) shows how beta access is set up

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
FernandoJVideiraandClaude Sonnet 5.5 committed 2026-10-23 00:38:48 +01:00
1 parent 136377d81a
commit a364435bab
15 files changed
+789 -52

No files matched your search

+115
View File
@@ -0,0 +1,115 @@
package beta
import (
"testing"
"github.com/bwmarrin/discordgo"
)
const (
betaGuild = "1170934850157547600"
testerRol = "555000000000000001"
)
func member(roles ...string) *discordgo.Member { return &discordgo.Member{Roles: roles} }
func interaction(guildID string, m *discordgo.Member) *discordgo.InteractionCreate {
return &discordgo.InteractionCreate{Interaction: &discordgo.Interaction{GuildID: guildID, Member: m}}
}
func TestAllowed(t *testing.T) {
cases := []struct {
name string
guild, role string // configuration
inGuild string
member *discordgo.Member
want bool
inBeta, hasRole bool
}{
{"tester in the beta server", betaGuild, testerRol, betaGuild, member("1", testerRol), true, true, true},
{"member without the role", betaGuild, testerRol, betaGuild, member("1", "2"), false, true, false},
{"member with no roles at all", betaGuild, testerRol, betaGuild, member(), false, true, false},
{"the role in another server doesn't count", betaGuild, testerRol, "999000000000000001", member(testerRol), false, false, false},
{"a DM has no member", betaGuild, testerRol, "", nil, false, false, false},
{"a nil member in the beta server", betaGuild, testerRol, betaGuild, nil, false, true, false},
{"no role configured: nobody", betaGuild, "", betaGuild, member(testerRol, ""), false, true, false},
{"no beta server configured: nobody", "", testerRol, betaGuild, member(testerRol), false, false, false},
{"a role ID that isn't a number is dropped", betaGuild, "tester-role", betaGuild, member("tester-role"), false, true, false},
{"a server ID that isn't a number is dropped", "my-server", testerRol, "my-server", member(testerRol), false, false, false},
{"a role that only contains the ID isn't a match", betaGuild, testerRol, betaGuild, member(testerRol + "9"), false, true, false},
{"stray spaces in the configuration are ignored", " " + betaGuild + " ", " " + testerRol + "\n", betaGuild, member(testerRol), true, true, true},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
Configure(tc.guild, tc.role)
if got := Allowed(tc.inGuild, tc.member); got != tc.want {
t.Errorf("Allowed = %v, want %v", got, tc.want)
}
if got := AllowedInteraction(interaction(tc.inGuild, tc.member)); got != tc.want {
t.Errorf("AllowedInteraction = %v, want %v", got, tc.want)
}
st := StatusOf(tc.inGuild, tc.member)
if st.InBetaGuild != tc.inBeta || st.HasRole != tc.hasRole {
t.Errorf("StatusOf = %+v, want in beta server %v, has role %v", st, tc.inBeta, tc.hasRole)
}
})
}
}
func TestNotConfiguredAtAll(t *testing.T) {
current.Store(nil)
if Allowed(betaGuild, member(testerRol)) || GuildID() != "" {
t.Error("before Configure nothing is allowed and there's no beta server")
}
if AllowedInteraction(nil) || AllowedInteraction(&discordgo.InteractionCreate{}) {
t.Error("a missing interaction is never allowed")
}
}
func TestGateRunsTheHandlerOnlyForTesters(t *testing.T) {
Configure(betaGuild, testerRol)
var answered []string
orig := respond
respond = func(_ *discordgo.Session, _ *discordgo.InteractionCreate, msg string) {
answered = append(answered, msg)
}
t.Cleanup(func() { respond = orig })
ran := 0
h := Gate(func(*discordgo.Session, *discordgo.InteractionCreate) { ran++ })
h(nil, interaction(betaGuild, member(testerRol)))
if ran != 1 || len(answered) != 0 {
t.Fatalf("a tester runs the handler without being refused: ran=%d answered=%v", ran, answered)
}
for name, i := range map[string]*discordgo.InteractionCreate{
"no role": interaction(betaGuild, member("1")),
"wrong server": interaction("999000000000000001", member(testerRol)),
"DM": interaction("", nil),
} {
before := ran
h(nil, i)
if ran != before {
t.Errorf("%s: the handler must not run", name)
}
}
if len(answered) != 3 || answered[0] != denied {
t.Errorf("each refusal is answered with the beta message: %v", answered)
}
}
func TestGuardOnItsOwn(t *testing.T) {
Configure(betaGuild, testerRol)
n := 0
orig := respond
respond = func(*discordgo.Session, *discordgo.InteractionCreate, string) { n++ }
t.Cleanup(func() { respond = orig })
if !Guard(nil, interaction(betaGuild, member(testerRol))) || n != 0 {
t.Error("a tester passes without a reply")
}
if Guard(nil, interaction(betaGuild, member())) || n != 1 {
t.Error("someone else is refused with a reply")
}
}