мини фиксы
This commit is contained in:
@@ -20,28 +20,11 @@ type exec struct {
|
||||
}
|
||||
|
||||
var botUsername string
|
||||
var botUsernameOnce sync.Once
|
||||
|
||||
func SetBotUsername(username string) { botUsername = username }
|
||||
|
||||
func BotUsername() string { return botUsername }
|
||||
|
||||
func ensureBotUsername(api echotron.API) {
|
||||
if botUsername != "" {
|
||||
return
|
||||
}
|
||||
botUsernameOnce.Do(func() {
|
||||
me, err := api.GetMe()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("GetMe failed, bot username will be empty")
|
||||
return
|
||||
}
|
||||
if me.Result != nil {
|
||||
botUsername = me.Result.Username
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
type lastRender struct {
|
||||
textHash string
|
||||
kbHash string
|
||||
@@ -77,7 +60,6 @@ func NewBot(chatID int64, token string, commandRouter func(string) State, backen
|
||||
}
|
||||
|
||||
api := echotron.NewAPI(token)
|
||||
ensureBotUsername(api)
|
||||
|
||||
return &Bot{
|
||||
ChatID: chatID,
|
||||
|
||||
@@ -34,6 +34,13 @@ func main() {
|
||||
|
||||
// Регистрируем команды бота в Telegram
|
||||
api := echotron.NewAPI(botToken)
|
||||
if me, err := api.GetMe(); err != nil {
|
||||
log.Error().Err(err).Msg("Failed to get bot profile")
|
||||
} else if me.Result != nil {
|
||||
bot.SetBotUsername(me.Result.Username)
|
||||
log.Info().Str("username", me.Result.Username).Msg("Telegram bot authorized")
|
||||
}
|
||||
|
||||
if _, err := api.SetMyCommands(nil, botCommands...); err != nil {
|
||||
log.Error().Err(err).Msg("Failed to set bot commands")
|
||||
} else {
|
||||
|
||||
@@ -18,18 +18,18 @@ type ChannelInput struct {
|
||||
|
||||
// Парсеры для разных форматов
|
||||
var (
|
||||
// Username без @: 5-32 символа, начинается с буквы
|
||||
channelUsernameRe = regexp.MustCompile(`^[A-Za-z][A-Za-z0-9_]{4,31}$`)
|
||||
// Username без @: 4-32 символа, начинается с буквы
|
||||
channelUsernameRe = regexp.MustCompile(`^[A-Za-z][A-Za-z0-9_]{3,31}$`)
|
||||
|
||||
// Invite link: t.me/+xxxxx или t.me/joinchat/xxxxx
|
||||
inviteLinkRe = regexp.MustCompile(`^t\.me/\+[a-zA-Z0-9_-]+$`)
|
||||
inviteLinkJoinRe = regexp.MustCompile(`^t\.me/joinchat/[a-zA-Z0-9_-]+$`)
|
||||
|
||||
// TGStat: tgstat.ru/channel_name или tgstat.ru/channel/@username
|
||||
tgstatRe = regexp.MustCompile(`^(?:https?://)?(?:www\.)?tgstat\.ru/(?:channel/)?@?([A-Za-z][A-Za-z0-9_.]{4,31})`)
|
||||
tgstatRe = regexp.MustCompile(`^(?:https?://)?(?:www\.)?tgstat\.ru/(?:channel/)?@?([A-Za-z][A-Za-z0-9_.]{3,31})`)
|
||||
|
||||
// Telemetr: telemetr.io/channel/username или telemetr.io/channel/@username
|
||||
telemetrRe = regexp.MustCompile(`^(?:https?://)?(?:www\.)?telemetr\.io/(?:channel|channels)/@?([A-Za-z][A-Za-z0-9_.]{4,31})`)
|
||||
telemetrRe = regexp.MustCompile(`^(?:https?://)?(?:www\.)?telemetr\.io/(?:channel|channels)/@?([A-Za-z][A-Za-z0-9_.]{3,31})`)
|
||||
)
|
||||
|
||||
// ParseChannelInput парсит ввод пользователя и определяет тип канала
|
||||
|
||||
Reference in New Issue
Block a user