Archived
1

Academic access level, can see other profiles

This commit is contained in:
2017-12-01 10:55:18 +04:00
parent da8fe3f3e8
commit 703ea27cdb
7 changed files with 63 additions and 4 deletions

View File

@@ -72,6 +72,10 @@ func (u *Users) PlayerBetterThan(playerRaw *dbmapping.Player, powerLevel string)
if powerLevel != "owner" {
isBetter = true
}
case "academic":
if powerLevel != "ownder" && powerLevel != "admin" {
isBetter = true
}
default:
isBetter = false
}

View File

@@ -15,6 +15,28 @@ func (u *Users) FormatUsername(userName string) string {
return strings.Replace(userName, "_", "\\_", -1)
}
// ForeignProfileMessage shows profile of another user
func (u *Users) ForeignProfileMessage(update *tgbotapi.Update) string {
userNum := strings.TrimPrefix(update.Message.Command(), "profile")
userID, err := strconv.Atoi(userNum)
if err != nil {
c.Log.Error(err.Error())
return "fail"
}
playerRaw, ok := u.GetPlayerByID(userID)
if !ok {
return "fail"
}
_, ok = u.GetProfile(playerRaw.ID)
if !ok {
return c.Talkers.BotError(update)
}
return u.ProfileMessage(update, &playerRaw)
}
// ProfileMessage shows current player's profile
func (u *Users) ProfileMessage(update *tgbotapi.Update, playerRaw *dbmapping.Player) string {
profileRaw, ok := u.GetProfile(playerRaw.ID)
@@ -94,6 +116,8 @@ func (u *Users) ProfileMessage(update *tgbotapi.Update, playerRaw *dbmapping.Pla
message += "\n\nСтатус в боте: _владелец_"
} else if playerRaw.Status == "admin" {
message += "\n\nСтатус в боте: _администратор_"
} else if playerRaw.Status == "academic" {
message += "\n\nСтатус в боте: _академик_"
} else {
message += "\n\nСтатус в боте: _игрок_"
}

View File

@@ -98,7 +98,7 @@ func (u *Users) usersList(update *tgbotapi.Update, page int, usersArray []dbmapp
if usersArray[i].Profile.TelegramNickname != "" {
message += " (@" + u.FormatUsername(usersArray[i].Profile.TelegramNickname) + ")"
}
message += "\n"
message += " /profile" + strconv.Itoa(usersArray[i].Player.ID) + "\n"
message += "Telegram ID: " + strconv.Itoa(usersArray[i].Player.TelegramID) + "\n"
message += "Последнее обновление: " + usersArray[i].Profile.CreatedAt.Format("02.01.2006 15:04:05") + "\n"
} else {

View File

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