feat(modules): add Bot to Deps + BuildOptions for cron handlers

- Extend module.Deps struct with optional Bot field
- Add Bot to registry.BuildOptions and thread through builders
- Pass bot instance from main.go into module factory options
- Enables cron handlers to send messages and access bot state
This commit is contained in:
2026-05-10 03:06:01 +07:00
parent 8e9e46fd91
commit 7138f77bb5
3 changed files with 8 additions and 0 deletions
+3
View File
@@ -25,6 +25,7 @@ import (
"github.com/tiennm99/miti99bot-go/internal/modules/lolschedule"
"github.com/tiennm99/miti99bot-go/internal/modules/misc"
"github.com/tiennm99/miti99bot-go/internal/modules/semantle"
"github.com/tiennm99/miti99bot-go/internal/modules/trading"
"github.com/tiennm99/miti99bot-go/internal/modules/twentyq"
"github.com/tiennm99/miti99bot-go/internal/modules/util"
"github.com/tiennm99/miti99bot-go/internal/modules/wordle"
@@ -50,6 +51,7 @@ func factories() map[string]modules.Factory {
"semantle": semantle.New,
"doantu": doantu.New,
"twentyq": twentyq.New,
"trading": trading.New,
}
}
@@ -106,6 +108,7 @@ func main() {
reg, err := modules.Build(cfg.Modules, factories(), provider, cfg.ModuleEnv, modules.BuildOptions{
Embedder: aiClient,
Chatter: aiClient,
Bot: b,
})
if err != nil {
log.Fatal("module registry build failed", "err", err)
+1
View File
@@ -79,6 +79,7 @@ type Deps struct {
Registry *Registry // populated by Build; safe to capture but read-only at module use
Embedder ai.Embedder // nil if GEMINI_API_KEY unset; semantle/doantu must check
Chatter ai.Chatter // nil if GEMINI_API_KEY unset; twentyq must check
Bot *bot.Bot // nil-safe: only crons that fan-out (lolschedule daily push) need it
}
// Factory constructs a Module from its Deps. Spec deviation: Phase 03 plan
+4
View File
@@ -5,6 +5,8 @@ import (
"regexp"
"sort"
"github.com/go-telegram/bot"
"github.com/tiennm99/miti99bot-go/internal/ai"
"github.com/tiennm99/miti99bot-go/internal/storage"
)
@@ -83,6 +85,7 @@ func (r *Registry) Crons() []Cron {
type BuildOptions struct {
Embedder ai.Embedder
Chatter ai.Chatter
Bot *bot.Bot
}
func Build(enabled []string, factories map[string]Factory, kv storage.KVProvider, env map[string]string, opts BuildOptions) (*Registry, error) {
@@ -125,6 +128,7 @@ func Build(enabled []string, factories map[string]Factory, kv storage.KVProvider
Registry: reg,
Embedder: opts.Embedder,
Chatter: opts.Chatter,
Bot: opts.Bot,
}
mod := factory(moduleDeps)
// A factory that hardcodes its own Name is a bug: the registry key is