New restrictions logic for all chats. Fixed filter for /send_league
This commit is contained in:
@@ -199,17 +199,6 @@ func (s *Squader) isUserAnyCommander(playerID int) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *Squader) getCommandersForSquadViaChat(chatRaw *dbmapping.Chat) ([]dbmapping.Player, bool) {
|
||||
commanders := []dbmapping.Player{}
|
||||
err := c.Db.Select(&commanders, c.Db.Rebind("SELECT p.* FROM players p, squads_players sp, squads s WHERE (s.chat_id=? OR s.flood_chat_id=?) AND sp.squad_id = s.id AND sp.user_type = 'commander' AND sp.player_id = p.id"), chatRaw.ID, chatRaw.ID)
|
||||
if err != nil {
|
||||
c.Log.Debug(err.Error())
|
||||
return commanders, false
|
||||
}
|
||||
|
||||
return commanders, true
|
||||
}
|
||||
|
||||
func (s *Squader) squadCreationDuplicate(update *tgbotapi.Update) string {
|
||||
message := "*Отряд уже существует*\n"
|
||||
message += "Проверьте, правильно ли вы ввели команду, и повторите попытку."
|
||||
@@ -380,192 +369,3 @@ func (s *Squader) CreateSquad(update *tgbotapi.Update) string {
|
||||
|
||||
return s.squadCreationSuccess(update)
|
||||
}
|
||||
|
||||
// ProcessMessage handles all squad-specified administration actions
|
||||
func (s *Squader) ProcessMessage(update *tgbotapi.Update, chatRaw *dbmapping.Chat) string {
|
||||
// It will pass message or do some extra actions
|
||||
// If it returns "ok", we can pass message to router, otherwise we will stop here
|
||||
processMain := false
|
||||
processFlood := false
|
||||
messageProcessed := false
|
||||
switch s.IsChatASquadEnabled(chatRaw) {
|
||||
case "main":
|
||||
processMain = true
|
||||
case "flood":
|
||||
processFlood = true
|
||||
default:
|
||||
return "ok"
|
||||
}
|
||||
|
||||
// Kicking non-squad members from any chat
|
||||
if processMain || processFlood {
|
||||
if update.Message.NewChatMembers != nil {
|
||||
newUsers := *update.Message.NewChatMembers
|
||||
if len(newUsers) > 0 {
|
||||
for i := range newUsers {
|
||||
switch strings.ToLower(newUsers[i].UserName) {
|
||||
case "gantz_yaka":
|
||||
messageProcessed = true
|
||||
case "agentpb":
|
||||
messageProcessed = true
|
||||
case "pbhelp":
|
||||
messageProcessed = true
|
||||
default:
|
||||
playerRaw, ok := c.Users.GetOrCreatePlayer(newUsers[i].ID)
|
||||
if !ok {
|
||||
s.kickUserFromSquadChat(&newUsers[i], chatRaw)
|
||||
messageProcessed = true
|
||||
}
|
||||
|
||||
availableChats, ok := s.GetAvailableSquadChatsForUser(&playerRaw)
|
||||
if !ok {
|
||||
s.kickUserFromSquadChat(&newUsers[i], chatRaw)
|
||||
messageProcessed = true
|
||||
}
|
||||
isChatValid := false
|
||||
for i := range availableChats {
|
||||
if *chatRaw == availableChats[i] {
|
||||
isChatValid = true
|
||||
}
|
||||
}
|
||||
if !isChatValid {
|
||||
s.kickUserFromSquadChat(&newUsers[i], chatRaw)
|
||||
messageProcessed = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if processMain {
|
||||
c.Log.Debug("Message found in one of squad's main chats.")
|
||||
talker, ok := c.Users.GetOrCreatePlayer(update.Message.From.ID)
|
||||
if !ok {
|
||||
s.deleteFloodMessage(update)
|
||||
messageProcessed = true
|
||||
}
|
||||
|
||||
if (update.Message.From.UserName != "i2_bot") && (update.Message.From.UserName != "i2_bot_dev") && !s.isUserAnyCommander(talker.ID) {
|
||||
s.deleteFloodMessage(update)
|
||||
messageProcessed = true
|
||||
}
|
||||
}
|
||||
|
||||
if messageProcessed {
|
||||
return "fail"
|
||||
}
|
||||
|
||||
return "ok"
|
||||
}
|
||||
|
||||
// ProtectBastion avoids spies and no-profile players to join Bastion
|
||||
func (s *Squader) ProtectBastion(update *tgbotapi.Update, newUser *tgbotapi.User) string {
|
||||
defaultChatID, _ := strconv.ParseInt(c.Cfg.SpecialChats.DefaultID, 10, 64)
|
||||
|
||||
chatRaw, ok := c.Chatter.GetOrCreateChat(update)
|
||||
if !ok {
|
||||
return "fail"
|
||||
}
|
||||
|
||||
playerRaw, ok := c.Users.GetOrCreatePlayer(newUser.ID)
|
||||
if !ok {
|
||||
switch strings.ToLower(newUser.UserName) {
|
||||
case "gantz_yaka":
|
||||
// do nothing
|
||||
case "agentpb":
|
||||
// do nothing
|
||||
case "pbhelp":
|
||||
// do nothing
|
||||
default:
|
||||
s.kickUserFromSquadChat(newUser, &chatRaw)
|
||||
return "fail"
|
||||
}
|
||||
}
|
||||
|
||||
if playerRaw.LeagueID != 1 {
|
||||
switch newUser.UserName {
|
||||
case "gantz_yaka":
|
||||
message := "Здравствуй, " + newUser.UserName + "!\n"
|
||||
message += "Инстинкт рад приветствовать Бога мира ПокемемБро! Проходите, располагайтесь, чувствуйте себя, как дома.\n"
|
||||
|
||||
msg := tgbotapi.NewMessage(chatRaw.TelegramID, message)
|
||||
msg.ParseMode = "Markdown"
|
||||
|
||||
c.Bot.Send(msg)
|
||||
case "agentpb":
|
||||
message := "Здравствуй, " + newUser.UserName + "!\n"
|
||||
message += "Инстинкт рад приветствовать одного из богов мира ПокемемБро! Проходите, располагайтесь, чувствуйте себя, как дома.\n"
|
||||
|
||||
msg := tgbotapi.NewMessage(chatRaw.TelegramID, message)
|
||||
msg.ParseMode = "Markdown"
|
||||
|
||||
c.Bot.Send(msg)
|
||||
case "pbhelp":
|
||||
message := "Здравствуй, " + newUser.UserName + "!\n"
|
||||
message += "Инстинкт рад приветствовать одного из богов мира ПокемемБро! Проходите, располагайтесь, чувствуйте себя, как дома.\n"
|
||||
|
||||
msg := tgbotapi.NewMessage(chatRaw.TelegramID, message)
|
||||
msg.ParseMode = "Markdown"
|
||||
|
||||
c.Bot.Send(msg)
|
||||
default:
|
||||
// Check for profile
|
||||
_, profileOK := c.Users.GetProfile(playerRaw.ID)
|
||||
if !profileOK {
|
||||
message := "Привет, " + c.Users.GetPrettyName(newUser) + "! Напиши мне и скинь профиль для доступа в чаты Лиги!"
|
||||
|
||||
msg := tgbotapi.NewMessage(defaultChatID, message)
|
||||
msg.ParseMode = "Markdown"
|
||||
|
||||
c.Bot.Send(msg)
|
||||
} else {
|
||||
message := "Привет, " + c.Users.GetPrettyName(newUser) + "! Там переход между лигами не завезли случайно? Переходи в нашу Лигу, будем рады тебя видеть... а пока — вход в наши чаты закрыт!"
|
||||
|
||||
msg := tgbotapi.NewMessage(defaultChatID, message)
|
||||
msg.ParseMode = "Markdown"
|
||||
|
||||
c.Bot.Send(msg)
|
||||
}
|
||||
s.kickUserFromSquadChat(newUser, &chatRaw)
|
||||
return "fail"
|
||||
}
|
||||
}
|
||||
|
||||
return "ok"
|
||||
}
|
||||
|
||||
// FilterBastion kicks already joined user if he changed league
|
||||
func (s *Squader) FilterBastion(update *tgbotapi.Update) string {
|
||||
user := update.Message.From
|
||||
chatRaw, ok := c.Chatter.GetOrCreateChat(update)
|
||||
if !ok {
|
||||
return "fail"
|
||||
}
|
||||
|
||||
playerRaw, playerOK := c.Users.GetOrCreatePlayer(update.Message.From.ID)
|
||||
if !playerOK {
|
||||
s.kickUserFromSquadChat(user, &chatRaw)
|
||||
return "fail"
|
||||
}
|
||||
_, profileOK := c.Users.GetProfile(playerRaw.ID)
|
||||
if !profileOK {
|
||||
s.kickUserFromSquadChat(user, &chatRaw)
|
||||
return "fail"
|
||||
}
|
||||
if playerRaw.LeagueID != 1 {
|
||||
switch strings.ToLower(user.UserName) {
|
||||
case "gantz_yaka":
|
||||
// do nothing
|
||||
case "agentpb":
|
||||
// do nothing
|
||||
case "pbhelp":
|
||||
// do nothing
|
||||
default:
|
||||
s.kickUserFromSquadChat(user, &chatRaw)
|
||||
return "fail"
|
||||
}
|
||||
}
|
||||
|
||||
return "ok"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user