2017-11-24 00:16:22 +04:00
|
|
|
|
// i2_bot – Instinct PokememBro Bot
|
|
|
|
|
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
|
|
|
|
|
|
|
|
|
package squader
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
|
|
|
|
"lab.pztrn.name/fat0troll/i2_bot/lib/dbmapping"
|
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// SquadsList lists all squads
|
|
|
|
|
func (s *Squader) SquadsList(update *tgbotapi.Update, playerRaw *dbmapping.Player) string {
|
|
|
|
|
if !c.Users.PlayerBetterThan(playerRaw, "admin") {
|
|
|
|
|
if s.isUserAnyCommander(playerRaw.ID) {
|
2017-11-25 03:00:34 +04:00
|
|
|
|
return c.Talkers.AnyMessageUnauthorized(update)
|
2017-11-24 00:16:22 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
squads, ok := s.getAllSquadsWithChats()
|
|
|
|
|
if !ok {
|
|
|
|
|
return "fail"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
message := "*Наши отряды:*\n"
|
2017-11-26 17:28:26 +04:00
|
|
|
|
message += "---\n"
|
|
|
|
|
message += "[#0] _Бастион Инстинкта_\n"
|
|
|
|
|
message += "Telegram ID: " + c.Cfg.SpecialChats.BastionID + "\n"
|
|
|
|
|
message += "Игроки по умолчанию оказываются здесь.\n"
|
2017-11-24 00:16:22 +04:00
|
|
|
|
|
|
|
|
|
for i := range squads {
|
|
|
|
|
message += "---\n"
|
|
|
|
|
message += "[#" + strconv.Itoa(squads[i].Squad.ID) + "] _" + squads[i].Chat.Name
|
|
|
|
|
message += "_ /show\\_squad" + strconv.Itoa(squads[i].Squad.ID) + "\n"
|
|
|
|
|
message += "Telegram ID: " + strconv.FormatInt(squads[i].Chat.TelegramID, 10) + "\n"
|
|
|
|
|
message += "Флудилка отряда: _" + squads[i].FloodChat.Name + "_\n"
|
|
|
|
|
message += "Статистика отряда:\n"
|
|
|
|
|
message += c.Statistics.SquadStatictics(squads[i].Squad.ID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
|
|
|
|
msg.ParseMode = "Markdown"
|
|
|
|
|
|
|
|
|
|
c.Bot.Send(msg)
|
|
|
|
|
|
|
|
|
|
return "ok"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SquadInfo returns statistic and list of squad players
|
|
|
|
|
func (s *Squader) SquadInfo(update *tgbotapi.Update, playerRaw *dbmapping.Player) string {
|
|
|
|
|
squadNumber := strings.Replace(update.Message.Text, "/show_squad", "", 1)
|
|
|
|
|
squadID, _ := strconv.Atoi(squadNumber)
|
|
|
|
|
if squadID == 0 {
|
|
|
|
|
squadID = 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !c.Users.PlayerBetterThan(playerRaw, "admin") {
|
|
|
|
|
if s.getUserRoleForSquad(squadID, playerRaw.ID) != "commander" {
|
2017-11-25 03:00:34 +04:00
|
|
|
|
return c.Talkers.AnyMessageUnauthorized(update)
|
2017-11-24 00:16:22 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
squad, ok := s.GetSquadByID(squadID)
|
|
|
|
|
if !ok {
|
2017-11-25 03:00:34 +04:00
|
|
|
|
return c.Talkers.BotError(update)
|
2017-11-24 00:16:22 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
message := "*Информация об отряде* _" + squad.Chat.Name + "_*:*\n"
|
|
|
|
|
message += c.Statistics.SquadStatictics(squad.Squad.ID)
|
|
|
|
|
message += "\n"
|
|
|
|
|
|
|
|
|
|
squadMembers, ok := s.getPlayersForSquad(squad.Squad.ID)
|
|
|
|
|
if !ok {
|
|
|
|
|
return "fail"
|
|
|
|
|
}
|
|
|
|
|
if len(squadMembers) > 0 {
|
|
|
|
|
message += "Участники отряда:\n"
|
|
|
|
|
for i := range squadMembers {
|
|
|
|
|
message += "#" + strconv.Itoa(squadMembers[i].Player.ID)
|
|
|
|
|
if squadMembers[i].UserRole == "commander" {
|
|
|
|
|
message += " \\[К]"
|
|
|
|
|
}
|
2017-11-26 16:17:21 +04:00
|
|
|
|
if squadMembers[i].Player.Status == "special" {
|
|
|
|
|
message += " _суперюзер_"
|
|
|
|
|
} else {
|
|
|
|
|
message += " " + squadMembers[i].Profile.Nickname + " "
|
|
|
|
|
if squadMembers[i].Profile.TelegramNickname != "" {
|
|
|
|
|
message += "(@" + c.Users.FormatUsername(squadMembers[i].Profile.TelegramNickname) + ")"
|
|
|
|
|
}
|
2017-11-24 00:16:22 +04:00
|
|
|
|
}
|
|
|
|
|
message += " ⚔" + strconv.Itoa(squadMembers[i].Profile.Power)
|
|
|
|
|
message += "\n"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
|
|
|
|
msg.ParseMode = "Markdown"
|
|
|
|
|
|
|
|
|
|
c.Bot.Send(msg)
|
|
|
|
|
|
|
|
|
|
return "ok"
|
|
|
|
|
}
|