Archived
1

Fixed error with underscores in usernames

This commit is contained in:
Vladimir Hodakov 2017-11-25 03:44:58 +04:00
parent ac0292ab6f
commit 130aabda81
4 changed files with 14 additions and 3 deletions

View File

@ -78,7 +78,7 @@ func (s *Squader) SquadInfo(update *tgbotapi.Update, playerRaw *dbmapping.Player
} }
message += " " + squadMembers[i].Profile.Nickname + " " message += " " + squadMembers[i].Profile.Nickname + " "
if squadMembers[i].Profile.TelegramNickname != "" { 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 += " ⚔" + strconv.Itoa(squadMembers[i].Profile.Power)
message += "\n" message += "\n"

View File

@ -10,6 +10,11 @@ import (
"strings" "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 // ProfileMessage shows current player's profile
func (u *Users) ProfileMessage(update *tgbotapi.Update, playerRaw *dbmapping.Player) string { func (u *Users) ProfileMessage(update *tgbotapi.Update, playerRaw *dbmapping.Player) string {
profileRaw, ok := u.GetProfile(playerRaw.ID) profileRaw, ok := u.GetProfile(playerRaw.ID)
@ -55,7 +60,10 @@ func (u *Users) ProfileMessage(update *tgbotapi.Update, playerRaw *dbmapping.Pla
} }
message := "*Профиль игрока " 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Лига: " + league.Symbol + league.Name
message += "\n👤 " + strconv.Itoa(profileRaw.LevelID) message += "\n👤 " + strconv.Itoa(profileRaw.LevelID)
message += " | 🎓 " + strconv.Itoa(profileRaw.Exp) + "/" + strconv.Itoa(level.MaxExp) 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 += "\nНе забывай обновляться, это важно для получения актуальной информации.\n\n"
message += "/best посмотреть лучших покемемов для поимки" message += "/best посмотреть лучших покемемов для поимки"
c.Log.Debug(message)
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message) msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
msg.ParseMode = "Markdown" msg.ParseMode = "Markdown"

View File

@ -89,7 +89,7 @@ func (u *Users) usersList(update *tgbotapi.Update, page int, usersArray []dbmapp
message += " " + usersArray[i].League.Symbol message += " " + usersArray[i].League.Symbol
message += " " + usersArray[i].Profile.Nickname message += " " + usersArray[i].Profile.Nickname
if usersArray[i].Profile.TelegramNickname != "" { if usersArray[i].Profile.TelegramNickname != "" {
message += " (@" + usersArray[i].Profile.TelegramNickname + ")" message += " (@" + u.FormatUsername(usersArray[i].Profile.TelegramNickname) + ")"
} }
message += "\n" message += "\n"
message += "Telegram ID: " + strconv.Itoa(usersArray[i].Player.TelegramID) + "\n" message += "Telegram ID: " + strconv.Itoa(usersArray[i].Player.TelegramID) + "\n"

View File

@ -19,6 +19,7 @@ type UsersInterface interface {
GetPlayerByID(playerID int) (dbmapping.Player, bool) GetPlayerByID(playerID int) (dbmapping.Player, bool)
PlayerBetterThan(playerRaw *dbmapping.Player, powerLevel string) bool PlayerBetterThan(playerRaw *dbmapping.Player, powerLevel string) bool
FormatUsername(userName string) string
ProfileMessage(update *tgbotapi.Update, playerRaw *dbmapping.Player) string ProfileMessage(update *tgbotapi.Update, playerRaw *dbmapping.Player) string
UsersList(update *tgbotapi.Update) string UsersList(update *tgbotapi.Update) string
} }