1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 16:23:48 +00:00

add support of external_reply in RawMessage

This commit is contained in:
InsanusMokrassar 2024-01-07 19:38:22 +06:00
parent 95011e2b3e
commit f3b05bbffd
27 changed files with 241 additions and 219 deletions

View File

@ -16,4 +16,4 @@ data class Contact(
val userId: UserId? = null, val userId: UserId? = null,
@SerialName(vcardField) @SerialName(vcardField)
override val vcard: String? = null override val vcard: String? = null
) : CommonContactData, ExternalReplyInfo.ContentVariant ) : CommonContactData, ReplyInfo.External.ContentVariant

View File

@ -1,166 +0,0 @@
package dev.inmo.tgbotapi.types
import dev.inmo.tgbotapi.abstracts.SpoilerableData
import dev.inmo.tgbotapi.types.chat.SuperPublicChat
import dev.inmo.tgbotapi.types.dice.Dice
import dev.inmo.tgbotapi.types.files.*
import dev.inmo.tgbotapi.types.games.Game
import dev.inmo.tgbotapi.types.games.RawGame
import dev.inmo.tgbotapi.types.giveaway.GiveawayPublicResults
import dev.inmo.tgbotapi.types.giveaway.ScheduledGiveaway
import dev.inmo.tgbotapi.types.location.Location
import dev.inmo.tgbotapi.types.message.MessageOrigin
import dev.inmo.tgbotapi.types.message.abstracts.Message
import dev.inmo.tgbotapi.types.payments.Invoice
import dev.inmo.tgbotapi.types.polls.Poll
import dev.inmo.tgbotapi.types.stories.Story
import dev.inmo.tgbotapi.types.venue.Venue
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.ClassCastsIncluded
import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
@Serializable(ExternalReplyInfo.Companion::class)
@ClassCastsIncluded
sealed interface ExternalReplyInfo {
val origin: MessageOrigin
val chat: SuperPublicChat?
val messageMeta: Message.MetaInfo?
interface ContentVariant
@Serializable
data class Text(
override val origin: MessageOrigin,
override val chat: SuperPublicChat?,
override val messageMeta: Message.MetaInfo?,
val linkPreviewOptions: LinkPreviewOptions?
) : ExternalReplyInfo
@Serializable(ExternalReplyInfo.Companion::class)
sealed interface Content : ExternalReplyInfo {
val content: ContentVariant
@Serializable
data class Simple(
override val origin: MessageOrigin,
override val chat: SuperPublicChat?,
override val messageMeta: Message.MetaInfo?,
override val content: ContentVariant
) : Content
@Serializable
data class Media<T>(
override val origin: MessageOrigin,
override val chat: SuperPublicChat?,
override val messageMeta: Message.MetaInfo?,
override val spoilered: Boolean,
override val content: T
) : Content, SpoilerableData where T: ContentVariant, T : TelegramMediaFile
}
@Serializable
private data class Surrogate(
val origin: MessageOrigin,
val chat: SuperPublicChat? = null,
val message_id: MessageId? = null,
val link_preview_options: LinkPreviewOptions? = null,
val has_media_spoiler: Boolean? = null,
private val story: Story? = null,
private val audio: AudioFile? = null,
private val document: DocumentFile? = null,
private val animation: AnimationFile? = null,
private val game: RawGame? = null,
@Serializable(PhotoSerializer::class)
private val photo: Photo? = null,
private val sticker: Sticker? = null,
private val video: VideoFile? = null,
private val voice: VoiceFile? = null,
private val video_note: VideoNoteFile? = null,
private val contact: Contact? = null,
private val location: Location? = null,
private val venue: Venue? = null,
private val poll: Poll? = null,
private val invoice: Invoice? = null,
private val dice: Dice? = null,
private val giveaway: ScheduledGiveaway? = null,
private val giveaway_winners: GiveawayPublicResults? = null,
) {
val asExternalReplyInfo: ExternalReplyInfo
get() {
val messageMeta = chat ?.let {
message_id ?.let {
Message.MetaInfo(
chat.id,
message_id
)
}
}
val content: ContentVariant? = when {
story != null -> story
audio != null -> audio
video != null -> video
video_note != null -> video_note
animation != null -> animation
document != null -> document
voice != null -> voice
photo != null -> photo
sticker != null -> sticker
dice != null -> dice
game != null -> game.asGame
contact != null -> contact
location != null -> location
venue != null -> venue
poll != null -> poll
invoice != null -> invoice
giveaway != null -> giveaway
giveaway_winners != null -> giveaway_winners
else -> null
}
return content ?.let {
when (it) {
is TelegramMediaFile -> {
Content.Media(
origin,
chat,
messageMeta,
has_media_spoiler == true,
it
)
}
else -> Content.Simple(
origin,
chat,
messageMeta,
it
)
}
} ?: Text(
origin,
chat,
messageMeta,
link_preview_options
)
}
}
@RiskFeature("This serializer currently support only deserialization, but not serialization")
companion object : KSerializer<ExternalReplyInfo> {
override val descriptor: SerialDescriptor
get() = Surrogate.serializer().descriptor
override fun deserialize(decoder: Decoder): ExternalReplyInfo {
return Surrogate.serializer().deserialize(decoder).asExternalReplyInfo
}
override fun serialize(encoder: Encoder, value: ExternalReplyInfo) {
}
}
}

