Add posting.enabled master switch to disable auto-posting to Matrix

Stories are still ingested, classified, and served to the web UI; only
automatic Matrix posting is gated. Command replies (!post, !petestats)
still work. Pointer-bool so an absent key defaults to posting-on.
This commit is contained in:
prosolis
2026-06-24 16:39:59 -07:00
parent e65ffb1373
commit 410f8dda0a
3 changed files with 26 additions and 5 deletions

View File

@@ -17,6 +17,7 @@ gaming = "!gamingroomid:matrix.example.org"
lego = "!legoroomid:matrix.example.org"
[posting]
enabled = true # master switch for auto-posting news to Matrix; false = web-only (commands still work)
min_interval_seconds = 300
burst_cap_count = 3
burst_cap_window_seconds = 1800

View File

@@ -57,10 +57,16 @@ type MatrixConfig struct {
}
type PostingConfig struct {
MinIntervalSeconds int `toml:"min_interval_seconds"`
BurstCapCount int `toml:"burst_cap_count"`
BurstCapWindowSeconds int `toml:"burst_cap_window_seconds"`
DedupCooldownHours int `toml:"dedup_cooldown_hours"`
// Enabled is the master switch for automatic news posting to Matrix.
// When false, stories are still ingested, classified, and served to the
// web UI, but Pete never auto-posts them to rooms. Command replies
// (!post, !petestats) still work. Pointer so an absent key defaults to
// true (posting on) rather than Go's zero-value false.
Enabled *bool `toml:"enabled"`
MinIntervalSeconds int `toml:"min_interval_seconds"`
BurstCapCount int `toml:"burst_cap_count"`
BurstCapWindowSeconds int `toml:"burst_cap_window_seconds"`
DedupCooldownHours int `toml:"dedup_cooldown_hours"`
// DailyCapTotal is the hard global cap on posts across ALL channels in a
// rolling 24-hour window. 0 disables the cap.
DailyCapTotal int `toml:"daily_cap_total"`
@@ -198,6 +204,10 @@ func (c *Config) applyDefaults() {
if c.Matrix.DisplayName == "" {
c.Matrix.DisplayName = "Pete"
}
if c.Posting.Enabled == nil {
on := true
c.Posting.Enabled = &on
}
if c.Posting.MinIntervalSeconds == 0 {
c.Posting.MinIntervalSeconds = 300
}

12
main.go
View File

@@ -174,7 +174,11 @@ func main() {
go queue.Start(ctx)
slog.Info("post queue started")
postingEnabled := *cfg.Posting.Enabled
roundRobinMode := cfg.Posting.RoundRobin.Enabled
if !postingEnabled {
slog.Info("automatic Matrix posting is disabled (posting.enabled=false); stories will still be ingested and served to the web UI, and !post still works")
}
// Pipeline callback: route the story to its direct_route channel, then
// either enqueue immediately or leave it for the round-robin scheduler.
@@ -188,6 +192,12 @@ func main() {
channel := item.DirectRoute
storage.MarkClassified(item.GUID, channel, "[]")
// Posting disabled: classify and keep for the web UI / manual !post,
// but never auto-enqueue to Matrix.
if !postingEnabled {
return
}
if roundRobinMode {
slog.Info("story routed, awaiting round-robin tick",
"guid", item.GUID, "source", item.Source, "channel", channel)
@@ -215,7 +225,7 @@ func main() {
poller.Start(ctx)
slog.Info("pollers started")
if roundRobinMode {
if postingEnabled && roundRobinMode {
channelNames := make([]string, 0, len(cfg.Matrix.Channels))
for name := range cfg.Matrix.Channels {
channelNames = append(channelNames, name)