Beta server and role come from the dashboard

The owner sets them on the admin page; the bot polls the shared beta_settings
row (30s) and moves the beta commands if the server changes. BETA_* env vars
are gone.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
FernandoJVideiraandClaude Sonnet 5.5 committed 2026-10-23 00:55:09 +01:00
1 parent a364435bab
commit 1ee6280d91
7 files changed
+157 -24

No files matched your search

@@ -117,3 +117,66 @@ func TestMeetingLobbiesConcurrent(t *testing.T) {
t.Errorf("have %d lobbies, want %d", len(ids), MaxMeetingLobbies)
}
}
func TestGetBetaSettings(t *testing.T) {
r, _ := testRepo(t)
db := r.db
ctx := context.Background()
_, err := db.ExecContext(ctx, `CREATE TABLE IF NOT EXISTS beta_settings (
id BOOLEAN PRIMARY KEY DEFAULT TRUE CHECK (id), guild_id BIGINT, role_id BIGINT, updated_by BIGINT,
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW())`)
if err != nil {
t.Fatal(err)
}
var wasG, wasR sql.NullInt64
hadRow := db.QueryRowContext(ctx, `SELECT guild_id, role_id FROM beta_settings WHERE id`).Scan(&wasG, &wasR) == nil
t.Cleanup(func() {
if hadRow {
_, _ = db.ExecContext(ctx, `UPDATE beta_settings SET guild_id=$1, role_id=$2 WHERE id`, wasG, wasR)
} else {
_, _ = db.ExecContext(ctx, `DELETE FROM beta_settings`)
}
})
_, err = db.ExecContext(ctx, `DELETE FROM beta_settings`)
if err != nil {
t.Fatal(err)
}
g, role, err := r.GetBetaSettings(ctx)
if err != nil {
t.Fatal(err)
}
if g != "" {
t.Fatalf("g = %q, want empty", g)
}
if role != "" {
t.Fatalf("role = %q, want empty", role)
}
_, err = db.ExecContext(ctx, `INSERT INTO beta_settings (id, guild_id) VALUES (TRUE, 1170934850157547600)`)
if err != nil {
t.Fatal(err)
}
g, role, err = r.GetBetaSettings(ctx)
if err != nil {
t.Fatal(err)
}
if g != "1170934850157547600" {
t.Fatalf("g = %q, want %q", g, "1170934850157547600")
}
if role != "" {
t.Fatalf("role = %q, want empty", role)
}
_, err = db.ExecContext(ctx, `UPDATE beta_settings SET role_id = 42`)
if err != nil {
t.Fatal(err)
}
_, role, err = r.GetBetaSettings(ctx)
if err != nil {
t.Fatal(err)
}
if role != "42" {
t.Fatalf("role = %q, want %q", role, "42")
}
}
+21
View File
@@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"errors"
"strconv"
"github.com/jackc/pgx/v5/pgconn"
)
@@ -401,3 +402,23 @@ func (r *Repo) SetMusicEnabled(ctx context.Context, guildID int64, enabled bool)
_, err := r.db.ExecContext(ctx, q, guildID, enabled)
return err
}
// GetBetaSettings returns the beta server and Beta Tester role as set on the
// dashboard. Either is "" when not set (or when there's no row yet).
func (r *Repo) GetBetaSettings(ctx context.Context) (guildID, roleID string, err error) {
var g, role sql.NullInt64
err = r.db.QueryRowContext(ctx, `SELECT guild_id, role_id FROM beta_settings WHERE id = TRUE`).Scan(&g, &role)
if errors.Is(err, sql.ErrNoRows) {
return "", "", nil
}
if err != nil {
return "", "", err
}
if g.Valid {
guildID = strconv.FormatInt(g.Int64, 10)
}
if role.Valid {
roleID = strconv.FormatInt(role.Int64, 10)
}
return guildID, roleID, nil
}