Useing Option[T] instead of nullable value
This commit is contained in:
parent
36d44f006f
commit
263f1139b3
1 changed files with 7 additions and 7 deletions
|
@ -37,13 +37,13 @@ class BotUser(private val user: User, private val chat: Chat, private val bot: B
|
|||
bot.request(UnbanChatMember(ChatId.fromChat(chat.id), user.id))
|
||||
}
|
||||
|
||||
var chatMember: ChatMember = null
|
||||
var chatMember: Option[ChatMember] = None
|
||||
|
||||
def init() : Future[Try[Unit]] = Future {
|
||||
blocking {
|
||||
Await.ready(bot.request(GetChatMember(ChatId.fromChat(chat.id), user.id)), Duration.Inf).value.get match {
|
||||
case Success(cm) => {
|
||||
chatMember = cm
|
||||
chatMember = Some(cm)
|
||||
Success()
|
||||
}
|
||||
case Failure(err) => {
|
||||
|
@ -63,12 +63,12 @@ class BotUser(private val user: User, private val chat: Chat, private val bot: B
|
|||
}
|
||||
}
|
||||
|
||||
def isCreator: Boolean = if (chatMember != null) chatMember.status == MemberStatus.Creator else false
|
||||
def isAdmin : Boolean = if (chatMember != null) chatMember.status == MemberStatus.Administrator else false
|
||||
def isMember : Boolean = if (chatMember != null) chatMember.status == MemberStatus.Member else false
|
||||
def isKicked : Boolean = if (chatMember != null) chatMember.status == MemberStatus.Kicked else false
|
||||
def isCreator: Boolean = chatMember.exists {cm => cm.status == MemberStatus.Creator}
|
||||
def isAdmin: Boolean = chatMember.exists {cm => cm.status == MemberStatus.Administrator}
|
||||
def isMember: Boolean = chatMember.exists {cm => cm.status == MemberStatus.Member}
|
||||
def isKicked: Boolean = chatMember.exists {cm => cm.status == MemberStatus.Kicked}
|
||||
|
||||
def canBanUsers : Boolean = if (chatMember != null) chatMember.canRestrictMembers.getOrElse(false) else false
|
||||
def canBanUsers : Boolean = chatMember.exists {cm => cm.canRestrictMembers.getOrElse(false)}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue