mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-23 00:57:13 +00:00
commit
dc93997b8c
14
CHANGELOG.md
14
CHANGELOG.md
@ -8,6 +8,20 @@
|
||||
* `User` now have no field `userLocale`
|
||||
* For `Java` there is `User#javaLocale` extension function, which will give an old locale work way
|
||||
|
||||
### 0.20.1
|
||||
|
||||
* `User` now implement `PrivateChat`
|
||||
* `TextMentionMessageEntity` now accept `PrivateChat` instead of `User` in main constructor
|
||||
* `TextMentionMessageEntity` now contains not user, but contains `PrivateChat`
|
||||
* Fixeed: `TextMentionMessageEntity#asHtmlSource` previously worked incorrect
|
||||
* Abstraction `TextSource`
|
||||
* `MessageEntity` now extends `TextSource`
|
||||
* `createFormattedText` method now accept `List<TextSource>`
|
||||
* `createHtmlText` method now accept `List<TextSource>`
|
||||
* `createMarkdownText` method now accept `List<TextSource>`
|
||||
* A lot of `TextSource` implementors was added. More info [here](src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/)
|
||||
* All `MessageEntity` implementations now are using new `TextSource` analogues as delegates
|
||||
|
||||
## 0.19.0 ImplicitReflection removing
|
||||
|
||||
* Total rework of serialization for requests. Now all `SimpleRequest` children have:
|
||||
|
@ -17,7 +17,7 @@ plugins {
|
||||
id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version"
|
||||
}
|
||||
|
||||
project.version = "0.20.0"
|
||||
project.version = "0.20.1"
|
||||
project.group = "com.github.insanusmokrassar"
|
||||
|
||||
apply from: "publish.gradle"
|
||||
|
@ -0,0 +1,6 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts
|
||||
|
||||
interface TextSource {
|
||||
val asMarkdownSource: String
|
||||
val asHtmlSource: String
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.BoldTextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.boldHTML
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.boldMarkdown
|
||||
|
||||
@ -7,7 +9,4 @@ data class BoldTextMessageEntity(
|
||||
override val offset: Int,
|
||||
override val length: Int,
|
||||
override val sourceString: String
|
||||
) : MessageEntity {
|
||||
override val asMarkdownSource: String = sourceString.boldMarkdown()
|
||||
override val asHtmlSource: String = sourceString.boldHTML()
|
||||
}
|
||||
) : MessageEntity, TextSource by BoldTextSource(sourceString)
|
||||
|
@ -1,19 +1,16 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.BotCommandTextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.commandHTML
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.commandMarkdown
|
||||
|
||||
private val commandRegex = Regex("[/!][^@\\s]*")
|
||||
|
||||
data class BotCommandMessageEntity(
|
||||
override val offset: Int,
|
||||
override val length: Int,
|
||||
override val sourceString: String
|
||||
) : MessageEntity {
|
||||
override val asMarkdownSource: String = sourceString.commandMarkdown()
|
||||
override val asHtmlSource: String = sourceString.commandHTML()
|
||||
|
||||
val command: String by lazy {
|
||||
commandRegex.find(sourceString) ?.value ?.substring(1) ?: sourceString.substring(1)// skip first symbol like "/" or "!"
|
||||
}
|
||||
override val sourceString: String,
|
||||
private val botCommandTextSource: BotCommandTextSource = BotCommandTextSource(sourceString)
|
||||
) : MessageEntity, TextSource by botCommandTextSource {
|
||||
val command: String
|
||||
get() = botCommandTextSource.command
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.CodeTextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.codeHTML
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.codeMarkdown
|
||||
|
||||
@ -7,7 +9,4 @@ data class CodeTextMessageEntity(
|
||||
override val offset: Int,
|
||||
override val length: Int,
|
||||
override val sourceString: String
|
||||
) : MessageEntity {
|
||||
override val asMarkdownSource: String = sourceString.codeMarkdown()
|
||||
override val asHtmlSource: String = sourceString.codeHTML()
|
||||
}
|
||||
) : MessageEntity, TextSource by CodeTextSource(sourceString)
|
||||
|
@ -1,13 +1,12 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.EMailTextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.emailHTML
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.emailMarkdown
|
||||
|
||||
class EMailMessageEntity(
|
||||
data class EMailMessageEntity(
|
||||
override val offset: Int,
|
||||
override val length: Int,
|
||||
override val sourceString: String
|
||||
) : MessageEntity {
|
||||
override val asMarkdownSource: String = sourceString.emailMarkdown()
|
||||
override val asHtmlSource: String = sourceString.emailHTML()
|
||||
}
|
||||
) : MessageEntity, TextSource by EMailTextSource(sourceString)
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.HashTagTextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.hashTagHTML
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.hashTagMarkdown
|
||||
|
||||
@ -7,7 +9,4 @@ data class HashTagMessageEntity(
|
||||
override val offset: Int,
|
||||
override val length: Int,
|
||||
override val sourceString: String
|
||||
) : MessageEntity {
|
||||
override val asMarkdownSource: String = sourceString.hashTagMarkdown()
|
||||
override val asHtmlSource: String = sourceString.hashTagHTML()
|
||||
}
|
||||
) : MessageEntity, TextSource by HashTagTextSource(sourceString)
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.ItalicTextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.italicHTML
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.italicMarkdown
|
||||
|
||||
@ -7,7 +9,4 @@ data class ItalicTextMessageEntity(
|
||||
override val offset: Int,
|
||||
override val length: Int,
|
||||
override val sourceString: String
|
||||
) : MessageEntity {
|
||||
override val asMarkdownSource: String = sourceString.italicMarkdown()
|
||||
override val asHtmlSource: String = sourceString.italicHTML()
|
||||
}
|
||||
) : MessageEntity, TextSource by ItalicTextSource(sourceString)
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.MentionTextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.mentionHTML
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.mentionMarkdown
|
||||
|
||||
@ -7,7 +9,4 @@ class MentionMessageEntity(
|
||||
override val offset: Int,
|
||||
override val length: Int,
|
||||
override val sourceString: String
|
||||
) : MessageEntity {
|
||||
override val asMarkdownSource: String = sourceString.mentionMarkdown()
|
||||
override val asHtmlSource: String = sourceString.mentionHTML()
|
||||
}
|
||||
) : MessageEntity, TextSource by MentionTextSource(sourceString)
|
||||
|
@ -1,10 +1,9 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
||||
|
||||
interface MessageEntity {
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||
|
||||
interface MessageEntity : TextSource {
|
||||
val offset: Int
|
||||
val length: Int
|
||||
val sourceString: String
|
||||
|
||||
val asMarkdownSource: String
|
||||
val asHtmlSource: String
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.PhoneNumberTextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.phoneHTML
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.phoneMarkdown
|
||||
|
||||
@ -7,7 +9,4 @@ data class PhoneNumberMessageEntity(
|
||||
override val offset: Int,
|
||||
override val length: Int,
|
||||
override val sourceString: String
|
||||
) : MessageEntity {
|
||||
override val asMarkdownSource: String = sourceString.phoneMarkdown()
|
||||
override val asHtmlSource: String = sourceString.phoneHTML()
|
||||
}
|
||||
) : MessageEntity, TextSource by PhoneNumberTextSource(sourceString)
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.PreTextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.preHTML
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.preMarkdown
|
||||
|
||||
@ -7,7 +9,4 @@ data class PreTextMessageEntity(
|
||||
override val offset: Int,
|
||||
override val length: Int,
|
||||
override val sourceString: String
|
||||
) : MessageEntity {
|
||||
override val asMarkdownSource: String = sourceString.preMarkdown()
|
||||
override val asHtmlSource: String = sourceString.preHTML()
|
||||
}
|
||||
) : MessageEntity, TextSource by PreTextSource(sourceString)
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.RegularTextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.toHtml
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.toMarkdown
|
||||
|
||||
@ -7,7 +9,4 @@ data class RegularTextMessageEntity(
|
||||
override val offset: Int,
|
||||
override val length: Int,
|
||||
override val sourceString: String
|
||||
) : MessageEntity {
|
||||
override val asMarkdownSource: String = sourceString.toMarkdown()
|
||||
override val asHtmlSource: String = sourceString.toHtml()
|
||||
}
|
||||
) : MessageEntity, TextSource by RegularTextSource(sourceString)
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.TextLinkTextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.linkHTML
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.linkMarkdown
|
||||
|
||||
@ -8,7 +10,4 @@ data class TextLinkMessageEntity(
|
||||
override val length: Int,
|
||||
override val sourceString: String,
|
||||
val url: String
|
||||
) : MessageEntity {
|
||||
override val asMarkdownSource: String = sourceString.linkMarkdown(url)
|
||||
override val asHtmlSource: String = sourceString.linkHTML(url)
|
||||
}
|
||||
) : MessageEntity, TextSource by TextLinkTextSource(sourceString, url)
|
||||
|
@ -1,14 +1,23 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.TextMentionTextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.User
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PrivateChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.mentionHTML
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.mentionMarkdown
|
||||
|
||||
class TextMentionMessageEntity(
|
||||
override val offset: Int,
|
||||
override val length: Int,
|
||||
override val sourceString: String,
|
||||
val user: User
|
||||
) : MessageEntity {
|
||||
override val asMarkdownSource: String = sourceString.mentionMarkdown(user.id)
|
||||
override val asHtmlSource: String = sourceString.mentionMarkdown(user.id)
|
||||
val privateChat: PrivateChat
|
||||
) : MessageEntity, TextSource by TextMentionTextSource(sourceString, privateChat) {
|
||||
@Deprecated("Deprecated due to the fact that there is more common constructor")
|
||||
constructor(
|
||||
offset: Int,
|
||||
length: Int,
|
||||
sourceString: String,
|
||||
user: User
|
||||
) : this(offset, length, sourceString, user as PrivateChat)
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.URLTextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.linkHTML
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.linkMarkdown
|
||||
|
||||
@ -7,9 +9,6 @@ data class URLMessageEntity(
|
||||
override val offset: Int,
|
||||
override val length: Int,
|
||||
override val sourceString: String
|
||||
) : MessageEntity{
|
||||
) : MessageEntity, TextSource by URLTextSource(sourceString) {
|
||||
val url: String = sourceString
|
||||
|
||||
override val asMarkdownSource: String = sourceString.linkMarkdown(url)
|
||||
override val asHtmlSource: String = sourceString.linkHTML(url)
|
||||
}
|
||||
|
@ -0,0 +1,12 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.boldHTML
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.boldMarkdown
|
||||
|
||||
class BoldTextSource(
|
||||
sourceString: String
|
||||
) : TextSource {
|
||||
override val asMarkdownSource: String = sourceString.boldMarkdown()
|
||||
override val asHtmlSource: String = sourceString.boldHTML()
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.commandHTML
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.commandMarkdown
|
||||
|
||||
private val commandRegex = Regex("[/!][^@\\s]*")
|
||||
|
||||
class BotCommandTextSource(
|
||||
sourceString: String
|
||||
) : TextSource {
|
||||
override val asMarkdownSource: String = sourceString.commandMarkdown()
|
||||
override val asHtmlSource: String = sourceString.commandHTML()
|
||||
|
||||
val command: String by lazy {
|
||||
commandRegex.find(sourceString) ?.value ?.substring(1) ?: sourceString.substring(1)// skip first symbol like "/" or "!"
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.codeHTML
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.codeMarkdown
|
||||
|
||||
class CodeTextSource(
|
||||
sourceString: String
|
||||
) : TextSource {
|
||||
override val asMarkdownSource: String = sourceString.codeMarkdown()
|
||||
override val asHtmlSource: String = sourceString.codeHTML()
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.emailHTML
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.emailMarkdown
|
||||
|
||||
class EMailTextSource(
|
||||
sourceString: String
|
||||
) : TextSource {
|
||||
override val asMarkdownSource: String = sourceString.emailMarkdown()
|
||||
override val asHtmlSource: String = sourceString.emailHTML()
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.hashTagHTML
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.hashTagMarkdown
|
||||
|
||||
class HashTagTextSource(
|
||||
sourceString: String
|
||||
) : TextSource {
|
||||
override val asMarkdownSource: String = sourceString.hashTagMarkdown()
|
||||
override val asHtmlSource: String = sourceString.hashTagHTML()
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.italicHTML
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.italicMarkdown
|
||||
|
||||
class ItalicTextSource(
|
||||
sourceString: String
|
||||
) : TextSource {
|
||||
override val asMarkdownSource: String = sourceString.italicMarkdown()
|
||||
override val asHtmlSource: String = sourceString.italicHTML()
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.mentionHTML
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.mentionMarkdown
|
||||
|
||||
class MentionTextSource(
|
||||
sourceString: String
|
||||
) : TextSource {
|
||||
override val asMarkdownSource: String = sourceString.mentionMarkdown()
|
||||
override val asHtmlSource: String = sourceString.mentionHTML()
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.phoneHTML
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.phoneMarkdown
|
||||
|
||||
class PhoneNumberTextSource(
|
||||
sourceString: String
|
||||
) : TextSource {
|
||||
override val asMarkdownSource: String = sourceString.phoneMarkdown()
|
||||
override val asHtmlSource: String = sourceString.phoneHTML()
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.preHTML
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.preMarkdown
|
||||
|
||||
class PreTextSource(
|
||||
sourceString: String
|
||||
) : TextSource {
|
||||
override val asMarkdownSource: String = sourceString.preMarkdown()
|
||||
override val asHtmlSource: String = sourceString.preHTML()
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.toHtml
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.toMarkdown
|
||||
|
||||
class RegularTextSource(
|
||||
sourceString: String
|
||||
) : TextSource {
|
||||
override val asMarkdownSource: String = sourceString.toMarkdown()
|
||||
override val asHtmlSource: String = sourceString.toHtml()
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.linkHTML
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.linkMarkdown
|
||||
|
||||
class TextLinkTextSource(
|
||||
sourceString: String,
|
||||
url: String
|
||||
) : TextSource {
|
||||
override val asMarkdownSource: String = sourceString.linkMarkdown(url)
|
||||
override val asHtmlSource: String = sourceString.linkHTML(url)
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.User
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PrivateChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.mentionHTML
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.mentionMarkdown
|
||||
|
||||
class TextMentionTextSource(
|
||||
sourceString: String,
|
||||
privateChat: PrivateChat
|
||||
) : TextSource {
|
||||
@Deprecated("Deprecated due to the fact that there is more common constructor")
|
||||
constructor(
|
||||
sourceString: String,
|
||||
user: User
|
||||
) : this(sourceString, user as PrivateChat)
|
||||
|
||||
override val asMarkdownSource: String = sourceString.mentionMarkdown(privateChat.id)
|
||||
override val asHtmlSource: String = sourceString.mentionHTML(privateChat.id)
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.linkHTML
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.linkMarkdown
|
||||
|
||||
class URLTextSource(
|
||||
sourceString: String
|
||||
) : TextSource{
|
||||
override val asMarkdownSource: String = sourceString.linkMarkdown(sourceString)
|
||||
override val asHtmlSource: String = sourceString.linkHTML(sourceString)
|
||||
}
|
@ -1,19 +1,20 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PrivateChat
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class User(
|
||||
val id: ChatId,
|
||||
override val id: ChatId,
|
||||
@SerialName(isBotField)
|
||||
val isBot: Boolean = false,
|
||||
@SerialName(firstNameField)
|
||||
val firstName: String,
|
||||
override val firstName: String,
|
||||
@SerialName(lastNameField)
|
||||
val lastName: String? = null,
|
||||
override val lastName: String = "",
|
||||
@SerialName(usernameField)
|
||||
val username: Username? = null,
|
||||
override val username: Username? = null,
|
||||
@SerialName(languageCodeField)
|
||||
val languageCode: String? = null
|
||||
)
|
||||
) : PrivateChat
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedInput
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.RegularTextMessageEntity
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.*
|
||||
@ -37,7 +38,7 @@ fun convertToFullMessageEntityList(
|
||||
}
|
||||
|
||||
fun createFormattedText(
|
||||
entities: List<MessageEntity>,
|
||||
entities: List<TextSource>,
|
||||
partLength: Int = 4096,
|
||||
mode: ParseMode = MarkdownParseMode
|
||||
): List<String> {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedInput
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.HTMLParseMode
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.captionLength
|
||||
@ -8,7 +9,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.TextCont
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.textLength
|
||||
|
||||
fun createHtmlText(
|
||||
entities: List<MessageEntity>,
|
||||
entities: List<TextSource>,
|
||||
partLength: Int = 4096
|
||||
): List<String> = createFormattedText(entities, partLength, HTMLParseMode)
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedInput
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.MarkdownParseMode
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.captionLength
|
||||
@ -8,7 +9,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.TextCont
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.textLength
|
||||
|
||||
fun createMarkdownText(
|
||||
entities: List<MessageEntity>,
|
||||
entities: List<TextSource>,
|
||||
partLength: Int = 4096
|
||||
): List<String> = createFormattedText(entities, partLength, MarkdownParseMode)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user