mirror of
https://github.com/tiennm99/miti99bot.git
synced 2026-09-18 12:21:10 +00:00
Implements Phases 02 (partial) and 03 of the go-port-cloud-run plan. Introduces module framework with per-module KV prefix isolation, health check endpoint, request timeout protection, and comprehensive test coverage. Cloud Run deployment deferred to Phase 01. Security hardening: constant-time secret comparison, cron auth bridge, and secrets stripped from dependency environment exports. Includes Dockerfile, GitHub CI workflow (vet + race + build), and integration tests for module lifecycle.
30 lines
767 B
Go
30 lines
767 B
Go
package modules
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
|
|
"github.com/go-telegram/bot"
|
|
"github.com/go-telegram/bot/models"
|
|
)
|
|
|
|
// Install registers every command in the registry with the Telegram bot.
|
|
//
|
|
// MatchTypeCommand expects the bare command name without the leading slash;
|
|
// the library compares against entity bytes after the "/" prefix.
|
|
func Install(b *bot.Bot, reg *Registry) {
|
|
for name, cmd := range reg.AllCommands {
|
|
cmdCopy := cmd // capture by value for the closure
|
|
b.RegisterHandler(
|
|
bot.HandlerTypeMessageText,
|
|
name,
|
|
bot.MatchTypeCommand,
|
|
func(ctx context.Context, b *bot.Bot, update *models.Update) {
|
|
if err := cmdCopy.Handler(ctx, b, update); err != nil {
|
|
log.Printf("command /%s failed: %v", cmdCopy.Name, err)
|
|
}
|
|
},
|
|
)
|
|
}
|
|
}
|