View File

@ -0,0 +1,175 @@
package dev.inmo.tgbotapi.types
import dev.inmo.tgbotapi.abstracts.SpoilerableData
import dev.inmo.tgbotapi.types.chat.SuperPublicChat
import dev.inmo.tgbotapi.types.dice.Dice
import dev.inmo.tgbotapi.types.files.*
import dev.inmo.tgbotapi.types.games.RawGame
import dev.inmo.tgbotapi.types.giveaway.GiveawayPublicResults
import dev.inmo.tgbotapi.types.giveaway.ScheduledGiveaway
import dev.inmo.tgbotapi.types.location.Location
import dev.inmo.tgbotapi.types.message.MessageOrigin
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
import dev.inmo.tgbotapi.types.message.abstracts.Message
import dev.inmo.tgbotapi.types.payments.Invoice
import dev.inmo.tgbotapi.types.polls.Poll
import dev.inmo.tgbotapi.types.stories.Story
import dev.inmo.tgbotapi.types.venue.Venue
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.ClassCastsIncluded
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
@ClassCastsIncluded
sealed interface ReplyInfo {
val messageMeta: Message.MetaInfo?
data class Internal(
val message: AccessibleMessage
): ReplyInfo {
override val messageMeta: Message.MetaInfo
get() = message.metaInfo
}
@Serializable(External.Companion::class)
sealed interface External : ReplyInfo {
val origin: MessageOrigin
val chat: SuperPublicChat?
interface ContentVariant
@Serializable
data class Text(
override val origin: MessageOrigin,
override val chat: SuperPublicChat?,
override val messageMeta: Message.MetaInfo?,
val linkPreviewOptions: LinkPreviewOptions?
) : External
@Serializable(External.Companion::class)
sealed interface Content : External {
val content: ContentVariant
@Serializable
data class Simple(
override val origin: MessageOrigin,
override val chat: SuperPublicChat?,
override val messageMeta: Message.MetaInfo?,
override val content: ContentVariant
) : Content
@Serializable
data class Media<T>(
override val origin: MessageOrigin,
override val chat: SuperPublicChat?,
override val messageMeta: Message.MetaInfo?,
override val spoilered: Boolean,
override val content: T
) : Content, SpoilerableData where T: ContentVariant, T : TelegramMediaFile
}
@Serializable
private data class Surrogate(
val origin: MessageOrigin,
val chat: SuperPublicChat? = null,
val message_id: MessageId? = null,
val link_preview_options: LinkPreviewOptions? = null,
val has_media_spoiler: Boolean? = null,
private val story: Story? = null,
private val audio: AudioFile? = null,
private val document: DocumentFile? = null,
private val animation: AnimationFile? = null,
private val game: RawGame? = null,
@Serializable(PhotoSerializer::class)
private val photo: Photo? = null,
private val sticker: Sticker? = null,
private val video: VideoFile? = null,
private val voice: VoiceFile? = null,
private val video_note: VideoNoteFile? = null,
private val contact: Contact? = null,
private val location: Location? = null,
private val venue: Venue? = null,
private val poll: Poll? = null,
private val invoice: Invoice? = null,
private val dice: Dice? = null,
private val giveaway: ScheduledGiveaway? = null,
private val giveaway_winners: GiveawayPublicResults? = null,
) {
val asExternalReplyInfo: External
get() {
val messageMeta = chat ?.let {
message_id ?.let {
Message.MetaInfo(
chat.id,
message_id
)
}
}
val content: ContentVariant? = when {
story != null -> story
audio != null -> audio
video != null -> video
video_note != null -> video_note
animation != null -> animation
document != null -> document
voice != null -> voice
photo != null -> photo
sticker != null -> sticker
dice != null -> dice
game != null -> game.asGame
contact != null -> contact
location != null -> location
venue != null -> venue
poll != null -> poll
invoice != null -> invoice
giveaway != null -> giveaway
giveaway_winners != null -> giveaway_winners
else -> null
}
return content ?.let {
when (it) {
is TelegramMediaFile -> {
Content.Media(
origin,
chat,
messageMeta,
has_media_spoiler == true,
it
)
}
else -> Content.Simple(
origin,
chat,
messageMeta,
it
)
}
} ?: Text(
origin,
chat,
messageMeta,
link_preview_options
)
}
}
@RiskFeature("This serializer currently support only deserialization, but not serialization")
companion object : KSerializer<External> {
override val descriptor: SerialDescriptor
get() = Surrogate.serializer().descriptor
override fun deserialize(decoder: Decoder): External {
return Surrogate.serializer().deserialize(decoder).asExternalReplyInfo
}
override fun serialize(encoder: Encoder, value: External) {
}
}
}
}

