diff --git a/lib/router/group_request.go b/lib/router/group_request.go index a38956c..4d9db21 100644 --- a/lib/router/group_request.go +++ b/lib/router/group_request.go @@ -8,6 +8,7 @@ import ( "lab.pztrn.name/fat0troll/i2_bot/lib/dbmapping" "math/rand" "regexp" + "strconv" ) func (r *Router) routeGroupRequest(update *tgbotapi.Update, playerRaw *dbmapping.Player, chatRaw *dbmapping.Chat) string { @@ -24,6 +25,11 @@ func (r *Router) routeGroupRequest(update *tgbotapi.Update, playerRaw *dbmapping return squadHandled } + bastionChatID, _ := strconv.ParseInt(c.Cfg.SpecialChats.BastionID, 10, 64) + if update.Message.Chat.ID == bastionChatID { + c.Squader.FilterBastion(update) + } + // Welcomes if update.Message.NewChatMembers != nil { newUsers := *update.Message.NewChatMembers diff --git a/lib/squader/squader.go b/lib/squader/squader.go index fed3ae4..62eb01f 100644 --- a/lib/squader/squader.go +++ b/lib/squader/squader.go @@ -594,3 +594,29 @@ func (s *Squader) ProtectBastion(update *tgbotapi.Update, newUser *tgbotapi.User 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 { + s.kickUserFromSquadChat(user, &chatRaw) + return "fail" + } + + return "ok" +} diff --git a/lib/squader/squaderinterface/squaderinterface.go b/lib/squader/squaderinterface/squaderinterface.go index c27dec5..55df281 100644 --- a/lib/squader/squaderinterface/squaderinterface.go +++ b/lib/squader/squaderinterface/squaderinterface.go @@ -28,4 +28,5 @@ type SquaderInterface interface { ProcessMessage(update *tgbotapi.Update, chatRaw *dbmapping.Chat) string ProtectBastion(update *tgbotapi.Update, newUser *tgbotapi.User) string + FilterBastion(update *tgbotapi.Update) string }