1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 08:13:47 +00:00

final refactor, fixes and upfilling of changelog

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

View File

@ -6,15 +6,25 @@
* `Version`:
* `Kotlin`: `1.5.10` -> `1.5.20`
* `MicroUtils`: `0.5.6` -> `0.5.15`
* `Core`:
* New interface `MyCommandsRequest` (also see `Bot API 5.3` below)
* `Behaviour Builder`:
* ❗️ All triggers (`on*` extensions) have been modified to work in parallel by some marker by default (new parameter
`markerFactory`, in most cases will work async for different chats)
* New extensions `telegramBotWithBehaviour`
* All triggers (`on*` extensions) have been modified to work in parallel by default (new parameter
`performInParallel`, by default `true`)
* All behaviour builder extensions got new parameter `defaultExceptionsHandler`
* Class `BehaviourContext` was rewritten as an interface with default realization `DefaultBehaviourContext` and
factory `BehaviourContext(TelegramBot, CoroutineScope, FlowsUpdatesFilter)`
factory `BehaviourContext(TelegramBot, CoroutineScope, FlowsUpdatesFilter)`
* Extension `buildBehaviour` (and all related extensions/functions) for opportunity to pass
`defaultExceptionsHandler`
* Trigger `onContentMessage` now may include media groups
* `API`:
* All `reply` and subsequent extension have been replaced in send package
* All `reply` and subsequent extensions have been replaced in send package
* `Utils`:
* With class casts like `as*` and `require*` now you may use `when*` with parameter callback
* Methods of `EntitiesBuilder` now will return builder itself, so you may create sequences like
`buildEntities { bold("Hello,") + italic(" world") }` directly in `buildEntities` body
* New extension `TelegramBot#longPollingFlow` has been added with returning value `Flow` with updates
* `Bot API 5.3`:
* Add type `BotCommandScope`, its serializer `BotCommandScopeSerializer` and all its children
* New request `DeleteMyCommands` and updates in `GetMyCommands` and `SetMyCommands`

View File

@ -18,14 +18,14 @@ private class SurrogateBotCommandScope(
val userId: UserId? = null
) {
fun asBotCommandScope() = when (type) {
"default" -> BotCommandScopeDefault
"all_private_chats" -> BotCommandScopeAllPrivateChats
"all_group_chats" -> BotCommandScopeAllGroupChats
"all_chat_administrators" -> BotCommandScopeAllChatAdministrators
"chat_administrators" -> BotCommandScopeChatAdministrators(
BotCommandScopeDefault.type -> BotCommandScopeDefault
BotCommandScopeAllPrivateChats.type -> BotCommandScopeAllPrivateChats
BotCommandScopeAllGroupChats.type -> BotCommandScopeAllGroupChats
BotCommandScopeAllChatAdministrators.type -> BotCommandScopeAllChatAdministrators
BotCommandScopeChatAdministrators.type -> BotCommandScopeChatAdministrators(
chatId ?: error("chat_administrators type must have $chatIdField field, but have no")
)
"chat_member" -> BotCommandScopeChatMember(
BotCommandScopeChatMember.type -> BotCommandScopeChatMember(
chatId ?: error("chat_administrators type must have $chatIdField field, but have no"),
userId ?: error("chat_administrators type must have $userIdField field, but have no")
)
@ -89,7 +89,10 @@ data class BotCommandScopeChatAdministrators(
override val chatId: ChatIdentifier
) : ChatBotCommandScope {
@Required
override val type: String = "chat_administrators"
override val type: String = BotCommandScopeChatAdministrators.type
companion object {
const val type = "chat_administrators"
}
}
@Serializable
@ -98,13 +101,15 @@ data class BotCommandScopeChatMember(
val userId: UserId
) : ChatBotCommandScope {
@Required
override val type: String = "chat_member"
override val type: String = BotCommandScopeChatMember.type
companion object {
const val type = "chat_member"
}
}
object BotCommandScopeSerializer : KSerializer<BotCommandScope> {
@RiskFeature
override val descriptor: SerialDescriptor = SurrogateBotCommandScope.serializer().descriptor
override fun deserialize(

View File

@ -42,7 +42,7 @@ fun FlowsUpdatesFilter(
broadcastChannelsSize: Int = 100
) = DefaultFlowsUpdatesFilter(broadcastChannelsSize)
@Suppress("EXPERIMENTAL_API_USAGE", "unused")
@Suppress("unused")
class DefaultFlowsUpdatesFilter(
broadcastChannelsSize: Int = 100,
onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND

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
}
}

View File

@ -52,7 +52,7 @@ class EntitiesBuilder internal constructor(
operator fun plus(sources: Iterable<TextSource>) = addAll(sources)
operator fun plus(other: EntitiesBuilder) = if (other == this) {
// do nothing; assume user
// do nothing; assume user is using something like regular("Hello, ") + bold("world") in buildEntities
this
} else {
addAll(other.entitiesList)