mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-26 12:08:43 +00:00
a little bit improve EntitiesBuilder
This commit is contained in:
parent
324018a0f6
commit
f0f18209f3
@ -1,128 +1,140 @@
|
||||
@file:Suppress("NOTHING_TO_INLINE")
|
||||
|
||||
package dev.inmo.tgbotapi.extensions.utils.formatting
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
|
||||
import dev.inmo.tgbotapi.types.User
|
||||
|
||||
fun buildEntities(init: EntitiesBuilder.() -> Unit): List<TextSource> {
|
||||
val builder = EntitiesBuilder()
|
||||
builder.init()
|
||||
return builder.build()
|
||||
}
|
||||
fun buildEntities(init: EntitiesBuilder.() -> Unit): List<TextSource> = EntitiesBuilder().apply(init).build()
|
||||
|
||||
/**
|
||||
* This builder can be used to provide building of [TextSource]s [List]
|
||||
*
|
||||
* @see buildEntities
|
||||
*/
|
||||
class EntitiesBuilder internal constructor(
|
||||
private val entitiesList: MutableList<TextSource> = mutableListOf()
|
||||
) {
|
||||
fun build(): List<TextSource> {
|
||||
return entitiesList
|
||||
}
|
||||
/**
|
||||
* It is not safe field which contains potentially changeable [List]
|
||||
*/
|
||||
val entities: List<TextSource>
|
||||
get() = entitiesList
|
||||
|
||||
fun add(source: TextSource) {
|
||||
entitiesList.add(source)
|
||||
}
|
||||
/**
|
||||
* @return New immutable list which will be deattached from this builder
|
||||
*/
|
||||
fun build(): List<TextSource> = entities.toList()
|
||||
|
||||
fun add(source: TextSource) { entitiesList.add(source) }
|
||||
|
||||
operator fun TextSource.unaryPlus() = add(this)
|
||||
operator fun List<TextSource>.unaryPlus() = entitiesList.addAll(this)
|
||||
operator fun invoke(vararg source: TextSource) = entitiesList.addAll(source)
|
||||
|
||||
operator fun String.unaryPlus() {
|
||||
add(dev.inmo.tgbotapi.types.MessageEntity.textsources.regular(this))
|
||||
}
|
||||
}
|
||||
|
||||
fun EntitiesBuilder.bold(parts: List<TextSource>) = add(dev.inmo.tgbotapi.types.MessageEntity.textsources.bold(parts))
|
||||
inline fun EntitiesBuilder.bold(parts: List<TextSource>) = add(dev.inmo.tgbotapi.types.MessageEntity.textsources.bold(parts))
|
||||
|
||||
fun EntitiesBuilder.bold(vararg parts: TextSource) =
|
||||
inline fun EntitiesBuilder.bold(vararg parts: TextSource) =
|
||||
add(dev.inmo.tgbotapi.types.MessageEntity.textsources.bold(*parts))
|
||||
|
||||
fun EntitiesBuilder.bold(text: String) = add(dev.inmo.tgbotapi.types.MessageEntity.textsources.bold(text))
|
||||
inline fun EntitiesBuilder.bold(text: String) = add(dev.inmo.tgbotapi.types.MessageEntity.textsources.bold(text))
|
||||
|
||||
fun EntitiesBuilder.botCommand(command: String) =
|
||||
inline fun EntitiesBuilder.botCommand(command: String) =
|
||||
add(dev.inmo.tgbotapi.types.MessageEntity.textsources.botCommand(command))
|
||||
|
||||
fun EntitiesBuilder.cashTag(parts: List<TextSource>) =
|
||||
inline fun EntitiesBuilder.cashTag(parts: List<TextSource>) =
|
||||
add(dev.inmo.tgbotapi.types.MessageEntity.textsources.cashTag(parts))
|
||||
|
||||
fun EntitiesBuilder.cashTag(vararg parts: TextSource) =
|
||||
inline fun EntitiesBuilder.cashTag(vararg parts: TextSource) =
|
||||
add(dev.inmo.tgbotapi.types.MessageEntity.textsources.cashTag(*parts))
|
||||
|
||||
fun EntitiesBuilder.cashTag(text: String) = add(dev.inmo.tgbotapi.types.MessageEntity.textsources.cashTag(text))
|
||||
inline fun EntitiesBuilder.cashTag(text: String) = add(dev.inmo.tgbotapi.types.MessageEntity.textsources.cashTag(text))
|
||||
|
||||
fun EntitiesBuilder.code(code: String) = add(dev.inmo.tgbotapi.types.MessageEntity.textsources.code(code))
|
||||
inline fun EntitiesBuilder.code(code: String) = add(dev.inmo.tgbotapi.types.MessageEntity.textsources.code(code))
|
||||
|
||||
fun EntitiesBuilder.email(parts: List<TextSource>) =
|
||||
inline fun EntitiesBuilder.email(parts: List<TextSource>) =
|
||||
add(dev.inmo.tgbotapi.types.MessageEntity.textsources.email(parts))
|
||||
|
||||
fun EntitiesBuilder.email(vararg parts: TextSource) =
|
||||
inline fun EntitiesBuilder.email(vararg parts: TextSource) =
|
||||
add(dev.inmo.tgbotapi.types.MessageEntity.textsources.email(*parts))
|
||||
|
||||
fun EntitiesBuilder.email(emailAddress: String) =
|
||||
inline fun EntitiesBuilder.email(emailAddress: String) =
|
||||
add(dev.inmo.tgbotapi.types.MessageEntity.textsources.email(emailAddress))
|
||||
|
||||
fun EntitiesBuilder.hashtag(parts: List<TextSource>) =
|
||||
inline fun EntitiesBuilder.hashtag(parts: List<TextSource>) =
|
||||
add(dev.inmo.tgbotapi.types.MessageEntity.textsources.hashtag(parts))
|
||||
|
||||
fun EntitiesBuilder.hashtag(vararg parts: TextSource) =
|
||||
inline fun EntitiesBuilder.hashtag(vararg parts: TextSource) =
|
||||
add(dev.inmo.tgbotapi.types.MessageEntity.textsources.hashtag(*parts))
|
||||
|
||||
fun EntitiesBuilder.hashtag(hashtag: String) = add(dev.inmo.tgbotapi.types.MessageEntity.textsources.hashtag(hashtag))
|
||||
inline fun EntitiesBuilder.hashtag(hashtag: String) = add(dev.inmo.tgbotapi.types.MessageEntity.textsources.hashtag(hashtag))
|
||||
|
||||
fun EntitiesBuilder.italic(parts: List<TextSource>) =
|
||||
inline fun EntitiesBuilder.italic(parts: List<TextSource>) =
|
||||
add(dev.inmo.tgbotapi.types.MessageEntity.textsources.italic(parts))
|
||||
|
||||
fun EntitiesBuilder.italic(vararg parts: TextSource) =
|
||||
inline fun EntitiesBuilder.italic(vararg parts: TextSource) =
|
||||
add(dev.inmo.tgbotapi.types.MessageEntity.textsources.italic(*parts))
|
||||
|
||||
fun EntitiesBuilder.italic(text: String) = add(dev.inmo.tgbotapi.types.MessageEntity.textsources.italic(text))
|
||||
inline fun EntitiesBuilder.italic(text: String) = add(dev.inmo.tgbotapi.types.MessageEntity.textsources.italic(text))
|
||||
|
||||
fun EntitiesBuilder.mention(parts: List<TextSource>) =
|
||||
inline fun EntitiesBuilder.mention(parts: List<TextSource>) =
|
||||
add(dev.inmo.tgbotapi.types.MessageEntity.textsources.mention(parts))
|
||||
|
||||
fun EntitiesBuilder.mention(vararg parts: TextSource) =
|
||||
inline fun EntitiesBuilder.mention(vararg parts: TextSource) =
|
||||
add(dev.inmo.tgbotapi.types.MessageEntity.textsources.mention(*parts))
|
||||
|
||||
fun EntitiesBuilder.mention(whoToMention: String) =
|
||||
inline fun EntitiesBuilder.mention(whoToMention: String) =
|
||||
add(dev.inmo.tgbotapi.types.MessageEntity.textsources.mention(whoToMention))
|
||||
|
||||
fun EntitiesBuilder.mention(parts: List<TextSource>, user: User) =
|
||||
inline fun EntitiesBuilder.mention(parts: List<TextSource>, user: User) =
|
||||
add(dev.inmo.tgbotapi.types.MessageEntity.textsources.mention(parts, user))
|
||||
|
||||
fun EntitiesBuilder.mention(user: User, vararg parts: TextSource) =
|
||||
inline fun EntitiesBuilder.mention(user: User, vararg parts: TextSource) =
|
||||
add(dev.inmo.tgbotapi.types.MessageEntity.textsources.mention(user, *parts))
|
||||
|
||||
fun EntitiesBuilder.mention(text: String, user: User) =
|
||||
inline fun EntitiesBuilder.mention(text: String, user: User) =
|
||||
add(dev.inmo.tgbotapi.types.MessageEntity.textsources.mention(text, user))
|
||||
|
||||
fun EntitiesBuilder.phone(parts: List<TextSource>) =
|
||||
inline fun EntitiesBuilder.phone(parts: List<TextSource>) =
|
||||
add(dev.inmo.tgbotapi.types.MessageEntity.textsources.phone(parts))
|
||||
|
||||
fun EntitiesBuilder.phone(vararg parts: TextSource) =
|
||||
inline fun EntitiesBuilder.phone(vararg parts: TextSource) =
|
||||
add(dev.inmo.tgbotapi.types.MessageEntity.textsources.phone(*parts))
|
||||
|
||||
fun EntitiesBuilder.phone(number: String) =
|
||||
inline fun EntitiesBuilder.phone(number: String) =
|
||||
add(dev.inmo.tgbotapi.types.MessageEntity.textsources.phone(number))
|
||||
|
||||
fun EntitiesBuilder.pre(code: String, language: String?) =
|
||||
inline fun EntitiesBuilder.pre(code: String, language: String?) =
|
||||
add(dev.inmo.tgbotapi.types.MessageEntity.textsources.pre(code, language))
|
||||
|
||||
fun EntitiesBuilder.regular(text: String) =
|
||||
inline fun EntitiesBuilder.regular(text: String) =
|
||||
add(dev.inmo.tgbotapi.types.MessageEntity.textsources.regular(text))
|
||||
|
||||
fun EntitiesBuilder.strikethrough(parts: List<TextSource>) =
|
||||
inline fun EntitiesBuilder.strikethrough(parts: List<TextSource>) =
|
||||
add(dev.inmo.tgbotapi.types.MessageEntity.textsources.strikethrough(parts))
|
||||
|
||||
fun EntitiesBuilder.strikethrough(vararg parts: TextSource) =
|
||||
inline fun EntitiesBuilder.strikethrough(vararg parts: TextSource) =
|
||||
add(dev.inmo.tgbotapi.types.MessageEntity.textsources.strikethrough(*parts))
|
||||
|
||||
fun EntitiesBuilder.strikethrough(text: String) =
|
||||
inline fun EntitiesBuilder.strikethrough(text: String) =
|
||||
add(dev.inmo.tgbotapi.types.MessageEntity.textsources.strikethrough(text))
|
||||
|
||||
fun EntitiesBuilder.link(text: String, url: String) =
|
||||
inline fun EntitiesBuilder.link(text: String, url: String) =
|
||||
add(dev.inmo.tgbotapi.types.MessageEntity.textsources.link(text, url))
|
||||
|
||||
fun EntitiesBuilder.link(url: String) =
|
||||
inline fun EntitiesBuilder.link(url: String) =
|
||||
add(dev.inmo.tgbotapi.types.MessageEntity.textsources.link(url))
|
||||
|
||||
fun EntitiesBuilder.underline(parts: List<TextSource>) =
|
||||
inline fun EntitiesBuilder.underline(parts: List<TextSource>) =
|
||||
add(dev.inmo.tgbotapi.types.MessageEntity.textsources.underline(parts))
|
||||
|
||||
fun EntitiesBuilder.underline(vararg parts: TextSource) =
|
||||
inline fun EntitiesBuilder.underline(vararg parts: TextSource) =
|
||||
add(dev.inmo.tgbotapi.types.MessageEntity.textsources.underline(*parts))
|
||||
|
||||
fun EntitiesBuilder.underline(text: String) =
|
||||
inline fun EntitiesBuilder.underline(text: String) =
|
||||
add(dev.inmo.tgbotapi.types.MessageEntity.textsources.underline(text))
|
||||
|
Loading…
Reference in New Issue
Block a user