mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-11-16 12:00:18 +00:00
Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| dc3ecec5c7 | |||
| ebd5e1a37b | |||
| 3da2e4fffb | |||
| 9aea59b44b | |||
| 7bab96a9cd | |||
| a0c10d9a9a | |||
| e2901cb9f9 | |||
| 3c60d074ba | |||
| f10cfdc5f1 | |||
| 270f9a60c1 | |||
| 2b49a75a42 | |||
| 9f7a348000 | |||
| 8cec74aa6a | |||
| d1914c8045 | |||
| baeb4848cf | |||
| dbadcb3f5a | |||
| 13dd73dd63 | |||
| ceba86abcb | |||
| f6a0b1a19d | |||
| 4ed6e5c7b2 | |||
| 7f43dc0815 | |||
| c72993017f | |||
| e8991f8f89 | |||
| 03cd4276a9 | |||
| 4427d76cd1 | |||
| 00f504a095 |
2
.github/FUNDING.yml
vendored
2
.github/FUNDING.yml
vendored
@@ -1,3 +1,3 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
custom: ['https://www.tinkoff.ru/rm/ovsyannikov.aleksey113/ObMJ712472']
|
||||
custom: ['https://www.tinkoff.ru/rm/ovsyannikov.aleksey113/ObMJ712472', 'https://boosty.to/insanusmokrassar']
|
||||
|
||||
7
.github/workflows/packages_publishing.yml
vendored
7
.github/workflows/packages_publishing.yml
vendored
@@ -16,7 +16,12 @@ jobs:
|
||||
mv gradle.properties.tmp gradle.properties
|
||||
- name: Build
|
||||
run: ./gradlew build
|
||||
- name: Publish
|
||||
- name: Publish to Gitea
|
||||
continue-on-error: true
|
||||
run: ./gradlew publishAllPublicationsToGiteaRepository
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
- name: Publish to GithubPackages
|
||||
continue-on-error: true
|
||||
run: ./gradlew publishAllPublicationsToGithubPackagesRepository --no-parallel
|
||||
env:
|
||||
|
||||
28
CHANGELOG.md
28
CHANGELOG.md
@@ -1,5 +1,33 @@
|
||||
# TelegramBotAPI changelog
|
||||
|
||||
## 4.2.0
|
||||
|
||||
* `Versions`:
|
||||
* `Kotlin`: `1.7.21` -> `1.7.22`
|
||||
* `MicroUtils`: `0.14.4` -> `0.15.0`
|
||||
|
||||
## 4.1.3
|
||||
|
||||
* `Versions`:
|
||||
* `MicroUtils`: `0.14.2` -> `0.14.4`
|
||||
* `Core`:
|
||||
* `ContentMessage`, `CommonMessage`, `PossiblyMediaGroupMessage` and `PossiblySentViaBotCommonMessage` got `out`
|
||||
variance
|
||||
* `UserId` now is `ChatId` instead of `IdChatIdentififer`
|
||||
|
||||
## 4.1.2
|
||||
|
||||
* `Versions`:
|
||||
* `MicroUtils`: `0.14.1` -> `0.14.2`
|
||||
* `BehaviourBuilder`:
|
||||
* Fixes in `CallbackQuery` waiters
|
||||
|
||||
## 4.1.1
|
||||
|
||||
* `Core`:
|
||||
* Add opportunity to create `IdChatIdentifier` with optional `threadId`
|
||||
* New serializer `FullChatIdentifierSerializer` with serialization of `ChatIdWithThreadId`
|
||||
|
||||
## 4.1.0
|
||||
|
||||
* `Versions`:
|
||||
|
||||
@@ -6,4 +6,4 @@ kotlin.incremental=true
|
||||
kotlin.incremental.js=true
|
||||
|
||||
library_group=dev.inmo
|
||||
library_version=4.1.0
|
||||
library_version=4.2.0
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[versions]
|
||||
|
||||
kotlin = "1.7.21"
|
||||
kotlin = "1.7.22"
|
||||
kotlin-serialization = "1.4.1"
|
||||
kotlin-coroutines = "1.6.4"
|
||||
|
||||
@@ -10,10 +10,10 @@ korlibs = "3.4.0"
|
||||
uuid = "0.6.0"
|
||||
ktor = "2.1.3"
|
||||
|
||||
ksp = "1.7.21-1.0.8"
|
||||
ksp = "1.7.22-1.0.8"
|
||||
kotlin-poet = "1.12.0"
|
||||
|
||||
microutils = "0.14.1"
|
||||
microutils = "0.15.0"
|
||||
|
||||
github-release-plugin = "2.4.1"
|
||||
dokka = "1.7.20"
|
||||
|
||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
|
||||
|
||||
@@ -42,20 +42,40 @@ publishing {
|
||||
maven {
|
||||
name = "GithubPackages"
|
||||
url = uri("https://maven.pkg.github.com/InsanusMokrassar/TelegramBotAPI")
|
||||
|
||||
credentials {
|
||||
username = project.hasProperty('GITHUBPACKAGES_USER') ? project.property('GITHUBPACKAGES_USER') : System.getenv('GITHUBPACKAGES_USER')
|
||||
password = project.hasProperty('GITHUBPACKAGES_PASSWORD') ? project.property('GITHUBPACKAGES_PASSWORD') : System.getenv('GITHUBPACKAGES_PASSWORD')
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (project.hasProperty('GITEA_TOKEN') || System.getenv('GITEA_TOKEN') != null) {
|
||||
maven {
|
||||
name = "Gitea"
|
||||
url = uri("https://git.inmo.dev/api/packages/InsanusMokrassar/maven")
|
||||
|
||||
credentials(HttpHeaderCredentials) {
|
||||
name = "Authorization"
|
||||
value = project.hasProperty('GITEA_TOKEN') ? project.property('GITEA_TOKEN') : System.getenv('GITEA_TOKEN')
|
||||
}
|
||||
|
||||
authentication {
|
||||
header(HttpHeaderAuthentication)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) {
|
||||
maven {
|
||||
name = "sonatype"
|
||||
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
|
||||
|
||||
credentials {
|
||||
username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER')
|
||||
password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD')
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"}],"mavenConfig":{"name":"${project.name}","description":"${project.description}","url":"https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI","vcsUrl":"https://github.com/insanusmokrassar/TelegramBotAPI.git","developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}],"repositories":[{"name":"GithubPackages","url":"https://maven.pkg.github.com/InsanusMokrassar/TelegramBotAPI"},{"name":"sonatype","url":"https://oss.sonatype.org/service/local/staging/deploy/maven2/"}],"gpgSigning":{"type":"dev.inmo.kmppscriptbuilder.core.models.GpgSigning.Optional"}}}
|
||||
{"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"}],"mavenConfig":{"name":"${project.name}","description":"${project.description}","url":"https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI","vcsUrl":"https://github.com/insanusmokrassar/TelegramBotAPI.git","developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}],"repositories":[{"name":"GithubPackages","url":"https://maven.pkg.github.com/InsanusMokrassar/TelegramBotAPI"},{"name":"Gitea","url":"https://git.inmo.dev/api/packages/InsanusMokrassar/maven","credsType":{"type":"dev.inmo.kmppscriptbuilder.core.models.MavenPublishingRepository.CredentialsType.HttpHeaderCredentials","headerName":"Authorization","headerValueProperty":"GITEA_TOKEN"}},{"name":"sonatype","url":"https://oss.sonatype.org/service/local/staging/deploy/maven2/"}],"gpgSigning":{"type":"dev.inmo.kmppscriptbuilder.core.models.GpgSigning.Optional"}}}
|
||||
@@ -20,7 +20,7 @@ suspend inline fun <reified O> BehaviourContext.waitCallbackQueries(
|
||||
initRequest,
|
||||
errorFactory
|
||||
) {
|
||||
(it.callbackQueryUpdateOrNull() ?.data as O).let(::listOfNotNull)
|
||||
(it.callbackQueryUpdateOrNull() ?.data as? O).let(::listOfNotNull)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -30,6 +30,9 @@ sealed interface IdChatIdentifier : ChatIdentifier {
|
||||
|
||||
companion object {
|
||||
operator fun invoke(chatId: Identifier) = ChatId(chatId)
|
||||
operator fun invoke(chatId: Identifier, threadId: MessageThreadId?) = threadId ?.let {
|
||||
ChatIdWithThreadId(chatId, threadId)
|
||||
} ?: ChatId(chatId)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,9 +69,9 @@ val UserId.userLink: String
|
||||
val User.link: String
|
||||
get() = id.userLink
|
||||
|
||||
typealias UserId = IdChatIdentifier
|
||||
typealias UserId = ChatId
|
||||
|
||||
fun Identifier.toChatId(): IdChatIdentifier = ChatId(this)
|
||||
fun Identifier.toChatId(): ChatId = ChatId(this)
|
||||
fun Int.toChatId(): IdChatIdentifier = toLong().toChatId()
|
||||
fun Byte.toChatId(): IdChatIdentifier = toLong().toChatId()
|
||||
|
||||
@@ -94,6 +97,7 @@ object ChatIdentifierSerializer : KSerializer<ChatIdentifier> {
|
||||
override val descriptor: SerialDescriptor = internalSerializer.descriptor
|
||||
override fun deserialize(decoder: Decoder): ChatIdentifier {
|
||||
val id = internalSerializer.deserialize(decoder)
|
||||
|
||||
return id.longOrNull ?.let {
|
||||
ChatId(it)
|
||||
} ?: id.content.let {
|
||||
@@ -112,3 +116,41 @@ object ChatIdentifierSerializer : KSerializer<ChatIdentifier> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@RiskFeature
|
||||
object FullChatIdentifierSerializer : KSerializer<ChatIdentifier> {
|
||||
private val internalSerializer = JsonPrimitive.serializer()
|
||||
override val descriptor: SerialDescriptor = internalSerializer.descriptor
|
||||
override fun deserialize(decoder: Decoder): ChatIdentifier {
|
||||
val id = internalSerializer.deserialize(decoder)
|
||||
|
||||
return id.longOrNull ?.let {
|
||||
ChatId(it)
|
||||
} ?:let {
|
||||
val splitted = id.content.split("/")
|
||||
if (splitted.size == 2) {
|
||||
val (chatId, threadId) = splitted
|
||||
ChatIdWithThreadId(
|
||||
chatId.toLongOrNull() ?: return@let null,
|
||||
threadId.toLongOrNull() ?: return@let null
|
||||
)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
} ?: id.content.let {
|
||||
if (!it.startsWith("@")) {
|
||||
Username("@$it")
|
||||
} else {
|
||||
Username(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, value: ChatIdentifier) {
|
||||
when (value) {
|
||||
is ChatId -> encoder.encodeLong(value.chatId)
|
||||
is ChatIdWithThreadId -> encoder.encodeString("${value.chatId}/${value.threadId}")
|
||||
is Username -> encoder.encodeString(value.username)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ data class ExtendedGroupChatImpl(
|
||||
@Serializable
|
||||
data class ExtendedPrivateChatImpl(
|
||||
@SerialName(idField)
|
||||
override val id: IdChatIdentifier,
|
||||
override val id: UserId,
|
||||
@SerialName(photoField)
|
||||
override val chatPhoto: ChatPhoto? = null,
|
||||
@SerialName(usernameField)
|
||||
|
||||
@@ -18,7 +18,7 @@ data class GroupChatImpl(
|
||||
@Serializable
|
||||
data class PrivateChatImpl(
|
||||
@SerialName(idField)
|
||||
override val id: IdChatIdentifier,
|
||||
override val id: UserId,
|
||||
@SerialName(usernameField)
|
||||
override val username: Username? = null,
|
||||
@SerialName(firstNameField)
|
||||
|
||||
@@ -42,6 +42,7 @@ sealed interface Sticker : TelegramMediaFile, SizedMediaFile, ThumbedMediaFile {
|
||||
get() = false
|
||||
}
|
||||
|
||||
@OptIn(RiskFeature::class)
|
||||
object StickerSerializer : KSerializer<Sticker> {
|
||||
override val descriptor: SerialDescriptor = StickerSurrogate.serializer().descriptor
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.types.message.abstracts
|
||||
|
||||
import dev.inmo.tgbotapi.types.message.content.MessageContent
|
||||
|
||||
sealed interface CommonMessage<T: MessageContent> : Message,
|
||||
sealed interface CommonMessage<out T: MessageContent> : Message,
|
||||
PossiblyForwardedMessage,
|
||||
PossiblyEditedMessage,
|
||||
PossiblyReplyMessage,
|
||||
|
||||
@@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.types.message.abstracts
|
||||
|
||||
import dev.inmo.tgbotapi.types.message.content.MessageContent
|
||||
|
||||
interface ContentMessage<T: MessageContent>: Message {
|
||||
interface ContentMessage<out T: MessageContent>: Message {
|
||||
val hasProtectedContent: Boolean
|
||||
val content: T
|
||||
|
||||
|
||||
@@ -3,6 +3,6 @@ package dev.inmo.tgbotapi.types.message.abstracts
|
||||
import dev.inmo.tgbotapi.types.MediaGroupIdentifier
|
||||
import dev.inmo.tgbotapi.types.message.content.MessageContent
|
||||
|
||||
interface PossiblyMediaGroupMessage<T : MessageContent> : ContentMessage<T> {
|
||||
interface PossiblyMediaGroupMessage<out T : MessageContent> : ContentMessage<T> {
|
||||
val mediaGroupId: MediaGroupIdentifier?
|
||||
}
|
||||
|
||||
@@ -2,4 +2,4 @@ package dev.inmo.tgbotapi.types.message.abstracts
|
||||
|
||||
import dev.inmo.tgbotapi.types.message.content.MessageContent
|
||||
|
||||
sealed interface PossiblySentViaBotCommonMessage<T: MessageContent> : CommonMessage<T>, PossiblySentViaBot
|
||||
sealed interface PossiblySentViaBotCommonMessage<out T: MessageContent> : CommonMessage<T>, PossiblySentViaBot
|
||||
|
||||
@@ -200,7 +200,7 @@ infix fun String.mention(parseMode: ParseMode): String = when (parseMode) {
|
||||
is MarkdownV2 -> mentionMarkdownV2()
|
||||
}
|
||||
|
||||
infix fun Pair<String, IdChatIdentifier>.mention(parseMode: ParseMode): String = when (parseMode) {
|
||||
infix fun Pair<String, UserId>.mention(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> first.textMentionHTML(second)
|
||||
is Markdown -> first.textMentionMarkdown(second)
|
||||
is MarkdownV2 -> first.textMentionMarkdownV2(second)
|
||||
|
||||
Reference in New Issue
Block a user