mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-23 00:57:13 +00:00
remove different internal strings things
This commit is contained in:
parent
1b15748f65
commit
a882a212c2
@ -1,55 +0,0 @@
|
||||
package dev.inmo.tgbotapi.utils.internal
|
||||
|
||||
import dev.inmo.tgbotapi.types.MediaGroupIdentifier
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
|
||||
import dev.inmo.tgbotapi.types.update.*
|
||||
import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.*
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
|
||||
private inline val Pair<MediaGroupMessage, *>.message
|
||||
get() = first
|
||||
|
||||
internal fun List<BaseMessageUpdate>.convertWithMediaGroupUpdates(): List<Update> {
|
||||
val resultUpdates = mutableListOf<Update>()
|
||||
val mediaGroups = mutableMapOf<MediaGroupIdentifier, MutableList<BaseMessageUpdate>>()
|
||||
for (update in this) {
|
||||
val asEditMediaGroupMessage = update.toEditMediaGroupUpdate()
|
||||
if (asEditMediaGroupMessage != null) {
|
||||
resultUpdates.add(asEditMediaGroupMessage)
|
||||
} else {
|
||||
val data = update.data
|
||||
if (data is MediaGroupMessage) {
|
||||
(mediaGroups[data.mediaGroupId] ?: mutableListOf<BaseMessageUpdate>().also { mediaGroups[data.mediaGroupId] = it }).add(update)
|
||||
} else {
|
||||
resultUpdates.add(update)
|
||||
}
|
||||
}
|
||||
}
|
||||
mediaGroups.values.map {
|
||||
it.toSentMediaGroupUpdate() ?.let { mediaGroupUpdate ->
|
||||
resultUpdates.add(mediaGroupUpdate)
|
||||
}
|
||||
}
|
||||
return resultUpdates.sortedBy { it.updateId }
|
||||
}
|
||||
|
||||
internal fun List<BaseMessageUpdate>.toSentMediaGroupUpdate(): SentMediaGroupUpdate? = (this as? SentMediaGroupUpdate) ?: let {
|
||||
if (isEmpty()) {
|
||||
return@let null
|
||||
}
|
||||
val resultList = sortedBy { it.updateId }
|
||||
when (first()) {
|
||||
is MessageUpdate -> MessageMediaGroupUpdate(resultList)
|
||||
is ChannelPostUpdate -> ChannelPostMediaGroupUpdate(resultList)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
internal fun BaseMessageUpdate.toEditMediaGroupUpdate(): EditMediaGroupUpdate? = (this as? EditMediaGroupUpdate) ?: let {
|
||||
when (this) {
|
||||
is EditMessageUpdate -> EditMessageMediaGroupUpdate(this)
|
||||
is EditChannelPostUpdate -> EditChannelPostMediaGroupUpdate(this)
|
||||
else -> null
|
||||
}
|
||||
}
|
@ -57,12 +57,6 @@ internal fun TextSourcesList.toMarkdownTexts(): List<String> = createMarkdownTex
|
||||
)
|
||||
internal fun TextContent.toMarkdownTexts(): List<String> = textSources.toMarkdownTexts()
|
||||
|
||||
internal fun TextSourcesList.toMarkdownExplanations(): List<String> = createMarkdownText(
|
||||
this,
|
||||
explanationLimit.last
|
||||
)
|
||||
internal fun ExplainedInput.toMarkdownExplanations(): List<String> = textSources.toMarkdownTexts()
|
||||
|
||||
|
||||
internal fun createMarkdownV2Text(
|
||||
entities: TextSourcesList,
|
||||
@ -81,12 +75,6 @@ internal fun TextSourcesList.toMarkdownV2Texts(): List<String> = createMarkdownV
|
||||
)
|
||||
internal fun TextContent.toMarkdownV2Texts(): List<String> = textSources.toMarkdownV2Texts()
|
||||
|
||||
internal fun TextSourcesList.toMarkdownV2Explanations(): List<String> = createMarkdownV2Text(
|
||||
this,
|
||||
explanationLimit.last
|
||||
)
|
||||
internal fun ExplainedInput.toMarkdownV2Explanations(): List<String> = textSources.toMarkdownV2Texts()
|
||||
|
||||
|
||||
internal fun createHtmlText(
|
||||
entities: TextSourcesList,
|
||||
|
@ -148,8 +148,3 @@ internal fun MultilevelTextSource.hashTagHTML(): String = optionalPrefix("#") +
|
||||
|
||||
internal fun MultilevelTextSource.phoneMarkdownV2(): String = subsources.joinSubSourcesMarkdownV2()
|
||||
internal fun MultilevelTextSource.phoneHTML(): String = subsources.joinSubSourcesHtml()
|
||||
|
||||
|
||||
internal fun MultilevelTextSource.commandMarkdownV2(): String = optionalPrefix("/") + subsources.joinSubSourcesMarkdownV2()
|
||||
internal fun MultilevelTextSource.commandHTML(): String = optionalPrefix("/") + subsources.joinSubSourcesHtml()
|
||||
|
||||
|
@ -99,12 +99,10 @@ private inline fun String.hashTag(adapt: String.() -> String): String = if (star
|
||||
}
|
||||
|
||||
internal fun String.textMentionMarkdown(userId: UserId): String = linkMarkdown(userId.link)
|
||||
internal fun String.textMentionMarkdownV2(userId: UserId): String = linkMarkdownV2(userId.link)
|
||||
|
||||
internal fun String.mentionMarkdown(): String = mention(String::toMarkdown)
|
||||
|
||||
internal fun String.hashTagMarkdown(): String = hashTag(String::toMarkdown)
|
||||
internal fun String.hashTagHTML(): String = hashTag(String::toHtml)
|
||||
|
||||
internal fun String.phoneMarkdown(): String = toMarkdown()
|
||||
|
||||
@ -136,14 +134,6 @@ internal infix fun Pair<String, String>.link(parseMode: ParseMode): String = whe
|
||||
is MarkdownV2 -> first.linkMarkdownV2(second)
|
||||
}
|
||||
|
||||
|
||||
internal infix fun String.command(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> commandHTML()
|
||||
is Markdown -> commandMarkdown()
|
||||
is MarkdownV2 -> commandMarkdownV2()
|
||||
}
|
||||
|
||||
|
||||
internal infix fun String.underline(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> underlineHTML()
|
||||
is Markdown -> underlineMarkdown()
|
||||
|
Loading…
Reference in New Issue
Block a user