mirror of
https://github.com/tiennm99/miti99bot.git
synced 2026-09-19 14:22:20 +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.
76 lines
2.0 KiB
Go
76 lines
2.0 KiB
Go
package util
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"html"
|
|
"strings"
|
|
|
|
"github.com/go-telegram/bot"
|
|
"github.com/go-telegram/bot/models"
|
|
|
|
"github.com/tiennm99/miti99bot-go/internal/modules"
|
|
)
|
|
|
|
const stickerIDUsage = "Reply to a sticker message with /stickerid to get its file_id.\n" +
|
|
"Usage: send a sticker to me, then tap Reply on it and type /stickerid."
|
|
|
|
// stickerIDCommand returns /stickerid — private dev helper. Reply to a
|
|
// sticker, run /stickerid, get the bot-scoped file_id back. Used to populate
|
|
// loldle's congrats/lose/giveup sticker pools.
|
|
func stickerIDCommand() modules.Command {
|
|
return modules.Command{
|
|
Name: "stickerid",
|
|
Visibility: modules.VisibilityPrivate,
|
|
Description: "Reply to a sticker with this command to get its bot-scoped file_id",
|
|
Handler: func(ctx context.Context, b *bot.Bot, update *models.Update) error {
|
|
msg := update.Message
|
|
if msg == nil {
|
|
return nil
|
|
}
|
|
|
|
sticker := stickerFrom(msg)
|
|
if sticker == nil {
|
|
_, err := b.SendMessage(ctx, &bot.SendMessageParams{
|
|
ChatID: msg.Chat.ID,
|
|
Text: stickerIDUsage,
|
|
})
|
|
return err
|
|
}
|
|
|
|
setName := sticker.SetName
|
|
if setName == "" {
|
|
setName = "(no set)"
|
|
}
|
|
emoji := sticker.Emoji
|
|
if emoji == "" {
|
|
emoji = "—"
|
|
}
|
|
|
|
var sb strings.Builder
|
|
sb.WriteString("<b>file_id</b>\n")
|
|
fmt.Fprintf(&sb, "<code>%s</code>\n\n", html.EscapeString(sticker.FileID))
|
|
sb.WriteString("<b>file_unique_id</b>\n")
|
|
fmt.Fprintf(&sb, "<code>%s</code>\n\n", html.EscapeString(sticker.FileUniqueID))
|
|
fmt.Fprintf(&sb, "set: %s · emoji: %s",
|
|
html.EscapeString(setName), html.EscapeString(emoji))
|
|
|
|
_, err := b.SendMessage(ctx, &bot.SendMessageParams{
|
|
ChatID: msg.Chat.ID,
|
|
Text: sb.String(),
|
|
ParseMode: models.ParseModeHTML,
|
|
})
|
|
return err
|
|
},
|
|
}
|
|
}
|
|
|
|
// stickerFrom pulls the sticker out of the *replied-to* message, mirroring the
|
|
// JS handler: ctx.message.reply_to_message.sticker.
|
|
func stickerFrom(msg *models.Message) *models.Sticker {
|
|
if msg.ReplyToMessage == nil {
|
|
return nil
|
|
}
|
|
return msg.ReplyToMessage.Sticker
|
|
}
|