@@ -16,6 +16,7 @@ import com.github.mmvpm.bot.model.{ChatID, MessageID}
16
16
import com .github .mmvpm .bot .render .Renderer
17
17
import com .github .mmvpm .bot .state .State ._
18
18
import com .github .mmvpm .bot .state .{State , StateManager , Storage }
19
+ import com .github .mmvpm .model .OfferStatus
19
20
import sttp .client3 .SttpBackend
20
21
21
22
import scala .util .Try
@@ -80,18 +81,24 @@ class OfferServiceBot[F[_]: Concurrent](
80
81
}
81
82
82
83
private def replyResolved (tag : String )(implicit message : Message ): F [Unit ] =
83
- for {
84
- nextState <- stateManager.getNextState(tag, stateStorage.get)
85
- _ = stateStorage.set(withoutError(nextState))
86
- replies = renderer.render(nextState, lastMessageStorage.get, lastPhotosStorage.get)
87
- _ <- requestLogged(replies)
88
- } yield ()
84
+ Concurrent [F ].ifM(isUserBanned)(
85
+ reply(
86
+ """
87
+ |Вы были забанены за неоднократное нарушение правил сервиса
88
+ |
89
+ |Связаться с поддержкой: @mmvpm
90
+ |""" .stripMargin
91
+ ).void,
92
+ for {
93
+ nextState <- stateManager.getNextState(tag, stateStorage.get)
94
+ _ = stateStorage.set(withoutError(nextState))
95
+ replies = renderer.render(nextState, lastMessageStorage.get, lastPhotosStorage.get)
96
+ _ <- requestLogged(replies)
97
+ } yield ()
98
+ )
89
99
90
- private def withoutError (state : State ): State =
91
- state match {
92
- case Error (returnTo, _) => returnTo
93
- case _ => state
94
- }
100
+ private def fail (implicit message : Message ): F [Unit ] =
101
+ reply(" Не понял вас :(" ).void
95
102
96
103
// internal
97
104
@@ -140,8 +147,11 @@ class OfferServiceBot[F[_]: Concurrent](
140
147
case ChatId .Channel (_) => sys.error(" channels are not supported" )
141
148
}
142
149
143
- private def fail (implicit message : Message ): F [Unit ] =
144
- reply(" Не понял вас :(" ).void
150
+ private def withoutError (state : State ): State =
151
+ state match {
152
+ case Error (returnTo, _) => returnTo
153
+ case _ => state
154
+ }
145
155
146
156
private def safe [A ](block : => A , default : A ): A =
147
157
Try {
@@ -150,4 +160,13 @@ class OfferServiceBot[F[_]: Concurrent](
150
160
logger.error(" Bot failed" , error)
151
161
default
152
162
}.get
163
+
164
+ private def isUserBanned (implicit message : Message ): F [Boolean ] =
165
+ ofsManager.getMyOffers.value.map {
166
+ case Left (error) =>
167
+ println(s " isUserBanned failed with $error" )
168
+ false
169
+ case Right (offers) =>
170
+ offers.count(_.status == OfferStatus .Banned ) >= 5
171
+ }
153
172
}
0 commit comments