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:
@@ -17,6 +17,7 @@ gaming = "!gamingroomid:matrix.example.org"
|
|||||||
lego = "!legoroomid:matrix.example.org"
|
lego = "!legoroomid:matrix.example.org"
|
||||||
|
|
||||||
[posting]
|
[posting]
|
||||||
|
enabled = true # master switch for auto-posting news to Matrix; false = web-only (commands still work)
|
||||||
min_interval_seconds = 300
|
min_interval_seconds = 300
|
||||||
burst_cap_count = 3
|
burst_cap_count = 3
|
||||||
burst_cap_window_seconds = 1800
|
burst_cap_window_seconds = 1800
|
||||||
|
|||||||
@@ -57,10 +57,16 @@ type MatrixConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PostingConfig struct {
|
type PostingConfig struct {
|
||||||
MinIntervalSeconds int `toml:"min_interval_seconds"`
|
// Enabled is the master switch for automatic news posting to Matrix.
|
||||||
BurstCapCount int `toml:"burst_cap_count"`
|
// When false, stories are still ingested, classified, and served to the
|
||||||
BurstCapWindowSeconds int `toml:"burst_cap_window_seconds"`
|
// web UI, but Pete never auto-posts them to rooms. Command replies
|
||||||
DedupCooldownHours int `toml:"dedup_cooldown_hours"`
|
// (!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
|
// DailyCapTotal is the hard global cap on posts across ALL channels in a
|
||||||
// rolling 24-hour window. 0 disables the cap.
|
// rolling 24-hour window. 0 disables the cap.
|
||||||
DailyCapTotal int `toml:"daily_cap_total"`
|
DailyCapTotal int `toml:"daily_cap_total"`
|
||||||
@@ -198,6 +204,10 @@ func (c *Config) applyDefaults() {
|
|||||||
if c.Matrix.DisplayName == "" {
|
if c.Matrix.DisplayName == "" {
|
||||||
c.Matrix.DisplayName = "Pete"
|
c.Matrix.DisplayName = "Pete"
|
||||||
}
|
}
|
||||||
|
if c.Posting.Enabled == nil {
|
||||||
|
on := true
|
||||||
|
c.Posting.Enabled = &on
|
||||||
|
}
|
||||||
if c.Posting.MinIntervalSeconds == 0 {
|
if c.Posting.MinIntervalSeconds == 0 {
|
||||||
c.Posting.MinIntervalSeconds = 300
|
c.Posting.MinIntervalSeconds = 300
|
||||||
}
|
}
|
||||||
|
|||||||
12
main.go
12
main.go
@@ -174,7 +174,11 @@ func main() {
|
|||||||
go queue.Start(ctx)
|
go queue.Start(ctx)
|
||||||
slog.Info("post queue started")
|
slog.Info("post queue started")
|
||||||
|
|
||||||
|
postingEnabled := *cfg.Posting.Enabled
|
||||||
roundRobinMode := cfg.Posting.RoundRobin.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
|
// Pipeline callback: route the story to its direct_route channel, then
|
||||||
// either enqueue immediately or leave it for the round-robin scheduler.
|
// either enqueue immediately or leave it for the round-robin scheduler.
|
||||||
@@ -188,6 +192,12 @@ func main() {
|
|||||||
channel := item.DirectRoute
|
channel := item.DirectRoute
|
||||||
storage.MarkClassified(item.GUID, channel, "[]")
|
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 {
|
if roundRobinMode {
|
||||||
slog.Info("story routed, awaiting round-robin tick",
|
slog.Info("story routed, awaiting round-robin tick",
|
||||||
"guid", item.GUID, "source", item.Source, "channel", channel)
|
"guid", item.GUID, "source", item.Source, "channel", channel)
|
||||||
@@ -215,7 +225,7 @@ func main() {
|
|||||||
poller.Start(ctx)
|
poller.Start(ctx)
|
||||||
slog.Info("pollers started")
|
slog.Info("pollers started")
|
||||||
|
|
||||||
if roundRobinMode {
|
if postingEnabled && roundRobinMode {
|
||||||
channelNames := make([]string, 0, len(cfg.Matrix.Channels))
|
channelNames := make([]string, 0, len(cfg.Matrix.Channels))
|
||||||
for name := range cfg.Matrix.Channels {
|
for name := range cfg.Matrix.Channels {
|
||||||
channelNames = append(channelNames, name)
|
channelNames = append(channelNames, name)
|
||||||
|
|||||||
Reference in New Issue
Block a user