Old comments removed
This commit is contained in:
parent
0034b21905
commit
73f3cd22c5
2 changed files with 5 additions and 12 deletions
|
@ -66,12 +66,9 @@ class Bot(val token: String) extends TelegramBot
|
||||||
*/
|
*/
|
||||||
def fromAdmin(msg: Message): Boolean =
|
def fromAdmin(msg: Message): Boolean =
|
||||||
if (fromActualUser(msg) && fromGroup(msg)) {
|
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)
|
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
|
user.isAdmin || user.isCreator
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
@ -80,12 +77,9 @@ class Bot(val token: String) extends TelegramBot
|
||||||
|
|
||||||
def canBan(msg: Message): Boolean =
|
def canBan(msg: Message): Boolean =
|
||||||
if (fromActualUser(msg) && fromGroup(msg)) {
|
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)
|
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
|
user.canBanUsers
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
|
|
@ -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))
|
bot.request(UnbanChatMember(ChatId.fromChat(chat.id), user.id))
|
||||||
}
|
}
|
||||||
|
|
||||||
// lazy attribute initialized on the first successful request
|
|
||||||
private var chatMember : ChatMember = {
|
private var chatMember : ChatMember = {
|
||||||
val maxRetryTimes: Int = 10
|
val maxRetryTimes: Int = 10
|
||||||
var chatMember: ChatMember = null
|
var chatMember: ChatMember = null
|
||||||
|
|
||||||
breakable {
|
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 {
|
Await.ready(bot.request(GetChatMember(ChatId.fromChat(chat.id), user.id)), Duration.Inf).value.get match {
|
||||||
case Success(cm) => {
|
case Success(cm) => {
|
||||||
chatMember = cm
|
chatMember = cm
|
||||||
|
|
Loading…
Reference in a new issue