View File

@ -10,4 +10,4 @@ data class Dice(
val value: DiceResult, val value: DiceResult,
@SerialName(emojiField) @SerialName(emojiField)
val animationType: DiceAnimationType val animationType: DiceAnimationType
) : ExternalReplyInfo.ContentVariant ) : ReplyInfo.External.ContentVariant

View File

@ -24,4 +24,4 @@ data class AnimationFile(
@SerialName(fileSizeField) @SerialName(fileSizeField)
override val fileSize: Long? = null override val fileSize: Long? = null
) : TelegramMediaFile, MimedMediaFile, ThumbedMediaFile, PlayableMediaFile, CustomNamedMediaFile, SizedMediaFile, ) : TelegramMediaFile, MimedMediaFile, ThumbedMediaFile, PlayableMediaFile, CustomNamedMediaFile, SizedMediaFile,
ExternalReplyInfo.ContentVariant ReplyInfo.External.ContentVariant

View File

@ -28,6 +28,6 @@ data class AudioFile(
@SerialName(thumbnailField) @SerialName(thumbnailField)
override val thumbnail: PhotoSize? = null override val thumbnail: PhotoSize? = null
) : TelegramMediaFile, CustomNamedMediaFile, MimedMediaFile, ThumbedMediaFile, PlayableMediaFile, TitledMediaFile, ) : TelegramMediaFile, CustomNamedMediaFile, MimedMediaFile, ThumbedMediaFile, PlayableMediaFile, TitledMediaFile,
Performerable, ExternalReplyInfo.ContentVariant Performerable, ReplyInfo.External.ContentVariant
fun AudioFile.asVoiceFile() = VoiceFile(fileId, fileUniqueId, duration, mimeType, fileSize) fun AudioFile.asVoiceFile() = VoiceFile(fileId, fileUniqueId, duration, mimeType, fileSize)

View File

