1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2025-09-02 22:59:48 +00:00

final refactor, fixes and upfilling of changelog

This commit is contained in:
2021-06-28 11:10:09 +06:00
parent 21c5d42dc2
commit fd6e4b0522
6 changed files with 39 additions and 37 deletions

View File

@@ -1,21 +0,0 @@
package dev.inmo.tgbotapi.extensions.behaviour_builder.utils
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
import kotlinx.coroutines.CoroutineScope
internal fun <T> CoroutineScope.wrapWithLaunch(
block: suspend (T) -> Unit
): suspend (T) -> Unit = {
launchSafelyWithoutExceptions {
block(it)
}
}
internal fun <T> CoroutineScope.optionallyWrapWithLaunch(
wrap: Boolean,
block: suspend (T) -> Unit
): suspend (T) -> Unit = if (wrap) {
wrapWithLaunch(block)
} else {
block
}

View File

@@ -1,7 +1,15 @@
package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories
import dev.inmo.tgbotapi.types.message.abstracts.Message
import dev.inmo.tgbotapi.types.message.abstracts.*
object ByChatMessageMarkerFactory : MarkerFactory<Message, Any> {
override suspend fun invoke(data: Message) = data.chat
}
object ByUserMessageMarkerFactory : MarkerFactory<Message, Any> {
override suspend fun invoke(data: Message) = when (data) {
is FromUserMessage -> data.user
is FromChannelGroupContentMessage<*> -> data.channel
else -> data.chat // including anonymous
}
}