diff --git a/lib/router/group_request.go b/lib/router/group_request.go index 4d9db21..959b1df 100644 --- a/lib/router/group_request.go +++ b/lib/router/group_request.go @@ -74,5 +74,10 @@ func (r *Router) routeGroupRequest(update *tgbotapi.Update, playerRaw *dbmapping } } + switch { + case update.Message.Command() == "long": + c.Talkers.LongMessage(update) + } + return "ok" } diff --git a/lib/router/private_request.go b/lib/router/private_request.go index 1089462..95543c9 100644 --- a/lib/router/private_request.go +++ b/lib/router/private_request.go @@ -134,7 +134,7 @@ func (r *Router) routePrivateRequest(update *tgbotapi.Update, playerRaw *dbmappi } return c.Talkers.AnyMessageUnauthorized(update) - + case profileMsg.MatchString(text): if c.Users.PlayerBetterThan(playerRaw, "academic") { return c.Users.ForeignProfileMessage(update) @@ -142,6 +142,13 @@ func (r *Router) routePrivateRequest(update *tgbotapi.Update, playerRaw *dbmappi return c.Talkers.AnyMessageUnauthorized(update) + case update.Message.Command() == "find_user": + if c.Users.PlayerBetterThan(playerRaw, "academic") { + return c.Users.FindByName(update) + } + + return c.Talkers.AnyMessageUnauthorized(update) + case update.Message.Command() == "squad_add_user": return c.Squader.AddUserToSquad(update, playerRaw) case update.Message.Command() == "squad_add_commander": diff --git a/lib/talkers/easter.go b/lib/talkers/easter.go index a62d429..f2e9906 100644 --- a/lib/talkers/easter.go +++ b/lib/talkers/easter.go @@ -9,6 +9,16 @@ import ( "time" ) +// LongMessage is an easter egg +func (t *Talkers) LongMessage(update *tgbotapi.Update) { + message := "Я ТЕБЕ НЕ ЗЕЛЁНЫЙ АКСОЛОТЛЬ! А ТЫ - НЕ ЦИФЕРКА!" + + msg := tgbotapi.NewMessage(update.Message.Chat.ID, message) + msg.ReplyToMessageID = update.Message.MessageID + + c.Bot.Send(msg) +} + // DurakMessage is an easter egg func (t *Talkers) DurakMessage(update *tgbotapi.Update) { reactions := make([]string, 0) diff --git a/lib/talkers/help.go b/lib/talkers/help.go index 996f982..baa1c38 100644 --- a/lib/talkers/help.go +++ b/lib/talkers/help.go @@ -28,6 +28,7 @@ func (t *Talkers) HelpMessage(update *tgbotapi.Update, playerRaw *dbmapping.Play } if c.Users.PlayerBetterThan(playerRaw, "academic") { message += "+ /users — просмотреть зарегистрированных пользователей бота\n" + message += "+ /find\\_user _строка_ — найти игрока в боте по его нику или имени. Ник ищется без собачки в начале\n" } message += "+ /help – выводит данное сообщение\n" diff --git a/lib/talkers/talkersinterface/talkersinterface.go b/lib/talkers/talkersinterface/talkersinterface.go index a8c8961..083f950 100644 --- a/lib/talkers/talkersinterface/talkersinterface.go +++ b/lib/talkers/talkersinterface/talkersinterface.go @@ -16,6 +16,7 @@ type TalkersInterface interface { AnyMessageUnauthorized(update *tgbotapi.Update) string BotError(update *tgbotapi.Update) string + LongMessage(update *tgbotapi.Update) DurakMessage(update *tgbotapi.Update) MatMessage(update *tgbotapi.Update) } diff --git a/lib/users/responders.go b/lib/users/responders.go index 0662d8e..3e0d92e 100644 --- a/lib/users/responders.go +++ b/lib/users/responders.go @@ -15,6 +15,43 @@ func (u *Users) FormatUsername(userName string) string { return strings.Replace(userName, "_", "\\_", -1) } +// FindByName finds user with such username or nickname +func (u *Users) FindByName(update *tgbotapi.Update) string { + commandArgs := update.Message.CommandArguments() + if commandArgs == "" { + c.Talkers.BotError(update) + return "fail" + } + + usersArray, ok := u.findUserByName(commandArgs) + if !ok { + return "fail" + } + + message := "*Найденные игроки:*\n" + + for i := range usersArray { + message += "#" + strconv.Itoa(usersArray[i].Player.ID) + message += " " + usersArray[i].League.Symbol + message += " " + usersArray[i].Profile.Nickname + if usersArray[i].Profile.TelegramNickname != "" { + message += " (@" + u.FormatUsername(usersArray[i].Profile.TelegramNickname) + ")" + } + 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" + } + + c.Log.Debug(message) + + msg := tgbotapi.NewMessage(update.Message.Chat.ID, message) + msg.ParseMode = "Markdown" + + c.Bot.Send(msg) + + return "ok" +} + // ForeignProfileMessage shows profile of another user func (u *Users) ForeignProfileMessage(update *tgbotapi.Update) string { userNum := strings.TrimPrefix(update.Message.Command(), "profile") diff --git a/lib/users/users.go b/lib/users/users.go index 5106e6a..45f89cd 100644 --- a/lib/users/users.go +++ b/lib/users/users.go @@ -7,6 +7,7 @@ import ( "github.com/go-telegram-bot-api/telegram-bot-api" "lab.pztrn.name/fat0troll/i2_bot/lib/dbmapping" "strconv" + "strings" ) // Internal functions for Users package @@ -47,6 +48,26 @@ func (u *Users) getUsersWithProfiles() ([]dbmapping.PlayerProfile, bool) { return usersArray, true } +func (u *Users) findUserByName(pattern string) ([]dbmapping.PlayerProfile, bool) { + allUsers, ok := u.getUsersWithProfiles() + if !ok { + return allUsers, ok + } + + selectedUsers := []dbmapping.PlayerProfile{} + + for i := range allUsers { + user := allUsers[i] + if user.HaveProfile { + if strings.Contains(user.Profile.TelegramNickname, pattern) || strings.Contains(user.Profile.Nickname, pattern) { + selectedUsers = append(selectedUsers, user) + } + } + } + + return selectedUsers, true +} + func (u *Users) profileAddSuccessMessage(update *tgbotapi.Update, leagueID int, level int) { message := "*Профиль успешно обновлен.*\n\n" message += "Функциональность бота держится на актуальности профилей. Обновляйся почаще, и да пребудет с тобой Рандом!\n" @@ -54,9 +75,10 @@ func (u *Users) profileAddSuccessMessage(update *tgbotapi.Update, leagueID int, message += "/best – посмотреть лучших покемемов для поимки" if leagueID == 1 { - message += "\nЗаходи в Бастион Инстинкта: https://t.me/joinchat/G2vME0mIX-QHjjxE\\_JBzoQ\n" - if level < 5 { - message += "\nАкадемия Инстинкта: все вопросы по игре, обучение и помощь новичку: https://t.me/joinchat/G2vME04jk02v2etRmumylg\n" + if level < 4 { + message += "\nЗаходи в Академию Инстинкта: все вопросы по игре, обучение и помощь новичку: https://t.me/joinchat/G2vME04jk02v2etRmumylg\n" + } else { + message += "\nЗаходи в Бастион Инстинкта: https://t.me/joinchat/G2vME0mIX-QHjjxE\\_JBzoQ\n" } } diff --git a/lib/users/usersinterface/usersinterface.go b/lib/users/usersinterface/usersinterface.go index 431d2b4..58f6ddf 100644 --- a/lib/users/usersinterface/usersinterface.go +++ b/lib/users/usersinterface/usersinterface.go @@ -19,6 +19,7 @@ type UsersInterface interface { GetPlayerByID(playerID int) (dbmapping.Player, bool) PlayerBetterThan(playerRaw *dbmapping.Player, powerLevel string) bool + FindByName(update *tgbotapi.Update) string ForeignProfileMessage(update *tgbotapi.Update) string FormatUsername(userName string) string ProfileMessage(update *tgbotapi.Update, playerRaw *dbmapping.Player) string