2020-10-04 11:06:30 +00:00
|
|
|
package dev.inmo.tgbotapi.types.MessageEntity.textsources
|
2019-12-11 08:06:09 +00:00
|
|
|
|
2021-01-09 14:59:37 +00:00
|
|
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
2020-11-07 07:42:10 +00:00
|
|
|
import dev.inmo.tgbotapi.utils.internal.*
|
2021-04-12 17:23:18 +00:00
|
|
|
import kotlinx.serialization.Serializable
|
2020-01-05 13:24:17 +00:00
|
|
|
|
|
|
|
private val String.withoutCommercialAt
|
|
|
|
get() = if (startsWith("@")) {
|
|
|
|
substring(1)
|
|
|
|
} else {
|
|
|
|
this
|
|
|
|
}
|
2019-12-11 08:06:09 +00:00
|
|
|
|
2020-11-06 12:52:59 +00:00
|
|
|
/**
|
|
|
|
* @see mention
|
|
|
|
*/
|
2021-04-12 17:23:18 +00:00
|
|
|
@Serializable
|
2020-11-06 12:52:59 +00:00
|
|
|
data class MentionTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
|
2020-04-08 09:17:13 +00:00
|
|
|
override val source: String,
|
2020-11-12 10:37:17 +00:00
|
|
|
override val subsources: List<TextSource>
|
2020-01-05 13:24:17 +00:00
|
|
|
) : MultilevelTextSource {
|
2020-11-16 07:32:20 +00:00
|
|
|
override val markdown: String by lazy { source.mentionMarkdown() }
|
|
|
|
override val markdownV2: String by lazy { mentionMarkdownV2() }
|
|
|
|
override val html: String by lazy { mentionHTML() }
|
2020-11-06 12:52:59 +00:00
|
|
|
|
|
|
|
init {
|
|
|
|
if (!source.startsWith("@")) {
|
|
|
|
error("Mention source must starts with @, but actual value is \"$source\"")
|
|
|
|
}
|
|
|
|
}
|
2019-12-11 08:06:09 +00:00
|
|
|
}
|
2020-11-06 12:52:59 +00:00
|
|
|
|
|
|
|
@Suppress("NOTHING_TO_INLINE")
|
|
|
|
inline fun mention(parts: List<TextSource>) = (regular("@") + parts).let { MentionTextSource(it.makeString(), it) }
|
|
|
|
@Suppress("NOTHING_TO_INLINE")
|
|
|
|
inline fun mention(vararg parts: TextSource) = mention(parts.toList())
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Without leading "@"
|
|
|
|
*/
|
|
|
|
@Suppress("NOTHING_TO_INLINE")
|
|
|
|
inline fun mention(whoToMention: String) = mention(regular(whoToMention))
|
|
|
|
|