mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-23 00:57:13 +00:00
PreviewFeature, message links
This commit is contained in:
parent
63e0f5c054
commit
92224b95df
@ -71,6 +71,12 @@ mistake - don't hesitate to say this.**
|
||||
### 0.22.1 MediaContent#asInputMedia
|
||||
|
||||
* All `MediaContent` instances now can create their `InputMedia` analog
|
||||
* New annotation `PreviewFeature` was added to mark new thing as preview for the time
|
||||
while they can work incorrectly
|
||||
* Added links utils:
|
||||
* `makeLinkToMessage` have two signatures - for direct creating using username and for abstract creating using
|
||||
chat id
|
||||
* `makeFileLink` is unsafe way to create file link
|
||||
|
||||
## 0.21.0 TelegramBotAPI 4.5
|
||||
|
||||
|
@ -0,0 +1,6 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
||||
|
||||
import kotlin.Experimental.*
|
||||
|
||||
@Experimental(Level.WARNING)
|
||||
annotation class PreviewFeature
|
@ -0,0 +1,40 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatId
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PrivateChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.UsernameChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.*
|
||||
|
||||
private const val internalLinkBeginning = "https://t.me"
|
||||
|
||||
@PreviewFeature
|
||||
fun makeLinkToMessage(
|
||||
username: String,
|
||||
messageId: MessageIdentifier
|
||||
): String = "$internalLinkBeginning/$username/$messageId"
|
||||
|
||||
private val linkIdRedundantPartRegex = Regex("^-100")
|
||||
|
||||
@PreviewFeature
|
||||
fun makeLinkToMessage(
|
||||
chat: ExtendedChat,
|
||||
messageId: MessageIdentifier
|
||||
): String? {
|
||||
return when {
|
||||
chat is UsernameChat && chat.username != null -> "$internalLinkBeginning/${chat.username}/$messageId"
|
||||
chat !is PrivateChat -> chat.id.chatId.toString().replace(
|
||||
linkIdRedundantPartRegex,
|
||||
""
|
||||
).let { bareId ->
|
||||
"$internalLinkBeginning/c/$bareId/$messageId"
|
||||
}
|
||||
else -> return null
|
||||
}
|
||||
}
|
||||
|
||||
@PreviewFeature
|
||||
fun makeFileLink(
|
||||
botToken: String,
|
||||
filePath: String
|
||||
) = "https://api.telegram.org/file/bot$botToken/$filePath"
|
Loading…
Reference in New Issue
Block a user