Fixed error with underscores in usernames
This commit is contained in:
parent
ac0292ab6f
commit
130aabda81
@ -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"
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user