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:
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")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user