Fix scheduled posts only broadcasting to first room

All scheduled post dedup keys (wotd, holidays, gaming, anime, movies,
concerts, birthdays) were global — after posting to the first room,
the job was marked complete and the second room was skipped. Fixed by
including the room ID in each dedup key so posts go to all broadcast
rooms. Birthday XP grants and DMs remain once-per-user-per-year.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
prosolis
2026-03-09 00:09:11 -07:00
parent c1cca5ae12
commit 2c191ec464
7 changed files with 47 additions and 42 deletions

View File

@@ -148,19 +148,25 @@ func (p *WOTDPlugin) PostWOTD(roomID id.RoomID) error {
today := time.Now().UTC().Format("2006-01-02")
d := db.Get()
// Per-room dedup
roomKey := fmt.Sprintf("%s:%s", today, roomID)
if db.JobCompleted("wotd", roomKey) {
slog.Info("wotd: already posted today", "date", today, "room", roomID)
return nil
}
var word, definition, partOfSpeech, example string
var posted int
err := d.QueryRow(
`SELECT word, definition, part_of_speech, example, posted FROM wotd_log WHERE date = ?`, today,
).Scan(&word, &definition, &partOfSpeech, &example, &posted)
`SELECT word, definition, part_of_speech, example FROM wotd_log WHERE date = ?`, today,
).Scan(&word, &definition, &partOfSpeech, &example)
if err == sql.ErrNoRows {
slog.Warn("wotd: no entry for today, attempting prefetch", "date", today)
if err := p.Prefetch(); err != nil {
return fmt.Errorf("wotd: prefetch failed: %w", err)
}
err = d.QueryRow(
`SELECT word, definition, part_of_speech, example, posted FROM wotd_log WHERE date = ?`, today,
).Scan(&word, &definition, &partOfSpeech, &example, &posted)
`SELECT word, definition, part_of_speech, example FROM wotd_log WHERE date = ?`, today,
).Scan(&word, &definition, &partOfSpeech, &example)
if err != nil {
return fmt.Errorf("wotd: still no entry after prefetch: %w", err)
}
@@ -168,20 +174,12 @@ func (p *WOTDPlugin) PostWOTD(roomID id.RoomID) error {
return fmt.Errorf("wotd: query: %w", err)
}
if posted == 1 {
slog.Info("wotd: already posted today", "date", today)
return nil
}
msg := p.formatWOTD(word, definition, partOfSpeech, example)
if err := p.SendMessage(roomID, msg); err != nil {
return fmt.Errorf("wotd: send message: %w", err)
}
_, err = d.Exec(`UPDATE wotd_log SET posted = 1 WHERE date = ?`, today)
if err != nil {
slog.Error("wotd: mark posted", "err", err)
}
db.MarkJobCompleted("wotd", roomKey)
return nil
}