Files
tiennm99bot/internal/modules/lol/lol.go
T
tiennm99 59c74de9a9 refactor(lol): move the subscriber list and daily push fan-out into a shared package
The subscriber store, the once-per-day claim, the terminal-error
classifier and the throttled fan-out with dead-chat pruning now live in
internal/modules/util/subscription so another module can offer an
opt-in daily push. Stored document shapes and keys are unchanged.
2026-10-02 13:06:07 +07:00

67 lines
2.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package lol
import (
"github.com/tiennm99/miti99bot/internal/modules"
"github.com/tiennm99/miti99bot/internal/modules/util/subscription"
"github.com/tiennm99/miti99bot/internal/storage"
)
// CollectionName is the MongoDB collection/module key used by the registry.
const CollectionName = "lol"
// New is the lol module Factory. The 6 user-facing commands plus the
// daily-push cron (lol_daily_push at 08:00 ICT, fan-out to
// subscribers) are wired here. The cron handler reads deps.Bot at invoke
// time — main.go must wire BuildOptions.Bot for the cron to function;
// without it the handler fails fast with a clear error.
func New(deps modules.Deps) modules.Module {
s := &state{
subscribers: storage.Typed[subscription.Doc](deps.Store),
pushDate: storage.Typed[subscription.DayDoc](deps.Store),
cache: storage.Typed[cacheRecord](deps.Store),
client: &Client{},
}
return modules.Module{
Commands: []modules.Command{
{
Name: "lol",
Visibility: modules.VisibilityPublic,
Description: "LoL matches for a date (dd, dd-mm, dd/mm, ddmm, or full date; default today)",
Parameters: "[date]",
Handler: s.handleSchedule,
},
{
Name: "lol_tomorrow",
Visibility: modules.VisibilityPublic,
Description: "LoL esports matches for tomorrow (ICT)",
Handler: s.handleTomorrow,
},
{
Name: "lol_this_week",
Visibility: modules.VisibilityPublic,
Description: "LoL esports matches for this week (Mon–Sun, ICT)",
Handler: s.handleWeek,
},
{
Name: "lol_next_week",
Visibility: modules.VisibilityPublic,
Description: "LoL esports matches for next week (Mon–Sun, ICT)",
Handler: s.handleNextWeek,
},
{
Name: "lol_subscribe",
Visibility: modules.VisibilityPublic,
Description: "Get the daily LoL schedule digest at 08:00 ICT",
Handler: s.handleSubscribe,
},
{
Name: "lol_unsubscribe",
Visibility: modules.VisibilityPublic,
Description: "Stop receiving the daily LoL schedule digest",
Handler: s.handleUnsubscribe,
},
},
Crons: []modules.Cron{s.dailyPushCron()},
}
}