mirror of
https://github.com/tiennm99/tiennm99bot.git
synced 2026-10-11 03:13:46 +00:00
Serve the BotFather game noitu from the bot's HTTP server under /games/noitu when GAME_BASE_URL is set. /noitu sends the game, Play answers with a signed, expiring link, and the server validates every word against the embedded noitu dictionary (CC BY-SA 4.0), runs the bot opponent and turn timer, and reports the score with setGameScore. Modules can now register game-short-name callbacks and HTTP routes.
36 lines
1.1 KiB
Go
36 lines
1.1 KiB
Go
package noitu
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/go-telegram/bot"
|
|
"github.com/go-telegram/bot/models"
|
|
|
|
"github.com/tiennm99/tiennm99bot/internal/modules/util/chathelper"
|
|
)
|
|
|
|
const (
|
|
msgChannel = "Không thể chơi nối từ trong kênh. Hãy dùng /noitu trong nhóm hoặc chat riêng với bot."
|
|
msgSendGameFail = "Không gửi được trò chơi nối từ. Thử lại sau nhé."
|
|
)
|
|
|
|
// handleCommand sends the BotFather game. No reply markup: Telegram then adds
|
|
// the Play button itself, which is the button the game requires first.
|
|
// The command works even when the game is disabled; Play explains why.
|
|
func (s *service) handleCommand(ctx context.Context, b *bot.Bot, update *models.Update) error {
|
|
msg := update.Message
|
|
if msg.Chat.Type == models.ChatTypeChannel {
|
|
return chathelper.Reply(ctx, b, msg, msgChannel)
|
|
}
|
|
_, err := b.SendGame(ctx, &bot.SendGameParams{
|
|
ChatID: msg.Chat.ID,
|
|
MessageThreadID: msg.MessageThreadID,
|
|
GameShorName: ShortName, // the library's field name is misspelled
|
|
})
|
|
if err != nil {
|
|
_ = chathelper.Reply(ctx, b, msg, msgSendGameFail)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|