Command to find users on level
This commit is contained in:
parent
190cdc6e7b
commit
6a57d8581c
@ -4,8 +4,8 @@
|
|||||||
package router
|
package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
|
||||||
"git.wtfteam.pro/fat0troll/i2_bot/lib/dbmapping"
|
"git.wtfteam.pro/fat0troll/i2_bot/lib/dbmapping"
|
||||||
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||||
"regexp"
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -159,6 +159,12 @@ func (r *Router) routePrivateRequest(update *tgbotapi.Update, playerRaw *dbmappi
|
|||||||
|
|
||||||
return c.Talkers.AnyMessageUnauthorized(update)
|
return c.Talkers.AnyMessageUnauthorized(update)
|
||||||
|
|
||||||
|
case update.Message.Command() == "find_level":
|
||||||
|
if c.Users.PlayerBetterThan(playerRaw, "academic") {
|
||||||
|
return c.Users.FindByLevel(update)
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.Talkers.AnyMessageUnauthorized(update)
|
||||||
case update.Message.Command() == "find_user":
|
case update.Message.Command() == "find_user":
|
||||||
if c.Users.PlayerBetterThan(playerRaw, "academic") {
|
if c.Users.PlayerBetterThan(playerRaw, "academic") {
|
||||||
return c.Users.FindByName(update)
|
return c.Users.FindByName(update)
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
package users
|
package users
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
|
||||||
"git.wtfteam.pro/fat0troll/i2_bot/lib/dbmapping"
|
"git.wtfteam.pro/fat0troll/i2_bot/lib/dbmapping"
|
||||||
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@ -15,6 +15,30 @@ func (u *Users) FormatUsername(userName string) string {
|
|||||||
return strings.Replace(userName, "_", `\_`, -1)
|
return strings.Replace(userName, "_", `\_`, -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FindByLevel finds user with level and recent profile update
|
||||||
|
func (u *Users) FindByLevel(update *tgbotapi.Update) string {
|
||||||
|
commandArgs := update.Message.CommandArguments()
|
||||||
|
if commandArgs == "" {
|
||||||
|
c.Talkers.BotError(update)
|
||||||
|
return "fail"
|
||||||
|
}
|
||||||
|
|
||||||
|
levelID, err := strconv.Atoi(commandArgs)
|
||||||
|
if err != nil {
|
||||||
|
c.Log.Error(err.Error())
|
||||||
|
return "fail"
|
||||||
|
}
|
||||||
|
|
||||||
|
usersArray, ok := u.findUsersByLevel(levelID)
|
||||||
|
if !ok {
|
||||||
|
return "fail"
|
||||||
|
}
|
||||||
|
|
||||||
|
u.foundUsersMessage(update, usersArray)
|
||||||
|
|
||||||
|
return "ok"
|
||||||
|
}
|
||||||
|
|
||||||
// FindByName finds user with such username or nickname
|
// FindByName finds user with such username or nickname
|
||||||
func (u *Users) FindByName(update *tgbotapi.Update) string {
|
func (u *Users) FindByName(update *tgbotapi.Update) string {
|
||||||
commandArgs := update.Message.CommandArguments()
|
commandArgs := update.Message.CommandArguments()
|
||||||
@ -28,24 +52,7 @@ func (u *Users) FindByName(update *tgbotapi.Update) string {
|
|||||||
return "fail"
|
return "fail"
|
||||||
}
|
}
|
||||||
|
|
||||||
message := "*Найденные игроки:*\n"
|
u.foundUsersMessage(update, usersArray)
|
||||||
|
|
||||||
for i := range usersArray {
|
|
||||||
message += "#" + strconv.Itoa(usersArray[i].PlayerID)
|
|
||||||
message += " " + usersArray[i].LeagueSymbol
|
|
||||||
message += " " + usersArray[i].Nickname
|
|
||||||
if usersArray[i].TelegramNickname != "" {
|
|
||||||
message += " (@" + u.FormatUsername(usersArray[i].TelegramNickname) + ")"
|
|
||||||
}
|
|
||||||
message += " /profile" + strconv.Itoa(usersArray[i].PlayerID) + "\n"
|
|
||||||
message += "Telegram ID: " + strconv.Itoa(usersArray[i].TelegramID) + "\n"
|
|
||||||
message += "Последнее обновление: " + usersArray[i].CreatedAt.Format("02.01.2006 15:04:05") + "\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
|
||||||
msg.ParseMode = "Markdown"
|
|
||||||
|
|
||||||
c.Bot.Send(msg)
|
|
||||||
|
|
||||||
return "ok"
|
return "ok"
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
package users
|
package users
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
|
||||||
"git.wtfteam.pro/fat0troll/i2_bot/lib/dbmapping"
|
"git.wtfteam.pro/fat0troll/i2_bot/lib/dbmapping"
|
||||||
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -47,6 +47,18 @@ func (u *Users) getUsersWithProfiles() ([]dbmapping.PlayerProfile, bool) {
|
|||||||
return usersArray, true
|
return usersArray, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *Users) findUsersByLevel(levelID int) ([]dbmapping.ProfileWithAddons, bool) {
|
||||||
|
selectedUsers := []dbmapping.ProfileWithAddons{}
|
||||||
|
|
||||||
|
err := c.Db.Select(&selectedUsers, c.Db.Rebind("SELECT p.*, l.symbol AS league_symbol, l.id AS league_id, pl.telegram_id FROM players pl, profiles p, leagues l WHERE p.created_at > NOW() - INTERVAL 72 HOUR AND p.level_id = ? GROUP BY player_id"), levelID)
|
||||||
|
if err != nil {
|
||||||
|
c.Log.Error(err.Error())
|
||||||
|
return selectedUsers, false
|
||||||
|
}
|
||||||
|
|
||||||
|
return selectedUsers, true
|
||||||
|
}
|
||||||
|
|
||||||
func (u *Users) findUserByName(pattern string) ([]dbmapping.ProfileWithAddons, bool) {
|
func (u *Users) findUserByName(pattern string) ([]dbmapping.ProfileWithAddons, bool) {
|
||||||
selectedUsers := []dbmapping.ProfileWithAddons{}
|
selectedUsers := []dbmapping.ProfileWithAddons{}
|
||||||
|
|
||||||
@ -59,6 +71,27 @@ func (u *Users) findUserByName(pattern string) ([]dbmapping.ProfileWithAddons, b
|
|||||||
return selectedUsers, true
|
return selectedUsers, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *Users) foundUsersMessage(update *tgbotapi.Update, usersArray []dbmapping.ProfileWithAddons) {
|
||||||
|
message := "*Найденные игроки:*\n"
|
||||||
|
|
||||||
|
for i := range usersArray {
|
||||||
|
message += "#" + strconv.Itoa(usersArray[i].PlayerID)
|
||||||
|
message += " " + usersArray[i].LeagueSymbol
|
||||||
|
message += " " + usersArray[i].Nickname
|
||||||
|
if usersArray[i].TelegramNickname != "" {
|
||||||
|
message += " (@" + u.FormatUsername(usersArray[i].TelegramNickname) + ")"
|
||||||
|
}
|
||||||
|
message += " /profile" + strconv.Itoa(usersArray[i].PlayerID) + "\n"
|
||||||
|
message += "Telegram ID: " + strconv.Itoa(usersArray[i].TelegramID) + "\n"
|
||||||
|
message += "Последнее обновление: " + usersArray[i].CreatedAt.Format("02.01.2006 15:04:05") + "\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
||||||
|
msg.ParseMode = "Markdown"
|
||||||
|
|
||||||
|
c.Bot.Send(msg)
|
||||||
|
}
|
||||||
|
|
||||||
func (u *Users) profileAddSuccessMessage(update *tgbotapi.Update, leagueID int, level int) {
|
func (u *Users) profileAddSuccessMessage(update *tgbotapi.Update, leagueID int, level int) {
|
||||||
message := "*Профиль успешно обновлен.*\n\n"
|
message := "*Профиль успешно обновлен.*\n\n"
|
||||||
message += "Функциональность бота держится на актуальности профилей. Обновляйся почаще, и да пребудет с тобой Рандом!\n"
|
message += "Функциональность бота держится на актуальности профилей. Обновляйся почаще, и да пребудет с тобой Рандом!\n"
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
package usersinterface
|
package usersinterface
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
|
||||||
"git.wtfteam.pro/fat0troll/i2_bot/lib/dbmapping"
|
"git.wtfteam.pro/fat0troll/i2_bot/lib/dbmapping"
|
||||||
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||||
)
|
)
|
||||||
|
|
||||||
// UsersInterface implements Users for importing via appcontex
|
// UsersInterface implements Users for importing via appcontex
|
||||||
@ -20,6 +20,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
|
||||||
|
|
||||||
|
FindByLevel(update *tgbotapi.Update) string
|
||||||
FindByName(update *tgbotapi.Update) string
|
FindByName(update *tgbotapi.Update) string
|
||||||
ForeignProfileMessage(update *tgbotapi.Update) string
|
ForeignProfileMessage(update *tgbotapi.Update) string
|
||||||
FormatUsername(userName string) string
|
FormatUsername(userName string) string
|
||||||
|
Reference in New Issue
Block a user