/find_top_attack for selecting users by top position
This commit is contained in:
parent
6dac398fd3
commit
feb1899992
@ -181,6 +181,12 @@ func (r *Router) routePrivateRequest(update *tgbotapi.Update, playerRaw *dbmappi
|
||||
return c.Users.FindByName(update)
|
||||
}
|
||||
|
||||
return c.Talkers.AnyMessageUnauthorized(update)
|
||||
case update.Message.Command() == "find_top_attack":
|
||||
if c.Users.PlayerBetterThan(playerRaw, "academic") {
|
||||
return c.Users.FindByTopAttack(update)
|
||||
}
|
||||
|
||||
return c.Talkers.AnyMessageUnauthorized(update)
|
||||
|
||||
case update.Message.Command() == "squad_add_user":
|
||||
|
@ -51,6 +51,28 @@ func (u *Users) FindByName(update *tgbotapi.Update) string {
|
||||
return "ok"
|
||||
}
|
||||
|
||||
// FindByTopAttack finds user by top-attack rating
|
||||
func (u *Users) FindByTopAttack(update *tgbotapi.Update) string {
|
||||
commandArgs := update.Message.CommandArguments()
|
||||
if commandArgs == "" {
|
||||
c.Talkers.BotError(update)
|
||||
return "fail"
|
||||
}
|
||||
|
||||
attackInt, err := strconv.Atoi(commandArgs)
|
||||
if err != nil {
|
||||
c.Log.Error(err.Error())
|
||||
c.Talkers.BotError(update)
|
||||
return "fail"
|
||||
}
|
||||
|
||||
users := u.findUserByTopAttack(attackInt)
|
||||
|
||||
u.foundUsersMessage(update, users)
|
||||
|
||||
return "ok"
|
||||
}
|
||||
|
||||
// ForeignProfileMessage shows profile of another user
|
||||
func (u *Users) ForeignProfileMessage(update *tgbotapi.Update) string {
|
||||
userNum := strings.TrimPrefix(update.Message.Command(), "profile")
|
||||
|
@ -49,6 +49,31 @@ func (u *Users) findUserByName(pattern string) map[int]*dbmapping.PlayerProfile
|
||||
return selectedUsers
|
||||
}
|
||||
|
||||
func (u *Users) findUserByTopAttack(power int) map[int]*dbmapping.PlayerProfile {
|
||||
selectedUsers := make(map[int]*dbmapping.PlayerProfile)
|
||||
allPlayers := c.DataCache.GetPlayersWithCurrentProfiles()
|
||||
|
||||
profiles := make([]*dbmapping.PlayerProfile, 0)
|
||||
|
||||
for i := range allPlayers {
|
||||
if allPlayers[i].Player.LeagueID == 1 {
|
||||
profiles = append(profiles, allPlayers[i])
|
||||
}
|
||||
}
|
||||
|
||||
sort.Slice(profiles, func(i, j int) bool {
|
||||
return profiles[i].Profile.Power > profiles[j].Profile.Power
|
||||
})
|
||||
|
||||
for i := (power - 1); i < (power + 2); i++ {
|
||||
if profiles[i] != nil {
|
||||
selectedUsers[i] = profiles[i]
|
||||
}
|
||||
}
|
||||
|
||||
return selectedUsers
|
||||
}
|
||||
|
||||
func (u *Users) foundUsersMessage(update *tgbotapi.Update, users map[int]*dbmapping.PlayerProfile) {
|
||||
var keys []int
|
||||
for i := range users {
|
||||
|
@ -19,6 +19,7 @@ type UsersInterface interface {
|
||||
|
||||
FindByLevel(update *tgbotapi.Update) string
|
||||
FindByName(update *tgbotapi.Update) string
|
||||
FindByTopAttack(update *tgbotapi.Update) string
|
||||
ForeignProfileMessage(update *tgbotapi.Update) string
|
||||
FormatUsername(userName string) string
|
||||
ProfileAddEffectsMessage(update *tgbotapi.Update) string
|
||||
|
Reference in New Issue
Block a user