mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-12-08 15:25:52 +00:00
Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 41e5c579a2 | |||
| bbf63c51ec | |||
| fb91199f83 | |||
| d76c09ffb2 | |||
| acfb7066d2 | |||
| 7507c107b4 | |||
| 2acb177ad6 | |||
| b5a14077fd | |||
| 5f60bf003f | |||
| f9b2c4c403 | |||
| c909774403 | |||
| 670cfcca13 | |||
| 130e00b62b | |||
| ca4beee95f | |||
| ca784e67df | |||
| 835b8b34f9 | |||
| e6430a729c | |||
| 6c4c9f2fc6 | |||
| 310a7e6e82 | |||
| 7375894645 |
4
.github/labeler.yml
vendored
4
.github/labeler.yml
vendored
@@ -4,4 +4,6 @@ core: "TelegramBotAPI/**" # currently not work
|
||||
|
||||
code: "**/*.kt"
|
||||
gradle: "**/*.gradle"
|
||||
markdown: "**/*.md"
|
||||
markdown:
|
||||
- "**/*.md"
|
||||
- "!CHANGELOG.md"
|
||||
|
||||
29
CHANGELOG.md
29
CHANGELOG.md
@@ -49,6 +49,35 @@
|
||||
* `closePollExactAfter`
|
||||
* `closePollAfter`
|
||||
|
||||
### 0.27.7
|
||||
|
||||
* `TelegramBotAPI`:
|
||||
* Operator function `unaryPlus` was added to `RowBuilder`. Now it is possible to write `row { +button }`
|
||||
* Function `flatMatrix` was added for single-row columns
|
||||
* Operator extension `RowBuilder#plus` was added to be able to write things like `row { this + button }`
|
||||
* `TelegramBotAPI-extensions-utils`:
|
||||
* Function `InlineKeyboardMarkup` for flat keyboards was added
|
||||
* Function `ReplyKeyboardMarkup` for flat keyboards was added
|
||||
|
||||
### 0.27.6
|
||||
|
||||
* `Common`:
|
||||
* Versions:
|
||||
* `Kotlin Coroutines`: `1.3.6` -> `1.3.7`
|
||||
* `TelegramBotAPI`:
|
||||
* Interface `PossiblySentViaBot` has been added
|
||||
* Additional interface `PossiblySentViaBotCommonMessage` was added for more explicit typing declaration for
|
||||
compiler
|
||||
* Currently, only `ChannelMessage` and `CommonMessageImpl` are implementing the interface
|
||||
`PossiblySentViaBotCommonMessage`. It could be changed in future
|
||||
* Factory `buildMimeType` was added
|
||||
* `BuiltinMimeTypes` was added
|
||||
* Abstraction `ThumbedWithMimeTypeInlineQueryResult` with `thumbMimeType` field was added
|
||||
* `InlineQueryResultGif` and `InlineQueryResultMpeg4Gif` now extend `ThumbedWithMimeTypeInlineQueryResult`
|
||||
instead of `ThumbedInlineQueryResult`
|
||||
* `TelegramBotAPI-extensions-utils`:
|
||||
* New extensions `onlyCommonMessages`, `onlySentViaBot` and `withoutSentViaBot` was added
|
||||
|
||||
### 0.27.5
|
||||
|
||||
* `Common`:
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
# TelegramBotAPI
|
||||
|
||||
| Common info | [](https://github.com/KotlinBy/awesome-kotlin) [](https://teleg.one/InMoTelegramBotAPI) [](https://travis-ci.com/InsanusMokrassar/TelegramBotAPI) [](https://tgbotapi.inmo.dev/docs/index.html) |
|
||||
| Common info | [](https://github.com/KotlinBy/awesome-kotlin) [](https://travis-ci.com/InsanusMokrassar/TelegramBotAPI) |
|
||||
| -------------------------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
| Useful links | • [Examples](https://github.com/InsanusMokrassar/TelegramBotAPI-examples/) |
|
||||
| | • [Mini tutorial](https://bookstack.inmo.dev/books/telegrambotapi/chapter/introduction-tutorial) |
|
||||
| | • [](https://teleg.one/InMoTelegramBotAPI) |
|
||||
| | • [](https://tgbotapi.inmo.dev/docs/index.html) |
|
||||
| TelegramBotAPI status | [](https://bintray.com/insanusmokrassar/StandardRepository/TelegramBotAPI/_latestVersion) [](https://maven-badges.herokuapp.com/maven-central/com.github.insanusmokrassar/TelegramBotAPI) |
|
||||
| TelegramBotAPI Extensions status | [](https://bintray.com/insanusmokrassar/StandardRepository/TelegramBotAPI-extensions-api/_latestVersion) [](https://maven-badges.herokuapp.com/maven-central/com.github.insanusmokrassar/TelegramBotAPI-extensions-api) |
|
||||
| TelegramBotAPI Util Extensions status | [](https://bintray.com/insanusmokrassar/StandardRepository/TelegramBotAPI-extensions-utils/_latestVersion) [](https://maven-badges.herokuapp.com/maven-central/com.github.insanusmokrassar/TelegramBotAPI-extensions-utils) |
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.CommonMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.PossiblySentViaBotCommonMessage
|
||||
import kotlinx.coroutines.flow.*
|
||||
|
||||
/**
|
||||
* Simple factory to convert [ContentMessage] to a [CommonMessage]
|
||||
*/
|
||||
fun <C: MessageContent, T : ContentMessage<C>> Flow<T>.onlyCommonMessages() = filterIsInstance<CommonMessage<C>>()
|
||||
|
||||
/**
|
||||
* Filter the messages and checking that incoming [CommonMessage] is [PossiblySentViaBotCommonMessage] and its
|
||||
* [PossiblySentViaBotCommonMessage.senderBot] is not null
|
||||
*/
|
||||
fun <T : MessageContent> Flow<CommonMessage<T>>.onlySentViaBot() = mapNotNull {
|
||||
(it as? PossiblySentViaBotCommonMessage) ?.let { possiblySentViaBot ->
|
||||
if (possiblySentViaBot.senderBot != null) {
|
||||
possiblySentViaBot
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the messages and checking that incoming [CommonMessage] not is [PossiblySentViaBotCommonMessage] or its
|
||||
* [PossiblySentViaBotCommonMessage.senderBot] is null
|
||||
*/
|
||||
fun <T : MessageContent> Flow<CommonMessage<T>>.withoutSentViaBot() = filter {
|
||||
it !is PossiblySentViaBotCommonMessage || it.senderBot == null
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.types.buttons
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardButtons.InlineKeyboardButton
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.*
|
||||
|
||||
fun InlineKeyboardMarkup(
|
||||
vararg buttons: InlineKeyboardButton
|
||||
): InlineKeyboardMarkup = InlineKeyboardMarkup(
|
||||
flatMatrix { buttons.forEach { +it } }
|
||||
)
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.types.buttons
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.ReplyKeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardButton
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.flatMatrix
|
||||
|
||||
fun ReplyKeyboardMarkup(
|
||||
vararg buttons: KeyboardButton,
|
||||
resizeKeyboard: Boolean? = null,
|
||||
oneTimeKeyboard: Boolean? = null,
|
||||
selective: Boolean? = null
|
||||
): ReplyKeyboardMarkup = ReplyKeyboardMarkup(
|
||||
flatMatrix { buttons.forEach { +it } },
|
||||
resizeKeyboard,
|
||||
oneTimeKeyboard,
|
||||
selective
|
||||
)
|
||||
@@ -12,6 +12,13 @@ fun <T : BaseSentMessageUpdate> Flow<T>.asContentMessagesFlow() = mapNotNull {
|
||||
it.data as? ContentMessage<*>
|
||||
}
|
||||
|
||||
/**
|
||||
* Will map incoming [BaseSentMessageUpdate]s to [CommonMessage] from [BaseSentMessageUpdate.data]
|
||||
*/
|
||||
fun <T : BaseSentMessageUpdate> Flow<T>.asCommonMessagesFlow() = mapNotNull {
|
||||
it.data as? CommonMessage<*>
|
||||
}
|
||||
|
||||
/**
|
||||
* Will map incoming [BaseSentMessageUpdate]s to [ChatEventMessage] from [BaseSentMessageUpdate.data]
|
||||
*/
|
||||
|
||||
@@ -10,7 +10,7 @@ moments are describing by official [Telegram Bot API](https://core.telegram.org/
|
||||
|
||||
## Compatibility
|
||||
|
||||
This version compatible with [24th of April 2020 update of TelegramBotAPI (version 4.8)](https://core.telegram.org/bots/api#april-24-2020).
|
||||
This version compatible with [4th of June 2020 update of TelegramBotAPI (version 4.9)](https://core.telegram.org/bots/api#june-4-2020).
|
||||
There is only one exception of implemented functionality - Telegram Passport API, which was presented in
|
||||
[August 2018 update of TelegramBotAPI](https://core.telegram.org/bots/api-changelog#august-27-2018) update. It will be implemented
|
||||
as soon as possible.
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.BuiltinMimeTypes
|
||||
|
||||
typealias Identifier = Long
|
||||
typealias MessageIdentifier = Long
|
||||
typealias InlineQueryIdentifier = String
|
||||
@@ -63,6 +65,12 @@ val quizPollExplanationLimit = explanationLimit
|
||||
|
||||
val openPeriodPollSecondsLimit = 5 .. 600
|
||||
|
||||
val telegramInlineModeGifPermittedMimeTypes = listOf(
|
||||
BuiltinMimeTypes.Image.Jpg,
|
||||
BuiltinMimeTypes.Image.Gif,
|
||||
BuiltinMimeTypes.Video.MP4
|
||||
)
|
||||
|
||||
const val chatIdField = "chat_id"
|
||||
const val messageIdField = "message_id"
|
||||
const val updateIdField = "update_id"
|
||||
@@ -177,6 +185,7 @@ const val stickerFileIdField = "sticker_file_id"
|
||||
const val gameShortNameField = "game_short_name"
|
||||
|
||||
const val thumbUrlField = "thumb_url"
|
||||
const val thumbMimeTypeField = "thumb_mime_type"
|
||||
const val thumbWidthField = "thumb_width"
|
||||
const val thumbHeightField = "thumb_height"
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.abstracts.
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.MimeType
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@@ -18,6 +19,8 @@ data class InlineQueryResultGifImpl(
|
||||
override val url: String,
|
||||
@SerialName(thumbUrlField)
|
||||
override val thumbUrl: String,
|
||||
@SerialName(thumbMimeTypeField)
|
||||
override val thumbMimeType: MimeType? = null,
|
||||
@SerialName(gifWidthField)
|
||||
override val width: Int? = null,
|
||||
@SerialName(gifHeightField)
|
||||
@@ -36,4 +39,10 @@ data class InlineQueryResultGifImpl(
|
||||
override val inputMessageContent: InputMessageContent? = null
|
||||
) : InlineQueryResultGif {
|
||||
override val type: String = inlineQueryResultGifType
|
||||
|
||||
init {
|
||||
if (thumbMimeType != null && thumbMimeType !in telegramInlineModeGifPermittedMimeTypes) {
|
||||
error("Passed thumb mime type is not permitted in Telegram Bot API. Passed $thumbMimeType, but permitted $telegramInlineModeGifPermittedMimeTypes")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.abstracts.
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.MimeType
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@@ -18,6 +19,8 @@ data class InlineQueryResultMpeg4GifImpl(
|
||||
override val url: String,
|
||||
@SerialName(thumbUrlField)
|
||||
override val thumbUrl: String,
|
||||
@SerialName(thumbMimeTypeField)
|
||||
override val thumbMimeType: MimeType? = null,
|
||||
@SerialName(mpeg4GifWidthField)
|
||||
override val width: Int? = null,
|
||||
@SerialName(mpeg4GifHeightField)
|
||||
@@ -36,4 +39,10 @@ data class InlineQueryResultMpeg4GifImpl(
|
||||
override val inputMessageContent: InputMessageContent? = null
|
||||
) : InlineQueryResultMpeg4Gif {
|
||||
override val type: String = inlineQueryResultMpeg4GifType
|
||||
|
||||
init {
|
||||
if (thumbMimeType != null && thumbMimeType !in telegramInlineModeGifPermittedMimeTypes) {
|
||||
error("Passed thumb mime type is not permitted in Telegram Bot API. Passed $thumbMimeType, but permitted $telegramInlineModeGifPermittedMimeTypes")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.MimeType
|
||||
|
||||
interface ThumbedInlineQueryResult : InlineQueryResult {
|
||||
val thumbUrl: String?
|
||||
}
|
||||
|
||||
interface ThumbedWithMimeTypeInlineQueryResult : ThumbedInlineQueryResult {
|
||||
val thumbMimeType: MimeType?
|
||||
}
|
||||
@@ -2,4 +2,4 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQue
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.abstracts.*
|
||||
|
||||
interface InlineQueryResultGif : InlineQueryResultGifCommon, UrlInlineQueryResult, ThumbedInlineQueryResult, SizedInlineQueryResult, DuratedInlineResultQuery
|
||||
interface InlineQueryResultGif : InlineQueryResultGifCommon, UrlInlineQueryResult, ThumbedWithMimeTypeInlineQueryResult, SizedInlineQueryResult, DuratedInlineResultQuery
|
||||
@@ -2,4 +2,4 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQue
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.abstracts.*
|
||||
|
||||
interface InlineQueryResultMpeg4Gif : InlineQueryResultMpeg4GifCommon, UrlInlineQueryResult, ThumbedInlineQueryResult, SizedInlineQueryResult, DuratedInlineResultQuery
|
||||
interface InlineQueryResultMpeg4Gif : InlineQueryResultMpeg4GifCommon, UrlInlineQueryResult, ThumbedWithMimeTypeInlineQueryResult, SizedInlineQueryResult, DuratedInlineResultQuery
|
||||
@@ -1,12 +1,11 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.message
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.AuthorSignature
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.CommonMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.PossiblySentViaBotCommonMessage
|
||||
import com.soywiz.klock.DateTime
|
||||
|
||||
data class ChannelMessage<T: MessageContent>(
|
||||
@@ -18,5 +17,6 @@ data class ChannelMessage<T: MessageContent>(
|
||||
override val forwardInfo: ForwardInfo?,
|
||||
override val replyTo: Message?,
|
||||
override val replyMarkup: InlineKeyboardMarkup?,
|
||||
override val senderBot: CommonBot?,
|
||||
val authorSignature: AuthorSignature?
|
||||
) : CommonMessage<T>
|
||||
) : PossiblySentViaBotCommonMessage<T>
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.message
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.User
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.PossiblySentViaBotCommonMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.SuccessfulPaymentInfo
|
||||
import com.soywiz.klock.DateTime
|
||||
|
||||
@@ -19,5 +19,6 @@ data class CommonMessageImpl<T: MessageContent>(
|
||||
override val forwardInfo: ForwardInfo?,
|
||||
override val replyTo: Message?,
|
||||
override val replyMarkup: InlineKeyboardMarkup?,
|
||||
override val senderBot: CommonBot?,
|
||||
val paymentInfo: SuccessfulPaymentInfo?
|
||||
) : Message, CommonMessage<T>, FromUserMessage
|
||||
) : PossiblySentViaBotCommonMessage<T>, FromUserMessage
|
||||
@@ -42,6 +42,7 @@ internal data class RawMessage(
|
||||
private val forward_sender_name: ForwardSenderName? = null,
|
||||
private val forward_date: TelegramDate? = null,
|
||||
private val reply_to_message: RawMessage? = null,
|
||||
private val via_bot: CommonBot? = null,
|
||||
private val edit_date: TelegramDate? = null,
|
||||
private val media_group_id: MediaGroupIdentifier? = null,
|
||||
private val author_signature: AuthorSignature? = null,
|
||||
@@ -147,7 +148,7 @@ internal data class RawMessage(
|
||||
)
|
||||
forward_from_chat is ChannelChat -> ForwardFromChannelInfo(
|
||||
forward_date,
|
||||
forward_from_message_id ?: throw IllegalStateException("Channel forwarded message must contain message id, but was not"),
|
||||
forward_from_message_id ?: error("Channel forwarded message must contain message id, but was not"),
|
||||
forward_from_chat,
|
||||
forward_signature
|
||||
)
|
||||
@@ -208,7 +209,7 @@ internal data class RawMessage(
|
||||
chatEvent as? ChannelEvent ?: throwWrongChatEvent(ChannelEvent::class, chatEvent),
|
||||
date.asDate
|
||||
)
|
||||
else -> throw IllegalStateException("Expected one of the public chats, but was $chat (in extracting of chat event message)")
|
||||
else -> error("Expected one of the public chats, but was $chat (in extracting of chat event message)")
|
||||
}
|
||||
} ?: content?.let { content ->
|
||||
media_group_id?.let {
|
||||
@@ -221,7 +222,7 @@ internal data class RawMessage(
|
||||
when (content) {
|
||||
is PhotoContent -> content
|
||||
is VideoContent -> content
|
||||
else -> throw IllegalStateException("Unsupported content for media group")
|
||||
else -> error("Unsupported content for media group")
|
||||
},
|
||||
edit_date?.asDate,
|
||||
forwarded,
|
||||
@@ -237,7 +238,7 @@ internal data class RawMessage(
|
||||
when (content) {
|
||||
is PhotoContent -> content
|
||||
is VideoContent -> content
|
||||
else -> throw IllegalStateException("Unsupported content for media group")
|
||||
else -> error("Unsupported content for media group")
|
||||
},
|
||||
edit_date?.asDate,
|
||||
forwarded,
|
||||
@@ -255,12 +256,12 @@ internal data class RawMessage(
|
||||
forwarded,
|
||||
reply_to_message?.asMessage,
|
||||
reply_markup,
|
||||
via_bot,
|
||||
author_signature
|
||||
)
|
||||
else -> CommonMessageImpl(
|
||||
messageId,
|
||||
from
|
||||
?: throw IllegalStateException("Was detected common message, but owner (sender) of the message was not found"),
|
||||
from ?: error("Was detected common message, but owner (sender) of the message was not found"),
|
||||
chat,
|
||||
content,
|
||||
date.asDate,
|
||||
@@ -268,10 +269,11 @@ internal data class RawMessage(
|
||||
forwarded,
|
||||
reply_to_message?.asMessage,
|
||||
reply_markup,
|
||||
via_bot,
|
||||
paymentInfo
|
||||
)
|
||||
}
|
||||
} ?: throw IllegalStateException("Was not found supported type of data")
|
||||
} ?: error("Was not found supported type of data")
|
||||
} catch (e: Exception) {
|
||||
UnknownMessageType(
|
||||
messageId,
|
||||
@@ -283,6 +285,6 @@ internal data class RawMessage(
|
||||
}
|
||||
|
||||
private fun throwWrongChatEvent(expected: KClass<*>, but: ChatEvent): CommonEvent {
|
||||
throw IllegalStateException("Wrong type of chat event: expected $expected, but was $but")
|
||||
error("Wrong type of chat event: expected $expected, but was $but")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.CommonBot
|
||||
|
||||
interface PossiblySentViaBot {
|
||||
val senderBot: CommonBot?
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.CommonMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.PossiblySentViaBot
|
||||
|
||||
interface PossiblySentViaBotCommonMessage<T: MessageContent> : CommonMessage<T>, PossiblySentViaBot
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
||||
|
||||
object BuiltinMimeTypes {
|
||||
object Image {
|
||||
val Jpg = buildMimeType("image/jpeg")
|
||||
val Gif = buildMimeType("image/gif")
|
||||
}
|
||||
object Video {
|
||||
val MP4 = buildMimeType("video/mp4")
|
||||
}
|
||||
}
|
||||
@@ -18,12 +18,27 @@ fun <T> matrix(block: MatrixBuilder<T>.() -> Unit): Matrix<T> {
|
||||
return MatrixBuilder<T>().also(block).matrix
|
||||
}
|
||||
|
||||
fun <T> flatMatrix(block: RowBuilder<T>.() -> Unit): Matrix<T> {
|
||||
return MatrixBuilder<T>().apply {
|
||||
row(block)
|
||||
}.matrix
|
||||
}
|
||||
|
||||
fun <T> flatMatrix(vararg elements: T): Matrix<T> {
|
||||
return MatrixBuilder<T>().apply {
|
||||
row { elements.forEach { +it } }
|
||||
}.matrix
|
||||
}
|
||||
|
||||
operator fun <T> RowBuilder<T>.plus(t: T) = add(t)
|
||||
|
||||
class RowBuilder<T> {
|
||||
private val mutRow: MutableList<T> = ArrayList()
|
||||
val row: List<T>
|
||||
get() = mutRow
|
||||
|
||||
fun add(t: T) = mutRow.add(t)
|
||||
operator fun T.unaryPlus() = add(this)
|
||||
}
|
||||
|
||||
class MatrixBuilder<T> {
|
||||
|
||||
@@ -7,5 +7,7 @@ expect class MimeType {
|
||||
val raw: String
|
||||
}
|
||||
|
||||
expect fun buildMimeType(raw: String): MimeType
|
||||
|
||||
@Serializer(MimeType::class)
|
||||
internal expect object MimeTypeSerializer : KSerializer<MimeType>
|
||||
|
||||
@@ -23,7 +23,7 @@ internal actual object MimeTypeSerializer : KSerializer<MimeType> {
|
||||
override fun deserialize(decoder: Decoder): MimeType {
|
||||
val mimeType = decoder.decodeString()
|
||||
return mimesCache.getOrPut(mimeType) {
|
||||
MimeType(mimeType)
|
||||
buildMimeType(mimeType)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,3 +31,5 @@ internal actual object MimeTypeSerializer : KSerializer<MimeType> {
|
||||
encoder.encodeString(value.raw)
|
||||
}
|
||||
}
|
||||
|
||||
actual fun buildMimeType(raw: String) = MimeType(raw)
|
||||
|
||||
@@ -24,3 +24,5 @@ internal actual object MimeTypeSerializer : KSerializer<MimeType> {
|
||||
encoder.encodeString(value.raw)
|
||||
}
|
||||
}
|
||||
|
||||
actual fun buildMimeType(raw: String): MimeType = MimeType(raw)
|
||||
|
||||
@@ -63,11 +63,17 @@ private Closure includeSourcesInDokka(String... approximateNames) {
|
||||
}
|
||||
}
|
||||
|
||||
String dokkaFolder = "$buildDir/dokka"
|
||||
|
||||
dokka {
|
||||
outputFormat = 'html'
|
||||
outputDirectory = dokkaFolder
|
||||
|
||||
switch (true) {
|
||||
case project.hasProperty("DOKKA_PATH"):
|
||||
outputDirectory = project.property("DOKKA_PATH").toString()
|
||||
break
|
||||
case System.getenv("DOKKA_PATH") != null:
|
||||
outputDirectory = System.getenv("DOKKA_PATH")
|
||||
break
|
||||
}
|
||||
|
||||
multiplatform {
|
||||
global {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
kotlin.code.style=official
|
||||
kotlin_version=1.3.72
|
||||
kotlin_coroutines_version=1.3.6
|
||||
kotlin_coroutines_version=1.3.7
|
||||
kotlin_serialisation_runtime_version=0.20.0
|
||||
klock_version=1.11.3
|
||||
uuid_version=0.1.0
|
||||
@@ -9,6 +9,6 @@ ktor_version=1.3.2
|
||||
javax_activation_version=1.1.1
|
||||
|
||||
library_group=com.github.insanusmokrassar
|
||||
library_version=0.27.5
|
||||
library_version=0.27.7
|
||||
|
||||
gradle_bintray_plugin_version=1.8.4
|
||||
|
||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
|
||||
|
||||
Reference in New Issue
Block a user