aa330b726e
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 10s
CI / integration (pull_request) Successful in 15s
CI / ui (pull_request) Has been skipped
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m17s
The main bot answered /start with a single English line ("Tap to open Scrabble.").
Localize it: Russian or English by the sender's reported Telegram language
(Message.from.language_code, which the Bot API carries on the message itself — there is
no separate user-update event — English fallback), with the longer welcome copy and a
localized launch button ("Открыть «Эрудит»" / "Open “Erudite”").
The welcome links the game channel and the discussion chat by their public @username,
resolved once at startup from the configured TELEGRAM_GAME_CHANNEL_ID / TELEGRAM_CHAT_ID
via getChat and cached. A handle that is unset, private, or unreadable degrades to a
generic noun ("the channel" / "our chat") rather than a dangling "@", so the paragraph
always reads cleanly (the bot's info screen still lists the real links). Adds
GameChannelID to bot.Config (wired from the existing config) for the channel handle.
Tests: startText localization + handle embedding + per-slot generic fallback; handleStart
language selection; resolveWelcomeHandles. README updated.
61 lines
2.6 KiB
Go
61 lines
2.6 KiB
Go
package bot
|
|
|
|
import "strings"
|
|
|
|
// startText returns the localized /start welcome body and the launch-button label.
|
|
// Russian is used when lang (the IETF language tag the Telegram client reports on the
|
|
// message's sender) starts with "ru", English otherwise and when it is absent — so a
|
|
// user with no reported language still gets a sensible message. channel and chat are
|
|
// the resolved public @usernames (without the leading @) of the game channel and the
|
|
// discussion chat; when either is empty its follow link degrades to a generic noun
|
|
// (e.g. "the channel" / "our chat") rather than rendering a dangling "@", since the
|
|
// bot's own info screen still lists the real links.
|
|
func startText(lang, channel, chat string) (text, button string) {
|
|
if strings.HasPrefix(strings.ToLower(lang), "ru") {
|
|
return ruWelcome(channel, chat), "Открыть «Эрудит»"
|
|
}
|
|
return enWelcome(channel, chat), "Open “Erudite”"
|
|
}
|
|
|
|
// ruWelcome builds the Russian welcome. A known handle is named as "@<username>"; an
|
|
// unresolved one degrades to a plain noun.
|
|
func ruWelcome(channel, chat string) string {
|
|
ch := "канал"
|
|
if channel != "" {
|
|
ch = "@" + channel
|
|
}
|
|
ct := "чате"
|
|
if chat != "" {
|
|
ct = "@" + chat
|
|
}
|
|
return strings.Join([]string{
|
|
"Привет! 👋",
|
|
"Здесь можно сражаться в «Эрудит» со случайными игроками или в компании друзей.",
|
|
"Подписывайтесь на " + ch + ", чтобы быть в курсе последних игровых событий и вовремя " +
|
|
"получать важные уведомления. Игроки могут обсуждать игру и просто общаться в нашем " +
|
|
ct + "! 💬",
|
|
"Ни слова больше.\nПервая партия сама себя не сыграет 😊",
|
|
}, "\n\n")
|
|
}
|
|
|
|
// enWelcome builds the English welcome (the fallback for any non-Russian or missing
|
|
// language). A known handle is named as "@<username>"; an unresolved one degrades to a
|
|
// plain noun.
|
|
func enWelcome(channel, chat string) string {
|
|
ch := "the channel"
|
|
if channel != "" {
|
|
ch = "@" + channel
|
|
}
|
|
ct := "group chat"
|
|
if chat != "" {
|
|
ct = "@" + chat
|
|
}
|
|
return strings.Join([]string{
|
|
"Hi! 👋",
|
|
"Play Scrabble against random players — or with a group of friends.",
|
|
"Follow " + ch + " to stay up to date with the latest game events and receive important " +
|
|
"notifications in time. Players can discuss the game and simply chat in our " + ct + "! 💬",
|
|
"Okay, no more talking.\nFirst game won't play itself 😊",
|
|
}, "\n\n")
|
|
}
|