ekardnam 4 лет назад
Родитель
Сommit
73f3cd22c5

+ 4 - 10
src/main/scala/org/congressodeiradicali/karlmarx/Bot.scala

@@ -66,12 +66,9 @@ class Bot(val token: String) extends TelegramBot
     */
   def fromAdmin(msg: Message): Boolean =
     if (fromActualUser(msg) && fromGroup(msg)) {
-      // it should be an actual user and a message from a group
-      // check the user member status
-      // get is safe as fromActualUser is called first
+
       val user = new BotUser(msg.from.get, msg.chat, this)
-      // if there is an error we cannot now whether the user is an admin or not
-      // but it's safe in any case to reply as if the user was not an admin
+
       user.isAdmin || user.isCreator
     } else {
       false
@@ -80,12 +77,9 @@ class Bot(val token: String) extends TelegramBot
 
   def canBan(msg: Message): Boolean =
     if (fromActualUser(msg) && fromGroup(msg)) {
-      // it should be an actual user and a message from a group
-      // check the user member status
-      // get is safe as fromActualUser is called first
+
       val user = new BotUser(msg.from.get, msg.chat, this)
-      // if there is an error we cannot now whether the user is an admin or not
-      // but it's safe in any case to reply as if the user was not an admin
+
       user.canBanUsers
     } else {
       false

+ 1 - 2
src/main/scala/org/congressodeiradicali/karlmarx/BotUser.scala

@@ -39,13 +39,12 @@ class BotUser(private val user: User, private val chat: Chat, private val bot: B
     bot.request(UnbanChatMember(ChatId.fromChat(chat.id), user.id))
   }
 
-  // lazy attribute initialized on the first successful request
   private var chatMember : ChatMember = {
     val maxRetryTimes: Int = 10
     var chatMember: ChatMember = null
 
     breakable {
-      for (time <- 0 to maxRetryTimes) {
+      for (_ <- 0 to maxRetryTimes) {
         Await.ready(bot.request(GetChatMember(ChatId.fromChat(chat.id), user.id)), Duration.Inf).value.get match {
           case Success(cm) => {
             chatMember = cm