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

Merge pull request #827 from InsanusMokrassar/10.1.0

10.1.0
This commit is contained in:
InsanusMokrassar 2024-02-17 01:57:17 +06:00 committed by GitHub
commit bce5fb658c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 153 additions and 15 deletions

View File

@ -1,5 +1,13 @@
# TelegramBotAPI changelog
## 10.1.0
**Add support of [Telegram Bots API 7.1](https://core.telegram.org/bots/api-changelog#february-16-2024)**
* `Version`:
* `Coroutines`: `1.7.3` -> `1.8.0`
* `MicroUtils`: `0.20.32` -> `0.20.34`
## 10.0.1
* `Version`:

View File

@ -1,4 +1,4 @@
# TelegramBotAPI [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi) [![Supported version](https://img.shields.io/badge/Telegram%20Bot%20API-7.0-blue)](https://core.telegram.org/bots/api-changelog#december-29-2023)
# TelegramBotAPI [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi) [![Supported version](https://img.shields.io/badge/Telegram%20Bot%20API-7.1-blue)](https://core.telegram.org/bots/api-changelog#february-16-2024)
| Docs | [![KDocs](https://img.shields.io/static/v1?label=Dokka&message=KDocs&color=blue&logo=kotlin)](https://tgbotapi.inmo.dev/index.html) [![Mini tutorial](https://img.shields.io/static/v1?label=Mk&message=Docs&color=blue&logo=mkdocs)](https://docs.inmo.dev/tgbotapi/index.html) |
|:----------------------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|

View File

@ -6,4 +6,4 @@ kotlin.incremental=true
kotlin.incremental.js=true
library_group=dev.inmo
library_version=10.0.1
library_version=10.1.0

View File

@ -2,7 +2,7 @@
kotlin = "1.9.22"
kotlin-serialization = "1.6.2"
kotlin-coroutines = "1.7.3"
kotlin-coroutines = "1.8.0"
javax-activation = "1.1.1"
@ -13,7 +13,7 @@ ktor = "2.3.8"
ksp = "1.9.22-1.0.17"
kotlin-poet = "1.16.0"
microutils = "0.20.32"
microutils = "0.20.34"
kslog = "1.3.2"
versions = "0.51.0"

View File

@ -214,3 +214,8 @@ suspend fun BehaviourContext.waitChatShared(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEvents<ChatShared>(initRequest, errorFactory)
suspend fun BehaviourContext.waitChatBoostAdded(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEvents<ChatBoostAdded>(initRequest, errorFactory)

View File

@ -208,3 +208,8 @@ suspend fun BehaviourContext.waitChatSharedEventsMessages(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEventsMessages<ChatShared>(initRequest, errorFactory)
suspend fun BehaviourContext.waitChatBoostAddedEventsMessages(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null }
) = waitEventsMessages<ChatBoostAdded>(initRequest, errorFactory)

View File

@ -823,3 +823,24 @@ suspend fun <BC : BehaviourContext> BC.onChatShared(
markerFactory: MarkerFactory<in ChatEventMessage<ChatShared>, Any> = ByChatMessageMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, PrivateEventMessage<ChatShared>>
) = onEventWithCustomChatEventMessage(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
/**
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
* to combinate several filters
* @param markerFactory Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
* data
*/
suspend fun <BC : BehaviourContext> BC.onChatBoostAdded(
initialFilter: SimpleFilter<ChatEventMessage<ChatBoostAdded>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<ChatBoostAdded>, Update>? = MessageFilterByChat,
markerFactory: MarkerFactory<in ChatEventMessage<ChatBoostAdded>, Any> = ByChatMessageMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<ChatBoostAdded>>
) = onEventWithCustomChatEventMessage(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)

View File

@ -45,6 +45,11 @@ value class CustomEmojiId(
val appLink
get() = "${internalTgAppLinksBeginning}emoji?id=$this"
}
@Serializable
@JvmInline
value class StoryId(
val long: Long
)
typealias Seconds = Int
typealias MilliSeconds = Long
@ -246,6 +251,8 @@ const val profileAccentColorIdField = "profile_accent_color_id"
const val backgroundCustomEmojiIdField = "background_custom_emoji_id"
const val profileBackgroundCustomEmojiIdField = "profile_background_custom_emoji_id"
const val hasVisibleHistoryField = "has_visible_history"
const val unrestrictBoostsCountField = "unrestrict_boost_count"
const val customEmojiStickerSetNameField = "custom_emoji_sticker_set_name"
const val iconCustomEmojiIdField = "icon_custom_emoji_id"
const val canJoinGroupsField = "can_join_groups"
const val canReadAllGroupMessagesField = "can_read_all_group_messages"
@ -656,6 +663,7 @@ const val menuButtonField = "menu_button"
const val boostIdField = "boost_id"
const val boostField = "boost"
const val boostCountField = "boost_count"
const val addDateField = "add_date"
const val expirationDateField = "expiration_date"
const val removeDateField = "remove_date"

View File

@ -9,7 +9,6 @@ import dev.inmo.tgbotapi.types.giveaway.GiveawayPublicResults
import dev.inmo.tgbotapi.types.giveaway.Giveaway
import dev.inmo.tgbotapi.types.location.Location
import dev.inmo.tgbotapi.types.message.MessageOrigin
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
import dev.inmo.tgbotapi.types.message.abstracts.Message
import dev.inmo.tgbotapi.types.payments.Invoice
import dev.inmo.tgbotapi.types.polls.Poll
@ -34,6 +33,14 @@ sealed interface ReplyInfo {
get() = message.metaInfo
}
@Serializable
data class ToStory(
val story: Story
): ReplyInfo {
override val messageMeta: Message.MetaInfo?
get() = null
}
@Serializable(External.Companion::class)
sealed interface External : ReplyInfo {
val origin: MessageOrigin

View File

@ -184,6 +184,10 @@ data class ExtendedSupergroupChatImpl(
override val profileBackgroundCustomEmojiId: CustomEmojiId? = null,
@SerialName(hasVisibleHistoryField)
override val newMembersSeeHistory: Boolean = false,
@SerialName(unrestrictBoostsCountField)
override val unrestrictBoostsCount: Int? = null,
@SerialName(customEmojiStickerSetNameField)
override val customEmojiStickerSetName: StickerSetName? = null,
) : ExtendedSupergroupChat
@Serializable
@ -242,6 +246,10 @@ data class ExtendedForumChatImpl(
override val profileBackgroundCustomEmojiId: CustomEmojiId? = null,
@SerialName(hasVisibleHistoryField)
override val newMembersSeeHistory: Boolean = false,
@SerialName(unrestrictBoostsCountField)
override val unrestrictBoostsCount: Int? = null,
@SerialName(customEmojiStickerSetNameField)
override val customEmojiStickerSetName: StickerSetName? = null,
) : ExtendedForumChat
@Serializable

View File

@ -59,7 +59,9 @@ sealed interface ExtendedSupergroupChat : SupergroupChat, ExtendedGroupChat, Ext
val stickerSetName: StickerSetName?
val canSetStickerSet: Boolean
val linkedChannelChatId: IdChatIdentifier?
val unrestrictBoostsCount: Int?
val location: ChatLocation?
val customEmojiStickerSetName: StickerSetName?
/**
* This field represents field "join_to_send_messages" from API

View File

@ -0,0 +1,12 @@
package dev.inmo.tgbotapi.types.message.ChatEvents
import dev.inmo.tgbotapi.types.boostCountField
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.PublicChatEvent
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class ChatBoostAdded(
@SerialName(boostCountField)
val count: Int
) : PublicChatEvent

View File

@ -123,6 +123,7 @@ data class CommonGroupContentMessageImpl<T : MessageContent>(
override val content: T,
override val senderBot: CommonBot?,
override val mediaGroupId: MediaGroupIdentifier?,
override val senderBoostsCount: Int?
) : CommonGroupContentMessage<T> {
constructor(
chat: PreviewGroupChat,
@ -137,8 +138,9 @@ data class CommonGroupContentMessageImpl<T : MessageContent>(
content: T,
senderBot: CommonBot?,
mediaGroupId: MediaGroupIdentifier?,
senderBoostsCount: Int?,
) : this(
chat, messageId, from, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, content, senderBot, mediaGroupId
chat, messageId, from, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, content, senderBot, mediaGroupId, senderBoostsCount
)
}
@ -226,6 +228,7 @@ data class CommonForumContentMessageImpl<T : MessageContent>(
override val content: T,
override val senderBot: CommonBot?,
override val mediaGroupId: MediaGroupIdentifier?,
override val senderBoostsCount: Int?,
) : CommonForumContentMessage<T> {
constructor(
chat: PreviewForumChat,
@ -241,7 +244,8 @@ data class CommonForumContentMessageImpl<T : MessageContent>(
content: T,
senderBot: CommonBot?,
mediaGroupId: MediaGroupIdentifier?,
senderBoostsCount: Int?,
) : this(
chat, messageId, threadId, from, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, content, senderBot, mediaGroupId
chat, messageId, threadId, from, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, content, senderBot, mediaGroupId, senderBoostsCount
)
}

View File

@ -54,6 +54,7 @@ internal data class RawMessage(
private val is_topic_message: Boolean? = null,
private val is_automatic_forward: Boolean? = null,
private val reply_to_message: RawMessage? = null,
private val reply_to_story: Story? = null,
private val external_reply: ReplyInfo.External? = null,
private val quote: TextQuote? = null,
private val via_bot: CommonBot? = null,
@ -98,6 +99,7 @@ internal data class RawMessage(
private val successful_payment: SuccessfulPayment? = null,
private val giveaway: Giveaway? = null,
private val giveaway_winners: GiveawayResults? = null,
private val sender_boost_count: Int? = null,
private val users_shared: UsersShared? = null,
private val chat_shared: ChatShared? = null,
@ -117,6 +119,9 @@ internal data class RawMessage(
private val general_forum_topic_unhidden: GeneralForumTopicUnhidden? = null,
private val write_access_allowed: WriteAccessAllowed? = null,
// Boost added to groups
private val boost_added: ChatBoostAdded? = null,
// AutoDelete Message time changed
private val message_auto_delete_timer_changed: MessageAutoDeleteTimerChanged? = null,
@ -247,6 +252,7 @@ internal data class RawMessage(
giveaway_created != null -> giveaway_created
giveaway_winners is GiveawayPrivateResults -> giveaway_winners
giveaway_completed != null -> giveaway_completed
boost_added != null -> boost_added
else -> null
}
}
@ -295,6 +301,7 @@ internal data class RawMessage(
reply_to_message != null -> ReplyInfo.Internal(
reply_to_message.asMessage
)
reply_to_story != null -> ReplyInfo.ToStory(reply_to_story)
external_reply != null -> external_reply
else -> null
}
@ -367,7 +374,8 @@ internal data class RawMessage(
reply_markup,
content,
via_bot,
media_group_id
media_group_id,
sender_boost_count
)
}
} else {
@ -431,7 +439,8 @@ internal data class RawMessage(
reply_markup,
content,
via_bot,
media_group_id
media_group_id,
sender_boost_count
)
}
}
@ -495,7 +504,8 @@ internal data class RawMessage(
reply_markup,
content,
via_bot,
media_group_id
media_group_id,
sender_boost_count
)
}
}

View File

@ -8,6 +8,10 @@ sealed interface GroupContentMessage<T : MessageContent> : PublicContentMessage<
override val chat: PreviewGroupChat
}
sealed interface PotentiallyFromUserGroupContentMessage<T : MessageContent> : GroupContentMessage<T> {
val senderBoostsCount: Int?
}
sealed interface ForumContentMessage<T : MessageContent> : GroupContentMessage<T>, PossiblyTopicMessage {
override val chat: PreviewForumChat
override val threadId: MessageThreadId
@ -28,7 +32,7 @@ interface AnonymousGroupContentMessage<T : MessageContent> : GroupContentMessage
get() = chat
}
interface CommonGroupContentMessage<T : MessageContent> : GroupContentMessage<T>, FromUserMessage
interface CommonGroupContentMessage<T : MessageContent> : GroupContentMessage<T>, PotentiallyFromUserGroupContentMessage<T>, FromUserMessage
interface FromChannelForumContentMessage<T: MessageContent> : FromChannelGroupContentMessage<T>, ForumContentMessage<T>
@ -37,4 +41,4 @@ interface AnonymousForumContentMessage<T : MessageContent> : ForumContentMessage
get() = chat
}
interface CommonForumContentMessage<T : MessageContent> : ForumContentMessage<T>, FromUserMessage
interface CommonForumContentMessage<T : MessageContent> : ForumContentMessage<T>, PotentiallyFromUserGroupContentMessage<T>, FromUserMessage

View File

@ -1,7 +1,17 @@
package dev.inmo.tgbotapi.types.stories
import dev.inmo.tgbotapi.types.ReplyInfo
import dev.inmo.tgbotapi.types.StoryId
import dev.inmo.tgbotapi.types.chat.PreviewChat
import dev.inmo.tgbotapi.types.chatField
import dev.inmo.tgbotapi.types.idField
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
class Story : ReplyInfo.External.ContentVariant
data class Story(
@SerialName(idField)
val id: StoryId,
@SerialName(chatField)
val chat: PreviewChat
) : ReplyInfo.External.ContentVariant

View File

@ -86,7 +86,8 @@ fun <T : MediaGroupPartContent> List<PossiblySentViaBotCommonMessage<T>>.asMedia
sourceMessage.replyMarkup,
content,
sourceMessage.senderBot,
sourceMessage.mediaGroupId
sourceMessage.mediaGroupId,
sourceMessage.senderBoostsCount
)
is ConnectedFromChannelGroupContentMessage -> ConnectedFromChannelGroupContentMessageImpl(
sourceMessage.chat,
@ -146,7 +147,8 @@ fun <T : MediaGroupPartContent> List<PossiblySentViaBotCommonMessage<T>>.asMedia
sourceMessage.replyMarkup,
content,
sourceMessage.senderBot,
sourceMessage.mediaGroupId
sourceMessage.mediaGroupId,
sourceMessage.senderBoostsCount
)
is FromChannelForumContentMessage -> FromChannelForumContentMessageImpl(
sourceMessage.chat,

View File

@ -222,6 +222,7 @@ import dev.inmo.tgbotapi.types.media.TitledTelegramMedia
import dev.inmo.tgbotapi.types.media.VisualMediaGroupMemberTelegramMedia
import dev.inmo.tgbotapi.types.message.ChannelEventMessage
import dev.inmo.tgbotapi.types.message.ChatEvents.ChannelChatCreated
import dev.inmo.tgbotapi.types.message.ChatEvents.ChatBoostAdded
import dev.inmo.tgbotapi.types.message.ChatEvents.DeleteChatPhoto
import dev.inmo.tgbotapi.types.message.ChatEvents.GroupChatCreated
import dev.inmo.tgbotapi.types.message.ChatEvents.LeftChatMemberEvent
@ -284,6 +285,7 @@ import dev.inmo.tgbotapi.types.message.abstracts.PossiblyMediaGroupMessage
import dev.inmo.tgbotapi.types.message.abstracts.PossiblyPaymentMessage
import dev.inmo.tgbotapi.types.message.abstracts.PossiblySentViaBotCommonMessage
import dev.inmo.tgbotapi.types.message.abstracts.PossiblyTopicMessage
import dev.inmo.tgbotapi.types.message.abstracts.PotentiallyFromUserGroupContentMessage
import dev.inmo.tgbotapi.types.message.abstracts.PrivateContentMessage
import dev.inmo.tgbotapi.types.message.abstracts.PublicContentMessage
import dev.inmo.tgbotapi.types.message.abstracts.SignedMessage
@ -1629,6 +1631,15 @@ public inline fun ReplyInfo.internalOrThrow(): ReplyInfo.Internal = this as
public inline fun <T> ReplyInfo.ifInternal(block: (ReplyInfo.Internal) -> T): T? = internalOrNull()
?.let(block)
public inline fun ReplyInfo.toStoryOrNull(): ReplyInfo.ToStory? = this as?
dev.inmo.tgbotapi.types.ReplyInfo.ToStory
public inline fun ReplyInfo.toStoryOrThrow(): ReplyInfo.ToStory = this as
dev.inmo.tgbotapi.types.ReplyInfo.ToStory
public inline fun <T> ReplyInfo.ifToStory(block: (ReplyInfo.ToStory) -> T): T? = toStoryOrNull()
?.let(block)
public inline fun BotAction.typingActionOrNull(): TypingAction? = this as?
dev.inmo.tgbotapi.types.actions.TypingAction
@ -2882,6 +2893,15 @@ public inline fun ChatEvent.channelChatCreatedOrThrow(): ChannelChatCreated = th
public inline fun <T> ChatEvent.ifChannelChatCreated(block: (ChannelChatCreated) -> T): T? =
channelChatCreatedOrNull() ?.let(block)
public inline fun ChatEvent.chatBoostAddedOrNull(): ChatBoostAdded? = this as?
dev.inmo.tgbotapi.types.message.ChatEvents.ChatBoostAdded
public inline fun ChatEvent.chatBoostAddedOrThrow(): ChatBoostAdded = this as
dev.inmo.tgbotapi.types.message.ChatEvents.ChatBoostAdded
public inline fun <T> ChatEvent.ifChatBoostAdded(block: (ChatBoostAdded) -> T): T? =
chatBoostAddedOrNull() ?.let(block)
public inline fun ChatEvent.deleteChatPhotoOrNull(): DeleteChatPhoto? = this as?
dev.inmo.tgbotapi.types.message.ChatEvents.DeleteChatPhoto
@ -3387,6 +3407,18 @@ public inline fun <T>
Message.ifGroupContentMessage(block: (GroupContentMessage<MessageContent>) -> T): T? =
groupContentMessageOrNull() ?.let(block)
public inline fun Message.potentiallyFromUserGroupContentMessageOrNull():
PotentiallyFromUserGroupContentMessage<MessageContent>? = this as?
dev.inmo.tgbotapi.types.message.abstracts.PotentiallyFromUserGroupContentMessage<dev.inmo.tgbotapi.types.message.content.MessageContent>
public inline fun Message.potentiallyFromUserGroupContentMessageOrThrow():
PotentiallyFromUserGroupContentMessage<MessageContent> = this as
dev.inmo.tgbotapi.types.message.abstracts.PotentiallyFromUserGroupContentMessage<dev.inmo.tgbotapi.types.message.content.MessageContent>
public inline fun <T>
Message.ifPotentiallyFromUserGroupContentMessage(block: (PotentiallyFromUserGroupContentMessage<MessageContent>) -> T):
T? = potentiallyFromUserGroupContentMessageOrNull() ?.let(block)
public inline fun Message.forumContentMessageOrNull(): ForumContentMessage<MessageContent>? = this
as?
dev.inmo.tgbotapi.types.message.abstracts.ForumContentMessage<dev.inmo.tgbotapi.types.message.content.MessageContent>