mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-11-25 08:45:50 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 71001b772a | |||
| 449f7f836f | |||
| b3a657b7d6 | |||
| 8247e7c69c | |||
| 67b7472868 | |||
| 13e4740d0a | |||
| 48db305541 | |||
| 6f512a144c |
@@ -1,5 +1,12 @@
|
||||
# TelegramBotAPI changelog
|
||||
|
||||
## 8.1.1
|
||||
|
||||
**THIS UPDATE CONTAINS BREAKING CHANGES: USERNAMES OF BOTS NOW BECAME NULLABLE**
|
||||
|
||||
* `Utils`:
|
||||
* Improve extension `Update.sourceChat` to add opportunity to select some chats by logic different with the default
|
||||
|
||||
## 8.1.0
|
||||
|
||||
**PARTIALLY BREAKING CHANGES: Exclude `.*Impl` classcasts from `ClassCastsNew`**
|
||||
|
||||
@@ -6,4 +6,4 @@ kotlin.incremental=true
|
||||
kotlin.incremental.js=true
|
||||
|
||||
library_group=dev.inmo
|
||||
library_version=8.1.0
|
||||
library_version=8.1.1
|
||||
|
||||
@@ -2,18 +2,18 @@
|
||||
|
||||
kotlin = "1.8.22"
|
||||
kotlin-serialization = "1.5.1"
|
||||
kotlin-coroutines = "1.6.4"
|
||||
kotlin-coroutines = "1.7.2"
|
||||
|
||||
javax-activation = "1.1.1"
|
||||
|
||||
korlibs = "4.0.3"
|
||||
uuid = "0.7.1"
|
||||
ktor = "2.3.1"
|
||||
ktor = "2.3.2"
|
||||
|
||||
ksp = "1.8.22-1.0.11"
|
||||
kotlin-poet = "1.14.2"
|
||||
|
||||
microutils = "0.19.4"
|
||||
microutils = "0.19.7"
|
||||
|
||||
github-release-plugin = "2.4.1"
|
||||
dokka = "1.8.20"
|
||||
|
||||
@@ -170,12 +170,12 @@ data class ExtendedForumChatImpl(
|
||||
@Serializable
|
||||
data class ExtendedBot(
|
||||
override val id: UserId,
|
||||
@SerialName(usernameField)
|
||||
override val username: Username,
|
||||
@SerialName(firstNameField)
|
||||
override val firstName: String,
|
||||
@SerialName(lastNameField)
|
||||
override val lastName: String = "",
|
||||
@SerialName(usernameField)
|
||||
override val username: Username? = null,
|
||||
@SerialName(canJoinGroupsField)
|
||||
val canJoinGroups: Boolean = false,
|
||||
@SerialName(canReadAllGroupMessagesField)
|
||||
|
||||
@@ -67,19 +67,17 @@ data class ChannelChatImpl(
|
||||
sealed class User : PrivateChat
|
||||
|
||||
@Serializable(UserSerializer::class)
|
||||
sealed class Bot : User() {
|
||||
abstract override val username: Username
|
||||
}
|
||||
sealed class Bot : User()
|
||||
|
||||
@Serializable
|
||||
data class CommonBot(
|
||||
override val id: UserId,
|
||||
@SerialName(usernameField)
|
||||
override val username: Username,
|
||||
@SerialName(firstNameField)
|
||||
override val firstName: String,
|
||||
@SerialName(lastNameField)
|
||||
override val lastName: String = ""
|
||||
override val lastName: String = "",
|
||||
@SerialName(usernameField)
|
||||
override val username: Username? = null,
|
||||
) : Bot() {
|
||||
@SerialName(isBotField)
|
||||
private val isBot = true
|
||||
|
||||
@@ -3,17 +3,60 @@ package dev.inmo.tgbotapi.extensions.utils.extensions
|
||||
import dev.inmo.tgbotapi.abstracts.FromUser
|
||||
import dev.inmo.tgbotapi.abstracts.WithUser
|
||||
import dev.inmo.tgbotapi.extensions.utils.asUser
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.BaseChosenInlineResult
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.ChosenInlineResult
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.LocationChosenInlineResult
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.query.BaseInlineQuery
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.query.LocationInlineQuery
|
||||
import dev.inmo.tgbotapi.types.chat.Chat
|
||||
import dev.inmo.tgbotapi.types.chat.User
|
||||
import dev.inmo.tgbotapi.types.update.ChatJoinRequestUpdate
|
||||
import dev.inmo.tgbotapi.types.queries.callback.*
|
||||
import dev.inmo.tgbotapi.types.update.*
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
import dev.inmo.tgbotapi.utils.PreviewFeature
|
||||
|
||||
fun CallbackQuery.sourceChat() = when (this) {
|
||||
is InlineMessageIdDataCallbackQuery -> null
|
||||
is MessageDataCallbackQuery -> message.chat
|
||||
is InlineMessageIdGameShortNameCallbackQuery -> null
|
||||
is MessageGameShortNameCallbackQuery -> message.chat
|
||||
is UnknownCallbackQueryType -> null
|
||||
}
|
||||
|
||||
@PreviewFeature
|
||||
fun Update.sourceChat(): Chat? = when (this) {
|
||||
is BaseMessageUpdate -> data.chat
|
||||
is ChatJoinRequestUpdate -> data.chat
|
||||
fun Update.sourceChatWithConverters(
|
||||
baseMessageUpdateConverter: (BaseMessageUpdate) -> Chat? = { it.data.chat },
|
||||
chatJoinRequestUpdateConverter: (ChatJoinRequestUpdate) -> Chat? = { it.data.chat },
|
||||
shippingQueryUpdateConverter: (ShippingQueryUpdate) -> Chat? = { null },
|
||||
pollAnswerUpdateConverter: (PollAnswerUpdate) -> Chat? = { null },
|
||||
preCheckoutQueryUpdateConverter: (PreCheckoutQueryUpdate) -> Chat? = { it.data.from },
|
||||
callbackQueryUpdateConverter: (CallbackQueryUpdate) -> Chat? = { it.data.sourceChat() },
|
||||
chosenInlineResultUpdateConverter: (ChosenInlineResultUpdate) -> Chat? = { null },
|
||||
inlineQueryUpdateConverter: (InlineQueryUpdate) -> Chat? = { null },
|
||||
pollUpdateConverter: (PollUpdate) -> Chat? = { null },
|
||||
channelPostUpdateConverter: (ChannelPostUpdate) -> Chat? = { it.data.chat },
|
||||
messageUpdateConverter: (MessageUpdate) -> Chat? = { it.data.chat },
|
||||
editChannelPostUpdateConverter: (EditChannelPostUpdate) -> Chat? = { it.data.chat },
|
||||
editMessageUpdateConverter: (EditMessageUpdate) -> Chat? = { it.data.chat },
|
||||
myChatMemberUpdatedUpdateConverter: (MyChatMemberUpdatedUpdate) -> Chat? = { it.data.chat },
|
||||
commonChatMemberUpdatedUpdateConverter: (CommonChatMemberUpdatedUpdate) -> Chat? = { it.data.chat }
|
||||
): Chat? = when (this) {
|
||||
is BaseMessageUpdate -> baseMessageUpdateConverter(this)
|
||||
is ChatJoinRequestUpdate -> chatJoinRequestUpdateConverter(this)
|
||||
is ShippingQueryUpdate -> shippingQueryUpdateConverter(this)
|
||||
is PollAnswerUpdate -> pollAnswerUpdateConverter(this)
|
||||
is PreCheckoutQueryUpdate -> preCheckoutQueryUpdateConverter(this)
|
||||
is CallbackQueryUpdate -> callbackQueryUpdateConverter(this)
|
||||
is ChosenInlineResultUpdate -> chosenInlineResultUpdateConverter(this)
|
||||
is InlineQueryUpdate -> inlineQueryUpdateConverter(this)
|
||||
is PollUpdate -> pollUpdateConverter(this)
|
||||
is ChannelPostUpdate -> channelPostUpdateConverter(this)
|
||||
is MessageUpdate -> messageUpdateConverter(this)
|
||||
is EditChannelPostUpdate -> editChannelPostUpdateConverter(this)
|
||||
is EditMessageUpdate -> editMessageUpdateConverter(this)
|
||||
is MyChatMemberUpdatedUpdate -> myChatMemberUpdatedUpdateConverter(this)
|
||||
is CommonChatMemberUpdatedUpdate -> commonChatMemberUpdatedUpdateConverter(this)
|
||||
else -> {
|
||||
when (val data = data) {
|
||||
is FromUser -> data.from
|
||||
@@ -23,6 +66,9 @@ fun Update.sourceChat(): Chat? = when (this) {
|
||||
}
|
||||
}
|
||||
|
||||
@PreviewFeature
|
||||
fun Update.sourceChat(): Chat? = sourceChatWithConverters()
|
||||
|
||||
@PreviewFeature
|
||||
fun Update.sourceUser(): User? = when (val data = data) {
|
||||
is FromUser -> data.from
|
||||
|
||||
@@ -28,9 +28,9 @@ val WebAppUser.isPremium
|
||||
fun WebAppUser.asUser() = if (isBot == true) {
|
||||
CommonBot(
|
||||
UserId(id),
|
||||
username ?.let(::Username) ?: error("Username is absent for bot, but must exists"),
|
||||
firstName,
|
||||
lastName ?: ""
|
||||
lastName ?: "",
|
||||
username ?.let(::Username) ?: error("Username is absent for bot, but must exists")
|
||||
)
|
||||
} else {
|
||||
CommonUser(
|
||||
|
||||
Reference in New Issue
Block a user