mirror of
https://github.com/tiennm99/miti99bot.git
synced 2026-09-12 04:20:49 +00:00
Phase 5a of go-port-cloud-run plan: port first 2 of 4 modules (wordle/loldle deferred to later phase). Port util.go, info.go, help.go, stickerid.go and misc.go with tests. /help renders registry view; /info exposes chat/thread/ sender ids; /stickerid (private) returns bot-scoped file_ids; /ping writes last_ping KV ms-epoch JSON for byte-parity, /mstats reads it, /fortytwo is easter egg. Registry-pointer-in-Deps required for /help to access module registry—pointer captured at factory time, stable post-Build. Static factory catalog moved from modules pkg to cmd/server to break import cycle. Code-review fixes applied in same session: /info nil-deref guard, KV wire-format parity.
47 lines
1.4 KiB
Go
47 lines
1.4 KiB
Go
package util
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/go-telegram/bot"
|
|
"github.com/go-telegram/bot/models"
|
|
|
|
"github.com/tiennm99/miti99bot-go/internal/modules"
|
|
)
|
|
|
|
// infoCommand returns /info — replies plain text with chat / thread / sender
|
|
// IDs, with "n/a" fallbacks. Used to debug bot routing in groups + topics.
|
|
func infoCommand() modules.Command {
|
|
return modules.Command{
|
|
Name: "info",
|
|
Visibility: modules.VisibilityPublic,
|
|
Description: "Show chat id, thread id, and sender id (debug helper)",
|
|
Handler: func(ctx context.Context, b *bot.Bot, update *models.Update) error {
|
|
msg := update.Message
|
|
if msg == nil {
|
|
// Today the dispatcher only routes message-text commands, but
|
|
// guard so /info can be safely reused from other update paths.
|
|
return nil
|
|
}
|
|
chatID := fmt.Sprintf("%d", msg.Chat.ID)
|
|
// Telegram omits message_thread_id outside forum topics, so a 0
|
|
// here is "no thread", same as JS's `?? "n/a"`.
|
|
threadID := "n/a"
|
|
if msg.MessageThreadID != 0 {
|
|
threadID = fmt.Sprintf("%d", msg.MessageThreadID)
|
|
}
|
|
senderID := "n/a"
|
|
if msg.From != nil {
|
|
senderID = fmt.Sprintf("%d", msg.From.ID)
|
|
}
|
|
text := fmt.Sprintf("chat id: %s\nthread id: %s\nsender id: %s", chatID, threadID, senderID)
|
|
_, err := b.SendMessage(ctx, &bot.SendMessageParams{
|
|
ChatID: msg.Chat.ID,
|
|
Text: text,
|
|
})
|
|
return err
|
|
},
|
|
}
|
|
}
|