@ -20,7 +20,7 @@ data class DocumentFile(
override val mimeType: MimeType? = null, override val mimeType: MimeType? = null,
@SerialName(fileNameField) @SerialName(fileNameField)
override val fileName: String? = null override val fileName: String? = null
) : TelegramMediaFile, MimedMediaFile, ThumbedMediaFile, CustomNamedMediaFile, ExternalReplyInfo.ContentVariant ) : TelegramMediaFile, MimedMediaFile, ThumbedMediaFile, CustomNamedMediaFile, ReplyInfo.External.ContentVariant
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun TelegramMediaFile.asDocumentFile() = if (this is DocumentFile) { inline fun TelegramMediaFile.asDocumentFile() = if (this is DocumentFile) {

View File

@ -12,7 +12,7 @@ import kotlin.jvm.JvmInline
@JvmInline @JvmInline
value class Photo( value class Photo(
val photos: List<PhotoSize> val photos: List<PhotoSize>
) : List<PhotoSize> by photos, ExternalReplyInfo.ContentVariant ) : List<PhotoSize> by photos, ReplyInfo.External.ContentVariant
fun Photo.biggest(): PhotoSize? = maxByOrNull { fun Photo.biggest(): PhotoSize? = maxByOrNull {
it.resolution it.resolution

View File

@ -34,7 +34,7 @@ data class StickerSurrogate(
// TODO:: Serializer // TODO:: Serializer
@Serializable(StickerSerializer::class) @Serializable(StickerSerializer::class)
sealed interface Sticker : TelegramMediaFile, SizedMediaFile, ThumbedMediaFile, ExternalReplyInfo.ContentVariant { sealed interface Sticker : TelegramMediaFile, SizedMediaFile, ThumbedMediaFile, ReplyInfo.External.ContentVariant {
val emoji: String? val emoji: String?
val stickerSetName: StickerSetName? val stickerSetName: StickerSetName?
val stickerFormat: StickerFormat val stickerFormat: StickerFormat

View File

@ -30,7 +30,7 @@ data class VideoFile(
@SerialName(fileSizeField) @SerialName(fileSizeField)
override val fileSize: Long? = null override val fileSize: Long? = null
) : TelegramMediaFile, CustomNamedMediaFile, MimedMediaFile, ThumbedMediaFile, PlayableMediaFile, SizedMediaFile, ) : TelegramMediaFile, CustomNamedMediaFile, MimedMediaFile, ThumbedMediaFile, PlayableMediaFile, SizedMediaFile,
ExternalReplyInfo.ContentVariant ReplyInfo.External.ContentVariant
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun VideoFile.toTelegramMediaVideo( inline fun VideoFile.toTelegramMediaVideo(

View File

@ -18,7 +18,7 @@ data class VideoNoteFile(
override val thumbnail: PhotoSize? = null, override val thumbnail: PhotoSize? = null,
@SerialName(fileSizeField) @SerialName(fileSizeField)
override val fileSize: Long? = null override val fileSize: Long? = null
) : TelegramMediaFile, ThumbedMediaFile, PlayableMediaFile, SizedMediaFile, ExternalReplyInfo.ContentVariant { ) : TelegramMediaFile, ThumbedMediaFile, PlayableMediaFile, SizedMediaFile, ReplyInfo.External.ContentVariant {
override val height: Int override val height: Int
get() = width get() = width
} }

View File

@ -19,7 +19,7 @@ data class VoiceFile(
override val mimeType: MimeType? = null, override val mimeType: MimeType? = null,
@SerialName(fileSizeField) @SerialName(fileSizeField)
override val fileSize: Long? = null override val fileSize: Long? = null
) : TelegramMediaFile, MimedMediaFile, PlayableMediaFile, ExternalReplyInfo.ContentVariant ) : TelegramMediaFile, MimedMediaFile, PlayableMediaFile, ReplyInfo.External.ContentVariant
fun VoiceFile.asAudioFile( fun VoiceFile.asAudioFile(
performer: String? = null, performer: String? = null,

View File

@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.types.games
import dev.inmo.tgbotapi.abstracts.TextedInput import dev.inmo.tgbotapi.abstracts.TextedInput
import dev.inmo.tgbotapi.abstracts.Titled import dev.inmo.tgbotapi.abstracts.Titled
import dev.inmo.tgbotapi.types.ExternalReplyInfo import dev.inmo.tgbotapi.types.ReplyInfo
import dev.inmo.tgbotapi.types.message.textsources.TextSourcesList import dev.inmo.tgbotapi.types.message.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.files.AnimationFile import dev.inmo.tgbotapi.types.files.AnimationFile
import dev.inmo.tgbotapi.types.files.Photo import dev.inmo.tgbotapi.types.files.Photo
@ -16,4 +16,4 @@ data class Game(
override val text: String? = null, override val text: String? = null,
override val textSources: TextSourcesList = emptyList(), override val textSources: TextSourcesList = emptyList(),
val animation: AnimationFile? = null val animation: AnimationFile? = null
) : Titled, TextedInput, ExternalReplyInfo.ContentVariant ) : Titled, TextedInput, ReplyInfo.External.ContentVariant

View File

@ -14,7 +14,7 @@ import kotlinx.serialization.encoding.Encoder
@Serializable(GiveawayPublicResults.Companion::class) @Serializable(GiveawayPublicResults.Companion::class)
sealed interface GiveawayPublicResults: GiveawayInfo, GiveawayResults, WithPreviewChatAndMessageId, sealed interface GiveawayPublicResults: GiveawayInfo, GiveawayResults, WithPreviewChatAndMessageId,
ExternalReplyInfo.ContentVariant { ReplyInfo.External.ContentVariant {
val count: Int val count: Int
val winners: List<PreviewUser> val winners: List<PreviewUser>
val additionalChats: Int val additionalChats: Int

View File

@ -30,4 +30,4 @@ data class ScheduledGiveaway(
val countries: List<IetfLang>? = null, val countries: List<IetfLang>? = null,
@SerialName(premiumSubscriptionMonthCountField) @SerialName(premiumSubscriptionMonthCountField)
override val premiumMonths: Int? = null override val premiumMonths: Int? = null
) : GiveawayInfo, ExternalReplyInfo.ContentVariant ) : GiveawayInfo, ReplyInfo.External.ContentVariant

View File

@ -20,7 +20,7 @@ import kotlinx.serialization.json.JsonObject
*/ */
@Serializable(LocationSerializer::class) @Serializable(LocationSerializer::class)
@ClassCastsIncluded @ClassCastsIncluded
sealed interface Location : Locationed, HorizontallyAccured, ExternalReplyInfo.ContentVariant sealed interface Location : Locationed, HorizontallyAccured, ReplyInfo.External.ContentVariant
@Serializable @Serializable
data class StaticLocation( data class StaticLocation(

View File

@ -16,7 +16,7 @@ data class ChannelContentMessageImpl<T: MessageContent>(
override val editDate: DateTime?, override val editDate: DateTime?,
override val hasProtectedContent: Boolean, override val hasProtectedContent: Boolean,
override val forwardOrigin: MessageOrigin?, override val forwardOrigin: MessageOrigin?,
override val replyTo: AccessibleMessage?, override val replyInfo: ReplyInfo?,
override val replyMarkup: InlineKeyboardMarkup?, override val replyMarkup: InlineKeyboardMarkup?,
override val senderBot: CommonBot?, override val senderBot: CommonBot?,
override val authorSignature: AuthorSignature?, override val authorSignature: AuthorSignature?,

View File

@ -17,7 +17,7 @@ data class ConnectedFromChannelGroupContentMessageImpl<T : MessageContent>(
override val forwardOrigin: MessageOrigin?, override val forwardOrigin: MessageOrigin?,
override val editDate: DateTime?, override val editDate: DateTime?,
override val hasProtectedContent: Boolean, override val hasProtectedContent: Boolean,
override val replyTo: AccessibleMessage?, override val replyInfo: ReplyInfo?,
override val replyMarkup: InlineKeyboardMarkup?, override val replyMarkup: InlineKeyboardMarkup?,
override val content: T, override val content: T,
override val senderBot: CommonBot?, override val senderBot: CommonBot?,
@ -52,7 +52,7 @@ data class UnconnectedFromChannelGroupContentMessageImpl<T: MessageContent>(
override val forwardOrigin: MessageOrigin?, override val forwardOrigin: MessageOrigin?,
override val editDate: DateTime?, override val editDate: DateTime?,
override val hasProtectedContent: Boolean, override val hasProtectedContent: Boolean,
override val replyTo: AccessibleMessage?, override val replyInfo: ReplyInfo?,
override val replyMarkup: InlineKeyboardMarkup?, override val replyMarkup: InlineKeyboardMarkup?,
override val content: T, override val content: T,
override val senderBot: CommonBot?, override val senderBot: CommonBot?,
@ -85,7 +85,7 @@ data class AnonymousGroupContentMessageImpl<T : MessageContent>(
override val forwardOrigin: MessageOrigin?, override val forwardOrigin: MessageOrigin?,
override val editDate: DateTime?, override val editDate: DateTime?,
override val hasProtectedContent: Boolean, override val hasProtectedContent: Boolean,
override val replyTo: AccessibleMessage?, override val replyInfo: ReplyInfo?,
override val replyMarkup: InlineKeyboardMarkup?, override val replyMarkup: InlineKeyboardMarkup?,
override val content: T, override val content: T,
override val senderBot: CommonBot?, override val senderBot: CommonBot?,
@ -118,7 +118,7 @@ data class CommonGroupContentMessageImpl<T : MessageContent>(
override val forwardOrigin: MessageOrigin?, override val forwardOrigin: MessageOrigin?,
override val editDate: DateTime?, override val editDate: DateTime?,
override val hasProtectedContent: Boolean, override val hasProtectedContent: Boolean,
override val replyTo: AccessibleMessage?, override val replyInfo: ReplyInfo?,
override val replyMarkup: InlineKeyboardMarkup?, override val replyMarkup: InlineKeyboardMarkup?,
override val content: T, override val content: T,
override val senderBot: CommonBot?, override val senderBot: CommonBot?,
@ -151,7 +151,7 @@ data class FromChannelForumContentMessageImpl<T: MessageContent>(
override val forwardOrigin: MessageOrigin?, override val forwardOrigin: MessageOrigin?,
override val editDate: DateTime?, override val editDate: DateTime?,
override val hasProtectedContent: Boolean, override val hasProtectedContent: Boolean,
override val replyTo: AccessibleMessage?, override val replyInfo: ReplyInfo?,
override val replyMarkup: InlineKeyboardMarkup?, override val replyMarkup: InlineKeyboardMarkup?,
override val content: T, override val content: T,
override val senderBot: CommonBot?, override val senderBot: CommonBot?,
@ -186,7 +186,7 @@ data class AnonymousForumContentMessageImpl<T : MessageContent>(
override val forwardOrigin: MessageOrigin?, override val forwardOrigin: MessageOrigin?,
override val editDate: DateTime?, override val editDate: DateTime?,
override val hasProtectedContent: Boolean, override val hasProtectedContent: Boolean,
override val replyTo: AccessibleMessage?, override val replyInfo: ReplyInfo?,
override val replyMarkup: InlineKeyboardMarkup?, override val replyMarkup: InlineKeyboardMarkup?,
override val content: T, override val content: T,
override val senderBot: CommonBot?, override val senderBot: CommonBot?,
@ -221,7 +221,7 @@ data class CommonForumContentMessageImpl<T : MessageContent>(
override val forwardOrigin: MessageOrigin?, override val forwardOrigin: MessageOrigin?,
override val editDate: DateTime?, override val editDate: DateTime?,
override val hasProtectedContent: Boolean, override val hasProtectedContent: Boolean,
override val replyTo: AccessibleMessage?, override val replyInfo: ReplyInfo?,
override val replyMarkup: InlineKeyboardMarkup?, override val replyMarkup: InlineKeyboardMarkup?,
override val content: T, override val content: T,
override val senderBot: CommonBot?, override val senderBot: CommonBot?,

View File

@ -19,7 +19,7 @@ data class PrivateContentMessageImpl<T: MessageContent>(
override val editDate: DateTime?, override val editDate: DateTime?,
override val hasProtectedContent: Boolean, override val hasProtectedContent: Boolean,
override val forwardOrigin: MessageOrigin?, override val forwardOrigin: MessageOrigin?,
override val replyTo: AccessibleMessage?, override val replyInfo: ReplyInfo?,
override val replyMarkup: InlineKeyboardMarkup?, override val replyMarkup: InlineKeyboardMarkup?,
override val senderBot: CommonBot?, override val senderBot: CommonBot?,
override val mediaGroupId: MediaGroupIdentifier?, override val mediaGroupId: MediaGroupIdentifier?,

View File

@ -54,6 +54,7 @@ internal data class RawMessage(
private val is_topic_message: Boolean? = null, private val is_topic_message: Boolean? = null,
private val is_automatic_forward: Boolean? = null, private val is_automatic_forward: Boolean? = null,
private val reply_to_message: RawMessage? = null, private val reply_to_message: RawMessage? = null,
private val external_reply: ReplyInfo.External? = null,
private val via_bot: CommonBot? = null, private val via_bot: CommonBot? = null,
private val edit_date: TelegramDate? = null, private val edit_date: TelegramDate? = null,
private val has_protected_content: Boolean? = null, private val has_protected_content: Boolean? = null,
@ -282,7 +283,15 @@ internal data class RawMessage(
) )
else -> error("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 -> when (chat) { } ?: content?.let { content ->
val replyInfo: ReplyInfo? = when {
reply_to_message != null -> ReplyInfo.Internal(
reply_to_message.asMessage
)
external_reply != null -> external_reply
else -> null
}
when (chat) {
is PreviewPublicChat -> when (chat) { is PreviewPublicChat -> when (chat) {
is PreviewChannelChat -> ChannelContentMessageImpl( is PreviewChannelChat -> ChannelContentMessageImpl(
messageId, messageId,
@ -292,7 +301,7 @@ internal data class RawMessage(
edit_date?.asDate, edit_date?.asDate,
has_protected_content == true, has_protected_content == true,
forward_origin, forward_origin,
reply_to_message?.asMessage, replyInfo,
reply_markup, reply_markup,
via_bot, via_bot,
author_signature, author_signature,
@ -316,7 +325,7 @@ internal data class RawMessage(
forward_origin, forward_origin,
edit_date ?.asDate, edit_date ?.asDate,
has_protected_content == true, has_protected_content == true,
reply_to_message ?.asMessage, replyInfo,
reply_markup, reply_markup,
content, content,
via_bot, via_bot,
@ -331,7 +340,7 @@ internal data class RawMessage(
forward_origin, forward_origin,
edit_date ?.asDate, edit_date ?.asDate,
has_protected_content == true, has_protected_content == true,
reply_to_message ?.asMessage, replyInfo,
reply_markup, reply_markup,
content, content,
via_bot, via_bot,
@ -347,7 +356,7 @@ internal data class RawMessage(
forward_origin, forward_origin,
edit_date ?.asDate, edit_date ?.asDate,
has_protected_content == true, has_protected_content == true,
reply_to_message ?.asMessage, replyInfo,
reply_markup, reply_markup,
content, content,
via_bot, via_bot,
@ -365,7 +374,7 @@ internal data class RawMessage(
forward_origin, forward_origin,
edit_date ?.asDate, edit_date ?.asDate,
has_protected_content == true, has_protected_content == true,
reply_to_message ?.asMessage, replyInfo,
reply_markup, reply_markup,
content, content,
via_bot, via_bot,
@ -381,7 +390,7 @@ internal data class RawMessage(
forward_origin, forward_origin,
edit_date ?.asDate, edit_date ?.asDate,
has_protected_content == true, has_protected_content == true,
reply_to_message ?.asMessage, replyInfo,
reply_markup, reply_markup,
content, content,
via_bot, via_bot,
@ -396,7 +405,7 @@ internal data class RawMessage(
forward_origin, forward_origin,
edit_date ?.asDate, edit_date ?.asDate,
has_protected_content == true, has_protected_content == true,
reply_to_message ?.asMessage, replyInfo,
reply_markup, reply_markup,
content, content,
via_bot, via_bot,
@ -411,7 +420,7 @@ internal data class RawMessage(
forward_origin, forward_origin,
edit_date ?.asDate, edit_date ?.asDate,
has_protected_content == true, has_protected_content == true,
reply_to_message ?.asMessage, replyInfo,
reply_markup, reply_markup,
content, content,
via_bot, via_bot,
@ -429,7 +438,7 @@ internal data class RawMessage(
forward_origin, forward_origin,
edit_date ?.asDate, edit_date ?.asDate,
has_protected_content == true, has_protected_content == true,
reply_to_message ?.asMessage, replyInfo,
reply_markup, reply_markup,
content, content,
via_bot, via_bot,
@ -445,7 +454,7 @@ internal data class RawMessage(
forward_origin, forward_origin,
edit_date ?.asDate, edit_date ?.asDate,
has_protected_content == true, has_protected_content == true,
reply_to_message ?.asMessage, replyInfo,
reply_markup, reply_markup,
content, content,
via_bot, via_bot,
@ -460,7 +469,7 @@ internal data class RawMessage(
forward_origin, forward_origin,
edit_date ?.asDate, edit_date ?.asDate,
has_protected_content == true, has_protected_content == true,
reply_to_message ?.asMessage, replyInfo,
reply_markup, reply_markup,
content, content,
via_bot, via_bot,
@ -475,7 +484,7 @@ internal data class RawMessage(
forward_origin, forward_origin,
edit_date ?.asDate, edit_date ?.asDate,
has_protected_content == true, has_protected_content == true,
reply_to_message ?.asMessage, replyInfo,
reply_markup, reply_markup,
content, content,
via_bot, via_bot,
@ -492,7 +501,7 @@ internal data class RawMessage(
edit_date?.asDate, edit_date?.asDate,
has_protected_content == true, has_protected_content == true,
forward_origin, forward_origin,
reply_to_message?.asMessage, replyInfo,
reply_markup, reply_markup,
via_bot, via_bot,
media_group_id media_group_id

View File

@ -1,5 +1,9 @@
package dev.inmo.tgbotapi.types.message.abstracts package dev.inmo.tgbotapi.types.message.abstracts
import dev.inmo.tgbotapi.types.ReplyInfo
interface PossiblyReplyMessage { interface PossiblyReplyMessage {
val replyInfo: ReplyInfo?
val replyTo: AccessibleMessage? val replyTo: AccessibleMessage?
get() = (replyInfo as? ReplyInfo.Internal) ?.message
} }

View File

@ -17,4 +17,4 @@ data class Invoice(
override val currency: Currency, override val currency: Currency,
@SerialName(totalAmountField) @SerialName(totalAmountField)
override val amount: Long override val amount: Long
) : Amounted, Currencied, ExternalReplyInfo.ContentVariant ) : Amounted, Currencied, ReplyInfo.External.ContentVariant

View File

@ -49,7 +49,7 @@ val LongSeconds.asExactScheduledCloseInfo
@Serializable(PollSerializer::class) @Serializable(PollSerializer::class)
@ClassCastsIncluded @ClassCastsIncluded
sealed interface Poll : ExternalReplyInfo.ContentVariant { sealed interface Poll : ReplyInfo.External.ContentVariant {
val id: PollIdentifier val id: PollIdentifier
val question: String val question: String
val options: List<PollOption> val options: List<PollOption>

View File

@ -1,7 +1,7 @@
package dev.inmo.tgbotapi.types.stories package dev.inmo.tgbotapi.types.stories
import dev.inmo.tgbotapi.types.ExternalReplyInfo import dev.inmo.tgbotapi.types.ReplyInfo
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@Serializable @Serializable
class Story : ExternalReplyInfo.ContentVariant class Story : ReplyInfo.External.ContentVariant

View File

@ -23,4 +23,4 @@ data class Venue(
override val googlePlaceId: GooglePlaceId? = null, override val googlePlaceId: GooglePlaceId? = null,
@SerialName(googlePlaceTypeField) @SerialName(googlePlaceTypeField)
override val googlePlaceType: GooglePlaceType? = null override val googlePlaceType: GooglePlaceType? = null
) : CommonVenueData, Locationed by location, ExternalReplyInfo.ContentVariant ) : CommonVenueData, Locationed by location, ReplyInfo.External.ContentVariant

View File

@ -40,7 +40,7 @@ fun <T : MediaGroupPartContent> List<PossiblySentViaBotCommonMessage<T>>.asMedia
sourceMessage.editDate, sourceMessage.editDate,
sourceMessage.hasProtectedContent, sourceMessage.hasProtectedContent,
sourceMessage.forwardOrigin, sourceMessage.forwardOrigin,
sourceMessage.replyTo, sourceMessage.replyInfo,
sourceMessage.replyMarkup, sourceMessage.replyMarkup,
sourceMessage.senderBot, sourceMessage.senderBot,
sourceMessage.authorSignature, sourceMessage.authorSignature,
@ -55,7 +55,7 @@ fun <T : MediaGroupPartContent> List<PossiblySentViaBotCommonMessage<T>>.asMedia
sourceMessage.editDate, sourceMessage.editDate,
sourceMessage.hasProtectedContent, sourceMessage.hasProtectedContent,
sourceMessage.forwardOrigin, sourceMessage.forwardOrigin,
sourceMessage.replyTo, sourceMessage.replyInfo,
sourceMessage.replyMarkup, sourceMessage.replyMarkup,
sourceMessage.senderBot, sourceMessage.senderBot,
sourceMessage.mediaGroupId sourceMessage.mediaGroupId
@ -67,7 +67,7 @@ fun <T : MediaGroupPartContent> List<PossiblySentViaBotCommonMessage<T>>.asMedia
sourceMessage.forwardOrigin, sourceMessage.forwardOrigin,
sourceMessage.editDate, sourceMessage.editDate,
sourceMessage.hasProtectedContent, sourceMessage.hasProtectedContent,
sourceMessage.replyTo, sourceMessage.replyInfo,
sourceMessage.replyMarkup, sourceMessage.replyMarkup,
content, content,
sourceMessage.senderBot, sourceMessage.senderBot,
@ -82,7 +82,7 @@ fun <T : MediaGroupPartContent> List<PossiblySentViaBotCommonMessage<T>>.asMedia
sourceMessage.forwardOrigin, sourceMessage.forwardOrigin,
sourceMessage.editDate, sourceMessage.editDate,
sourceMessage.hasProtectedContent, sourceMessage.hasProtectedContent,
sourceMessage.replyTo, sourceMessage.replyInfo,
sourceMessage.replyMarkup, sourceMessage.replyMarkup,
content, content,
sourceMessage.senderBot, sourceMessage.senderBot,
@ -96,7 +96,7 @@ fun <T : MediaGroupPartContent> List<PossiblySentViaBotCommonMessage<T>>.asMedia
sourceMessage.forwardOrigin, sourceMessage.forwardOrigin,
sourceMessage.editDate, sourceMessage.editDate,
sourceMessage.hasProtectedContent, sourceMessage.hasProtectedContent,
sourceMessage.replyTo, sourceMessage.replyInfo,
sourceMessage.replyMarkup, sourceMessage.replyMarkup,
content, content,
sourceMessage.senderBot, sourceMessage.senderBot,
@ -111,7 +111,7 @@ fun <T : MediaGroupPartContent> List<PossiblySentViaBotCommonMessage<T>>.asMedia
sourceMessage.forwardOrigin, sourceMessage.forwardOrigin,
sourceMessage.editDate, sourceMessage.editDate,
sourceMessage.hasProtectedContent, sourceMessage.hasProtectedContent,
sourceMessage.replyTo, sourceMessage.replyInfo,
sourceMessage.replyMarkup, sourceMessage.replyMarkup,
content, content,
sourceMessage.senderBot, sourceMessage.senderBot,
@ -126,7 +126,7 @@ fun <T : MediaGroupPartContent> List<PossiblySentViaBotCommonMessage<T>>.asMedia
sourceMessage.forwardOrigin, sourceMessage.forwardOrigin,
sourceMessage.editDate, sourceMessage.editDate,
sourceMessage.hasProtectedContent, sourceMessage.hasProtectedContent,
sourceMessage.replyTo, sourceMessage.replyInfo,
sourceMessage.replyMarkup, sourceMessage.replyMarkup,
content, content,
sourceMessage.senderBot, sourceMessage.senderBot,
@ -142,7 +142,7 @@ fun <T : MediaGroupPartContent> List<PossiblySentViaBotCommonMessage<T>>.asMedia
sourceMessage.forwardOrigin, sourceMessage.forwardOrigin,
sourceMessage.editDate, sourceMessage.editDate,
sourceMessage.hasProtectedContent, sourceMessage.hasProtectedContent,
sourceMessage.replyTo, sourceMessage.replyInfo,
sourceMessage.replyMarkup, sourceMessage.replyMarkup,
content, content,
sourceMessage.senderBot, sourceMessage.senderBot,
@ -157,7 +157,7 @@ fun <T : MediaGroupPartContent> List<PossiblySentViaBotCommonMessage<T>>.asMedia
sourceMessage.forwardOrigin, sourceMessage.forwardOrigin,
sourceMessage.editDate, sourceMessage.editDate,
sourceMessage.hasProtectedContent, sourceMessage.hasProtectedContent,
sourceMessage.replyTo, sourceMessage.replyInfo,
sourceMessage.replyMarkup, sourceMessage.replyMarkup,
content, content,
sourceMessage.senderBot, sourceMessage.senderBot,

View File

@ -51,7 +51,7 @@ inline val AccessibleMessage.is_automatic_forward: Boolean?
get() = this is ConnectedFromChannelGroupContentMessage<*> get() = this is ConnectedFromChannelGroupContentMessage<*>
@RiskFeature(RawFieldsUsageWarning) @RiskFeature(RawFieldsUsageWarning)
inline val AccessibleMessage.reply_to_message: AccessibleMessage? inline val AccessibleMessage.reply_to_message: AccessibleMessage?
get() = asPossiblyReplyMessage() ?.replyTo get() = asPossiblyReplyMessage() ?.replyInfo
@RiskFeature(RawFieldsUsageWarning) @RiskFeature(RawFieldsUsageWarning)
inline val AccessibleMessage.via_bot: CommonBot? inline val AccessibleMessage.via_bot: CommonBot?
get() = asPossiblySentViaBotCommonMessage() ?.senderBot get() = asPossiblySentViaBotCommonMessage() ?.senderBot