mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2024-11-10 02:13:54 +00:00
update sample of MemberUpdatedWatcher bot
This commit is contained in:
parent
777604e5a0
commit
0ec543d5c5
@ -3,6 +3,8 @@ import dev.inmo.tgbotapi.extensions.api.*
|
||||
import dev.inmo.tgbotapi.extensions.api.bot.*
|
||||
import dev.inmo.tgbotapi.extensions.api.send.*
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.chatMemberGotRestrictedFilter
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.chatMemberGotRestrictionsChangedFilter
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.*
|
||||
import dev.inmo.tgbotapi.extensions.utils.*
|
||||
@ -39,47 +41,58 @@ suspend fun main(args: Array<String>) {
|
||||
// This bot updates
|
||||
onChatMemberJoined(initialFilter = filterSelfUpdates) {
|
||||
internalLogger.i("Bot was added to chat")
|
||||
sendMessage(it.chat.id, "I was added to chat. Please grant me admin permissions to make me able to watch other users' events")
|
||||
send(it.chat.id, "I was added to chat. Please grant me admin permissions to make me able to watch other users' events")
|
||||
}
|
||||
|
||||
onChatMemberGotPromoted(initialFilter = filterSelfUpdates) {
|
||||
internalLogger.i("Bot was granted admin permissions")
|
||||
sendMessage(it.chat.id, "I was promoted to admin. I now can watch other users' events")
|
||||
send(it.chat.id, "I was promoted to admin. I now can watch other users' events")
|
||||
}
|
||||
|
||||
onChatMemberGotDemoted(initialFilter = filterSelfUpdates) {
|
||||
internalLogger.i("Admin permissions were revoked")
|
||||
sendMessage(it.chat.id, "I'm no longer an admin. Admin permissions are required to watch other users' events")
|
||||
send(it.chat.id, "I'm no longer an admin. Admin permissions are required to watch other users' events")
|
||||
}
|
||||
|
||||
// All users updates
|
||||
onChatMemberJoined {
|
||||
val member = it.member
|
||||
internalLogger.i("${member.firstName} joined the chat: ${it.oldChatMemberState::class.simpleName} => ${it.newChatMemberState::class.simpleName}")
|
||||
sendMessage(it.chat.id, "Welcome ${member.firstName}")
|
||||
send(it.chat.id, "Welcome ${member.firstName}")
|
||||
}
|
||||
|
||||
onChatMemberLeft {
|
||||
val member = it.member
|
||||
internalLogger.i("${member.firstName} left the chat: ${it.oldChatMemberState::class.simpleName} => ${it.newChatMemberState::class.simpleName}")
|
||||
sendMessage(it.chat.id, "Goodbye ${member.firstName}")
|
||||
send(it.chat.id, "Goodbye ${member.firstName}")
|
||||
}
|
||||
|
||||
onChatMemberGotPromoted {
|
||||
val newState = it.newChatMemberState.administratorChatMemberOrThrow()
|
||||
internalLogger.i("${newState.user.firstName} got promoted to ${newState.customTitle ?: "Admin"}: ${it.oldChatMemberState::class.simpleName} => ${it.newChatMemberState::class.simpleName}")
|
||||
sendMessage(it.chat.id, "${newState.user.firstName} is now an ${newState.customTitle ?: "Admin"}")
|
||||
send(it.chat.id, "${newState.user.firstName} is now an ${newState.customTitle ?: "Admin"}")
|
||||
}
|
||||
|
||||
onChatMemberGotDemoted {
|
||||
val member = it.member
|
||||
internalLogger.i("${member.firstName} got demoted: ${it.oldChatMemberState::class.simpleName} => ${it.newChatMemberState::class.simpleName}")
|
||||
sendMessage(it.chat.id, "${member.firstName} is now got demoted back to member")
|
||||
send(it.chat.id, "${member.firstName} is now got demoted back to member")
|
||||
}
|
||||
|
||||
onChatMemberGotPromotionChanged {
|
||||
val member = it.newChatMemberState.administratorChatMemberOrThrow()
|
||||
internalLogger.i("${member.user.firstName} has the permissions changed: ${it.oldChatMemberState::class.simpleName} => ${it.newChatMemberState::class.simpleName}")
|
||||
val member = it.member
|
||||
val message = "${member.firstName} has the permissions changed: ${it.oldChatMemberState::class.simpleName} => ${it.newChatMemberState::class.simpleName}"
|
||||
internalLogger.i(message)
|
||||
send(it.chat.id, message)
|
||||
}
|
||||
|
||||
onChatMemberUpdated(
|
||||
initialFilter = chatMemberGotRestrictedFilter + chatMemberGotRestrictionsChangedFilter,
|
||||
) {
|
||||
val member = it.member
|
||||
val message = "${member.firstName} has the permissions changed: ${it.oldChatMemberState::class.simpleName} => ${it.newChatMemberState::class.simpleName}"
|
||||
internalLogger.i(message)
|
||||
send(it.chat.id, message)
|
||||
}
|
||||
}.join()
|
||||
}
|
Loading…
Reference in New Issue
Block a user