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:
parent
21c5d42dc2
commit
fd6e4b0522
18
CHANGELOG.md
18
CHANGELOG.md
@ -6,15 +6,25 @@
|
|||||||
* `Version`:
|
* `Version`:
|
||||||
* `Kotlin`: `1.5.10` -> `1.5.20`
|
* `Kotlin`: `1.5.10` -> `1.5.20`
|
||||||
* `MicroUtils`: `0.5.6` -> `0.5.15`
|
* `MicroUtils`: `0.5.6` -> `0.5.15`
|
||||||
|
* `Core`:
|
||||||
|
* New interface `MyCommandsRequest` (also see `Bot API 5.3` below)
|
||||||
* `Behaviour Builder`:
|
* `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`
|
* 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`
|
* All behaviour builder extensions got new parameter `defaultExceptionsHandler`
|
||||||
* Class `BehaviourContext` was rewritten as an interface with default realization `DefaultBehaviourContext` and
|
* 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`:
|
* `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`:
|
* `Bot API 5.3`:
|
||||||
* Add type `BotCommandScope`, its serializer `BotCommandScopeSerializer` and all its children
|
* Add type `BotCommandScope`, its serializer `BotCommandScopeSerializer` and all its children
|
||||||
* New request `DeleteMyCommands` and updates in `GetMyCommands` and `SetMyCommands`
|
* New request `DeleteMyCommands` and updates in `GetMyCommands` and `SetMyCommands`
|
||||||
|
@ -18,14 +18,14 @@ private class SurrogateBotCommandScope(
|
|||||||
val userId: UserId? = null
|
val userId: UserId? = null
|
||||||
) {
|
) {
|
||||||
fun asBotCommandScope() = when (type) {
|
fun asBotCommandScope() = when (type) {
|
||||||
"default" -> BotCommandScopeDefault
|
BotCommandScopeDefault.type -> BotCommandScopeDefault
|
||||||
"all_private_chats" -> BotCommandScopeAllPrivateChats
|
BotCommandScopeAllPrivateChats.type -> BotCommandScopeAllPrivateChats
|
||||||
"all_group_chats" -> BotCommandScopeAllGroupChats
|
BotCommandScopeAllGroupChats.type -> BotCommandScopeAllGroupChats
|
||||||
"all_chat_administrators" -> BotCommandScopeAllChatAdministrators
|
BotCommandScopeAllChatAdministrators.type -> BotCommandScopeAllChatAdministrators
|
||||||
"chat_administrators" -> BotCommandScopeChatAdministrators(
|
BotCommandScopeChatAdministrators.type -> BotCommandScopeChatAdministrators(
|
||||||
chatId ?: error("chat_administrators type must have $chatIdField field, but have no")
|
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"),
|
chatId ?: error("chat_administrators type must have $chatIdField field, but have no"),
|
||||||
userId ?: error("chat_administrators type must have $userIdField 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
|
override val chatId: ChatIdentifier
|
||||||
) : ChatBotCommandScope {
|
) : ChatBotCommandScope {
|
||||||
@Required
|
@Required
|
||||||
override val type: String = "chat_administrators"
|
override val type: String = BotCommandScopeChatAdministrators.type
|
||||||
|
companion object {
|
||||||
|
const val type = "chat_administrators"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@ -98,13 +101,15 @@ data class BotCommandScopeChatMember(
|
|||||||
val userId: UserId
|
val userId: UserId
|
||||||
) : ChatBotCommandScope {
|
) : ChatBotCommandScope {
|
||||||
@Required
|
@Required
|
||||||
override val type: String = "chat_member"
|
override val type: String = BotCommandScopeChatMember.type
|
||||||
|
companion object {
|
||||||
|
const val type = "chat_member"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
object BotCommandScopeSerializer : KSerializer<BotCommandScope> {
|
object BotCommandScopeSerializer : KSerializer<BotCommandScope> {
|
||||||
|
|
||||||
@RiskFeature
|
|
||||||
override val descriptor: SerialDescriptor = SurrogateBotCommandScope.serializer().descriptor
|
override val descriptor: SerialDescriptor = SurrogateBotCommandScope.serializer().descriptor
|
||||||
|
|
||||||
override fun deserialize(
|
override fun deserialize(
|
||||||
|
@ -42,7 +42,7 @@ fun FlowsUpdatesFilter(
|
|||||||
broadcastChannelsSize: Int = 100
|
broadcastChannelsSize: Int = 100
|
||||||
) = DefaultFlowsUpdatesFilter(broadcastChannelsSize)
|
) = DefaultFlowsUpdatesFilter(broadcastChannelsSize)
|
||||||
|
|
||||||
@Suppress("EXPERIMENTAL_API_USAGE", "unused")
|
@Suppress("unused")
|
||||||
class DefaultFlowsUpdatesFilter(
|
class DefaultFlowsUpdatesFilter(
|
||||||
broadcastChannelsSize: Int = 100,
|
broadcastChannelsSize: Int = 100,
|
||||||
onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND
|
onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND
|
||||||
|
@ -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
|
|
||||||
}
|
|
@ -1,7 +1,15 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories
|
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> {
|
object ByChatMessageMarkerFactory : MarkerFactory<Message, Any> {
|
||||||
override suspend fun invoke(data: Message) = data.chat
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -52,7 +52,7 @@ class EntitiesBuilder internal constructor(
|
|||||||
operator fun plus(sources: Iterable<TextSource>) = addAll(sources)
|
operator fun plus(sources: Iterable<TextSource>) = addAll(sources)
|
||||||
|
|
||||||
operator fun plus(other: EntitiesBuilder) = if (other == this) {
|
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
|
this
|
||||||
} else {
|
} else {
|
||||||
addAll(other.entitiesList)
|
addAll(other.entitiesList)
|
||||||
|
Loading…
Reference in New Issue
Block a user