mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +00:00
BehaviourContext#followLocation
This commit is contained in:
parent
a046a72392
commit
24c47b00d4
@ -13,6 +13,7 @@
|
||||
* `Behaviour Builder`:
|
||||
* All triggers have been changed to use two filters: filter for in subcontext data and filter for incoming data
|
||||
* New waiters for edited content
|
||||
* New extension `BehaviourContext#followLocation`
|
||||
|
||||
## 0.35.8
|
||||
|
||||
|
@ -0,0 +1,30 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.utils
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTypeReceiver
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitEditedLocation
|
||||
import dev.inmo.tgbotapi.types.location.*
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||
import dev.inmo.tgbotapi.types.message.content.LiveLocationContent
|
||||
|
||||
/**
|
||||
* Use this extension when you want to follow [LiveLocation] until it will became [StaticLocation]. This method
|
||||
* is synchronous. You may use something like [kotlinx.coroutines.launch] or [kotlinx.coroutines.async] to run it
|
||||
* asynchronously
|
||||
*/
|
||||
suspend fun BehaviourContext.followLocation(
|
||||
message: ContentMessage<LiveLocationContent>,
|
||||
onLocation: BehaviourContextAndTypeReceiver<Unit, Location>
|
||||
) {
|
||||
var currentLocation: Location = message.content.location
|
||||
onLocation(message.content.location)
|
||||
|
||||
while (currentLocation !is StaticLocation) {
|
||||
currentLocation = waitEditedLocation(
|
||||
filter = {
|
||||
it.messageId == message.messageId && it.chat.id == message.chat.id
|
||||
}
|
||||
).first().location
|
||||
onLocation(currentLocation)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user