1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 16:23:48 +00:00

Merge pull request #693 from InsanusMokrassar/4.2.1

4.2.1
This commit is contained in:
InsanusMokrassar 2022-12-08 10:50:07 +06:00 committed by GitHub
commit 1f416d4a28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 29 deletions

View File

@ -1,5 +1,13 @@
# TelegramBotAPI changelog # TelegramBotAPI changelog
## 4.2.1
* `Versions`:
* `MicroUtils`: `0.15.0` -> `0.16.0`
* `Ktor`: `2.1.3` -> `2.2.1`
* `Utils`:
* Improve support of `makeLinkToMessage` extensions
## 4.2.0 ## 4.2.0
* `Versions`: * `Versions`:

View File

@ -20,6 +20,7 @@ allprojects {
mavenLocal() mavenLocal()
mavenCentral() mavenCentral()
google() google()
maven { url "https://git.inmo.dev/api/packages/InsanusMokrassar/maven" }
} }
if (it != rootProject.findProject("docs")) { if (it != rootProject.findProject("docs")) {
tasks.whenTaskAdded { task -> tasks.whenTaskAdded { task ->

View File

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

View File

@ -8,12 +8,12 @@ javax-activation = "1.1.1"
korlibs = "3.4.0" korlibs = "3.4.0"
uuid = "0.6.0" uuid = "0.6.0"
ktor = "2.1.3" ktor = "2.2.1"
ksp = "1.7.22-1.0.8" ksp = "1.7.22-1.0.8"
kotlin-poet = "1.12.0" kotlin-poet = "1.12.0"
microutils = "0.15.0" microutils = "0.16.0"
github-release-plugin = "2.4.1" github-release-plugin = "2.4.1"
dokka = "1.7.20" dokka = "1.7.20"

View File

@ -7,39 +7,61 @@ import dev.inmo.tgbotapi.types.message.textsources.link
import io.ktor.http.encodeURLQueryComponent import io.ktor.http.encodeURLQueryComponent
fun makeUsernameLink(username: String) = "$internalLinkBeginning/$username" fun makeUsernameLink(username: String, threadId: MessageThreadId? = null) = "$internalLinkBeginning/$username${threadId ?.let { "/$it" } ?: ""}"
fun makeChatLink(identifier: Identifier, threadId: MessageThreadId? = null) = identifier.toString().replace(
linkIdRedundantPartRegex,
""
).let { bareId ->
"$internalLinkBeginning/c/$bareId${threadId ?.let { "/$it" } ?: ""}"
}
fun makeUsernameDeepLinkPrefix(username: String) = "${makeUsernameLink(username)}?start=" fun makeUsernameDeepLinkPrefix(username: String) = "${makeUsernameLink(username)}?start="
fun makeUsernameStartattachPrefix(username: String) = "$internalLinkBeginning/$username?startattach" fun makeUsernameStartattachPrefix(username: String) = "$internalLinkBeginning/$username?startattach"
fun makeUsernameStartattachLink(username: String, data: String? = null) = "${makeUsernameStartattachPrefix(username)}${data?.let { "=$it" } ?: ""}" fun makeUsernameStartattachLink(username: String, data: String? = null) = "${makeUsernameStartattachPrefix(username)}${data?.let { "=$it" } ?: ""}"
inline val Username.link inline val Username.link
get() = makeUsernameLink(usernameWithoutAt) get() = makeUsernameLink(usernameWithoutAt)
val IdChatIdentifier.link: String
get() = makeChatLink(chatId, threadId)
fun ChatId.link(threadId: MessageThreadId?) = makeChatLink(chatId, threadId)
inline fun Username.link(threadId: MessageThreadId?) = makeUsernameLink(usernameWithoutAt, threadId)
inline val Username.deepLinkPrefix inline val Username.deepLinkPrefix
get() = makeUsernameDeepLinkPrefix(usernameWithoutAt) get() = makeUsernameDeepLinkPrefix(usernameWithoutAt)
inline val Username.startattachPrefix inline val Username.startattachPrefix
get() = makeUsernameStartattachPrefix(usernameWithoutAt) get() = makeUsernameStartattachPrefix(usernameWithoutAt)
inline fun makeLink(username: Username) = username.link inline fun makeLink(username: Username, threadId: MessageThreadId? = null) = username.link(threadId)
inline fun makeTelegramDeepLink(username: String, startParameter: String) = "${makeUsernameDeepLinkPrefix(username)}$startParameter".encodeURLQueryComponent() inline fun makeTelegramDeepLink(username: String, startParameter: String) = "${makeUsernameDeepLinkPrefix(username)}$startParameter".encodeURLQueryComponent()
inline fun makeTelegramStartattach(username: String, data: String? = null) = makeUsernameStartattachLink(username, data) inline fun makeTelegramStartattach(username: String, data: String? = null) = makeUsernameStartattachLink(username, data)
inline fun makeDeepLink(username: Username, startParameter: String) = makeTelegramDeepLink(username.usernameWithoutAt, startParameter) inline fun makeDeepLink(username: Username, startParameter: String) = makeTelegramDeepLink(username.usernameWithoutAt, startParameter)
inline fun makeTelegramDeepLink(username: Username, startParameter: String) = makeDeepLink(username, startParameter) inline fun makeTelegramDeepLink(username: Username, startParameter: String) = makeDeepLink(username, startParameter)
inline fun makeTelegramStartattach(username: Username, data: String? = null) = makeTelegramStartattach(username.usernameWithoutAt, data) inline fun makeTelegramStartattach(username: Username, data: String? = null) = makeTelegramStartattach(username.usernameWithoutAt, data)
fun makeLinkToMessage(
username: String,
messageId: MessageId
): String = "$internalLinkBeginning/$username/$messageId"
fun makeLinkToMessage(
username: Username,
messageId: MessageId
): String = makeLinkToMessage(username.username, messageId)
fun makeLinkToMessage(
chat: UsernameChat,
messageId: MessageId
): String? = chat.username ?.let { makeLinkToMessage(it, messageId) }
private val linkIdRedundantPartRegex = Regex("^-100") private val linkIdRedundantPartRegex = Regex("^-100")
private val usernameBeginSymbolRegex = Regex("^@") private val usernameBeginSymbolRegex = Regex("^@")
fun makeLinkToMessage(
username: String,
messageId: MessageId,
threadId: MessageThreadId? = null
): String = "${makeUsernameLink(username, threadId)}/$messageId"
fun makeLinkToMessage(
username: Username,
messageId: MessageId,
threadId: MessageThreadId? = null
): String = makeLinkToMessage(username.username, messageId, threadId)
fun makeLinkToMessage(
chatId: Identifier,
messageId: MessageId,
threadId: MessageThreadId? = null
): String = chatId.toString().replace(
linkIdRedundantPartRegex,
""
).let { bareId ->
"$internalLinkBeginning/c/$bareId/${threadId ?.let { "$it/" } ?: ""}$messageId"
}
fun makeLinkToMessage(
chatId: IdChatIdentifier,
messageId: MessageId,
): String = makeLinkToMessage(chatId.chatId, messageId, chatId.threadId)
/** /**
* Link which can be used as by any user to get access to [Message]. Returns null in case when there are no * Link which can be used as by any user to get access to [Message]. Returns null in case when there are no
* known way to build link (for [PrivateChat]s, for example) * known way to build link (for [PrivateChat]s, for example)
@ -49,16 +71,10 @@ fun makeLinkToMessage(
messageId: MessageId messageId: MessageId
): String? { ): String? {
return when { return when {
chat is UsernameChat && chat.username != null -> { chat is UsernameChat && chat.username != null -> chat.username ?.let {
"$internalLinkBeginning/${chat.username ?.username ?.replace( makeLinkToMessage(it, messageId, chat.id.threadId)
usernameBeginSymbolRegex, "")}/$messageId" } ?: makeLinkToMessage(chat.id, messageId)
} chat !is PrivateChat -> makeLinkToMessage(chat.id, messageId)
chat !is PrivateChat -> chat.id.chatId.toString().replace(
linkIdRedundantPartRegex,
""
).let { bareId ->
"$internalLinkBeginning/c/$bareId/$messageId"
}
else -> return null else -> return null
} }
} }
@ -79,7 +95,7 @@ val Message.link: String?
val Chat.link: String? val Chat.link: String?
get() { get() {
if (this is UsernameChat) { if (this is UsernameChat) {
username ?.link username ?.link ?: id.link
} }
if (this is ExtendedPublicChat) { if (this is ExtendedPublicChat) {
inviteLink ?.let { return it } inviteLink ?.let { return it }