diff --git a/lib/squader/responders.go b/lib/squader/responders.go index 6ba42e1..5f6a702 100644 --- a/lib/squader/responders.go +++ b/lib/squader/responders.go @@ -78,7 +78,7 @@ func (s *Squader) SquadInfo(update *tgbotapi.Update, playerRaw *dbmapping.Player } message += " " + squadMembers[i].Profile.Nickname + " " if squadMembers[i].Profile.TelegramNickname != "" { - message += "(@" + squadMembers[i].Profile.TelegramNickname + ")" + message += "(@" + c.Users.FormatUsername(squadMembers[i].Profile.TelegramNickname) + ")" } message += " ⚔" + strconv.Itoa(squadMembers[i].Profile.Power) message += "\n" diff --git a/lib/users/responders.go b/lib/users/responders.go index 9fb3350..bd730e1 100644 --- a/lib/users/responders.go +++ b/lib/users/responders.go @@ -10,6 +10,11 @@ import ( "strings" ) +// FormatUsername formats Telegram username for posting +func (u *Users) FormatUsername(userName string) string { + return strings.Replace(userName, "_", "\\_", -1) +} + // ProfileMessage shows current player's profile func (u *Users) ProfileMessage(update *tgbotapi.Update, playerRaw *dbmapping.Player) string { profileRaw, ok := u.GetProfile(playerRaw.ID) @@ -55,7 +60,10 @@ func (u *Users) ProfileMessage(update *tgbotapi.Update, playerRaw *dbmapping.Pla } message := "*Профиль игрока " - message += profileRaw.Nickname + "* (@" + profileRaw.TelegramNickname + ")\n" + message += profileRaw.Nickname + "*" + if profileRaw.TelegramNickname != "" { + message += " (@" + u.FormatUsername(profileRaw.TelegramNickname) + ")" + } message += "\nЛига: " + league.Symbol + league.Name message += "\n👤 " + strconv.Itoa(profileRaw.LevelID) message += " | 🎓 " + strconv.Itoa(profileRaw.Exp) + "/" + strconv.Itoa(level.MaxExp) @@ -105,6 +113,8 @@ func (u *Users) ProfileMessage(update *tgbotapi.Update, playerRaw *dbmapping.Pla message += "\nНе забывай обновляться, это важно для получения актуальной информации.\n\n" message += "/best – посмотреть лучших покемемов для поимки" + c.Log.Debug(message) + msg := tgbotapi.NewMessage(update.Message.Chat.ID, message) msg.ParseMode = "Markdown" diff --git a/lib/users/users.go b/lib/users/users.go index 328e4ec..0c6b70b 100644 --- a/lib/users/users.go +++ b/lib/users/users.go @@ -89,7 +89,7 @@ func (u *Users) usersList(update *tgbotapi.Update, page int, usersArray []dbmapp message += " " + usersArray[i].League.Symbol message += " " + usersArray[i].Profile.Nickname if usersArray[i].Profile.TelegramNickname != "" { - message += " (@" + usersArray[i].Profile.TelegramNickname + ")" + message += " (@" + u.FormatUsername(usersArray[i].Profile.TelegramNickname) + ")" } message += "\n" message += "Telegram ID: " + strconv.Itoa(usersArray[i].Player.TelegramID) + "\n" diff --git a/lib/users/usersinterface/usersinterface.go b/lib/users/usersinterface/usersinterface.go index 5a8af98..c6cb5bf 100644 --- a/lib/users/usersinterface/usersinterface.go +++ b/lib/users/usersinterface/usersinterface.go @@ -19,6 +19,7 @@ type UsersInterface interface { GetPlayerByID(playerID int) (dbmapping.Player, bool) PlayerBetterThan(playerRaw *dbmapping.Player, powerLevel string) bool + FormatUsername(userName string) string ProfileMessage(update *tgbotapi.Update, playerRaw *dbmapping.Player) string UsersList(update *tgbotapi.Update) string }