Files
tiennm99 7008a57cf5 refactor!: rebrand miti99bot to tiennm99bot
BREAKING CHANGE: the Go module path is now github.com/tiennm99/tiennm99bot,
the default sticker pack is stickers_by_<bot username>, and the health body,
deploy DM, User-Agents and image names say tiennm99bot.
2026-10-07 15:14:02 +07:00

49 lines
1.7 KiB
Go

package util
import (
"context"
"fmt"
"github.com/go-telegram/bot"
"github.com/go-telegram/bot/models"
"github.com/tiennm99/tiennm99bot/internal/modules"
"github.com/tiennm99/tiennm99bot/internal/modules/util/chathelper"
)
// 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",
// Protected (not Public) because the response exposes internal
// routing IDs — chat id, thread id, sender id. Useful for admins
// debugging group/topic routing; not something every group member
// should be able to enumerate. Non-admins see no response at all
// (Visibility denies are silent — see modules.Auth.Permits).
Visibility: modules.VisibilityProtected,
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 means "no thread" — render as "n/a" instead of "0".
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)
return chathelper.Reply(ctx, b, msg, text)
},
}
}