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