1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 08:13:47 +00:00

fixes of build

This commit is contained in:
InsanusMokrassar 2024-01-07 20:00:07 +06:00
parent f3b05bbffd
commit 8df72edd52
19 changed files with 125 additions and 26 deletions

View File

@ -741,7 +741,7 @@ suspend fun <BC : BehaviourContext> BC.onScheduledGiveawayContent(
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
* data
*/
suspend fun <BC : BehaviourContext> BC.onScheduledGiveawayContent(
suspend fun <BC : BehaviourContext> BC.onGiveawayPublicResultsContent(
initialFilter: CommonMessageFilter<GiveawayPublicResultsContent>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, GiveawayPublicResultsContentMessage, Update>? = MessageFilterByChat,
markerFactory: MarkerFactory<in GiveawayPublicResultsContentMessage, Any> = ByChatMessageMarkerFactory,

View File

@ -63,13 +63,13 @@ sealed interface ReplyInfo {
) : Content
@Serializable
data class Media<T>(
data class Media(
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
override val content: MediaContentVariant
) : Content, SpoilerableData
}
@Serializable
@ -133,7 +133,7 @@ sealed interface ReplyInfo {
return content ?.let {
when (it) {
is TelegramMediaFile -> {
is MediaContentVariant -> {
Content.Media(
origin,
chat,

View File

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

View File

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

View File

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

View File

@ -0,0 +1,5 @@
package dev.inmo.tgbotapi.types.files
import dev.inmo.tgbotapi.types.ReplyInfo
interface MediaContentVariant : ReplyInfo.External.ContentVariant, TelegramMediaFile

View File

@ -12,7 +12,22 @@ import kotlin.jvm.JvmInline
@JvmInline
value class Photo(
val photos: List<PhotoSize>
) : List<PhotoSize> by photos, ReplyInfo.External.ContentVariant
) : List<PhotoSize> by photos, MediaContentVariant {
val biggest: PhotoSize
get() = biggest()!!
override val fileId: FileId
get() = biggest.fileId
override val fileUniqueId: FileUniqueId
get() = biggest.fileUniqueId
override val fileSize: Long?
get() = biggest.fileSize
init {
require(photos.isNotEmpty()) {
"Photos collection must not be empty"
}
}
}
fun Photo.biggest(): PhotoSize? = maxByOrNull {
it.resolution

View File

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

View File

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

View File

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

View File

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

View File

@ -36,6 +36,6 @@ data class ChannelContentMessageImpl<T: MessageContent>(
authorSignature: AuthorSignature?,
mediaGroupId: MediaGroupIdentifier?,
) : this(
messageId, chat, content, date, editDate, hasProtectedContent, forwardInfo.messageOrigin(), replyTo, replyMarkup, senderBot, authorSignature, mediaGroupId
messageId, chat, content, date, editDate, hasProtectedContent, forwardInfo.messageOrigin(), replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, senderBot, authorSignature, mediaGroupId
)
}

View File

@ -83,6 +83,7 @@ fun MessageOrigin.forwardInfo() = when(this) {
date,
user
)
is MessageOrigin.Unknown -> null
}
fun ForwardInfo.messageOrigin() = when (this) {

View File

@ -40,7 +40,7 @@ data class ConnectedFromChannelGroupContentMessageImpl<T : MessageContent>(
authorSignature: AuthorSignature?,
mediaGroupId: MediaGroupIdentifier?,
) : this(
chat, channel, messageId, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo, replyMarkup, content, senderBot, authorSignature, mediaGroupId
chat, channel, messageId, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, content, senderBot, authorSignature, mediaGroupId
)
}
@ -74,7 +74,7 @@ data class UnconnectedFromChannelGroupContentMessageImpl<T: MessageContent>(
authorSignature: AuthorSignature?,
mediaGroupId: MediaGroupIdentifier?,
) : this(
chat, channel, messageId, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo, replyMarkup, content, senderBot, authorSignature, mediaGroupId
chat, channel, messageId, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, content, senderBot, authorSignature, mediaGroupId
)
}
@ -106,7 +106,7 @@ data class AnonymousGroupContentMessageImpl<T : MessageContent>(
authorSignature: AuthorSignature?,
mediaGroupId: MediaGroupIdentifier?,
) : this(
chat, messageId, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo, replyMarkup, content, senderBot, authorSignature, mediaGroupId
chat, messageId, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, content, senderBot, authorSignature, mediaGroupId
)
}
@ -138,7 +138,7 @@ data class CommonGroupContentMessageImpl<T : MessageContent>(
senderBot: CommonBot?,
mediaGroupId: MediaGroupIdentifier?,
) : this(
chat, messageId, from, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo, replyMarkup, content, senderBot, mediaGroupId
chat, messageId, from, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, content, senderBot, mediaGroupId
)
}
@ -174,7 +174,7 @@ data class FromChannelForumContentMessageImpl<T: MessageContent>(
authorSignature: AuthorSignature?,
mediaGroupId: MediaGroupIdentifier?,
) : this(
chat, channel, messageId, threadId, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo, replyMarkup, content, senderBot, authorSignature, mediaGroupId
chat, channel, messageId, threadId, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, content, senderBot, authorSignature, mediaGroupId
)
}
@ -208,7 +208,7 @@ data class AnonymousForumContentMessageImpl<T : MessageContent>(
authorSignature: AuthorSignature?,
mediaGroupId: MediaGroupIdentifier?,
) : this(
chat, messageId, threadId, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo, replyMarkup, content, senderBot, authorSignature, mediaGroupId
chat, messageId, threadId, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, content, senderBot, authorSignature, mediaGroupId
)
}
@ -242,6 +242,6 @@ data class CommonForumContentMessageImpl<T : MessageContent>(
senderBot: CommonBot?,
mediaGroupId: MediaGroupIdentifier?,
) : this(
chat, messageId, threadId, from, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo, replyMarkup, content, senderBot, mediaGroupId
chat, messageId, threadId, from, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, content, senderBot, mediaGroupId
)
}

View File

@ -21,7 +21,7 @@ sealed interface MessageOrigin {
@Serializable
data class User(
@SerialName(senderUserField)
val user: PreviewUser,
val user: dev.inmo.tgbotapi.types.chat.User,
@SerialName(dateField)
override val date: TelegramDate
) : MessageOrigin {

View File

@ -38,6 +38,6 @@ data class PrivateContentMessageImpl<T: MessageContent>(
senderBot: CommonBot?,
mediaGroupId: MediaGroupIdentifier?,
) : this(
messageId, from, chat, content, date, editDate, hasProtectedContent, forwardInfo.messageOrigin(), replyTo, replyMarkup, senderBot, mediaGroupId
messageId, from, chat, content, date, editDate, hasProtectedContent, forwardInfo.messageOrigin(), replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, senderBot, mediaGroupId
)
}

View File

@ -1,6 +1,7 @@
package dev.inmo.tgbotapi
import dev.inmo.tgbotapi.requests.abstracts.toInputFile
import dev.inmo.tgbotapi.types.files.Photo
import dev.inmo.tgbotapi.types.media.MediaGroupMemberTelegramMediaSerializer
import dev.inmo.tgbotapi.types.files.PhotoSize
import dev.inmo.tgbotapi.types.message.content.PhotoContent
@ -20,8 +21,10 @@ class SimpleInputFilesTest {
@Test
fun test_that_creating_of_photo_and_converting_to_input_media_working_correctly() {
val photoContent = PhotoContent(
listOf(
PhotoSize("example_file_id".toInputFile(), "example_unique_file_id", 100, 100, 100)
Photo(
listOf(
PhotoSize("example_file_id".toInputFile(), "example_unique_file_id", 100, 100, 100)
)
)
)
val inputMedia = photoContent.toMediaGroupMemberTelegramMedia()

View File

@ -75,6 +75,7 @@ import dev.inmo.tgbotapi.types.InlineQueries.query.BaseInlineQuery
import dev.inmo.tgbotapi.types.InlineQueries.query.InlineQuery
import dev.inmo.tgbotapi.types.InlineQueries.query.LocationInlineQuery
import dev.inmo.tgbotapi.types.PrimaryInviteLink
import dev.inmo.tgbotapi.types.ReplyInfo
import dev.inmo.tgbotapi.types.SecondaryChatInviteLink
import dev.inmo.tgbotapi.types.Username
import dev.inmo.tgbotapi.types.actions.BotAction
@ -179,9 +180,11 @@ import dev.inmo.tgbotapi.types.files.MaskAnimatedSticker
import dev.inmo.tgbotapi.types.files.MaskSimpleSticker
import dev.inmo.tgbotapi.types.files.MaskSticker
import dev.inmo.tgbotapi.types.files.MaskVideoSticker
import dev.inmo.tgbotapi.types.files.MediaContentVariant
import dev.inmo.tgbotapi.types.files.MimedMediaFile
import dev.inmo.tgbotapi.types.files.PassportFile
import dev.inmo.tgbotapi.types.files.PathedFile
import dev.inmo.tgbotapi.types.files.Photo
import dev.inmo.tgbotapi.types.files.PhotoSize
import dev.inmo.tgbotapi.types.files.PlayableMediaFile
import dev.inmo.tgbotapi.types.files.RegularAnimatedSticker
@ -1572,6 +1575,60 @@ public inline fun <T>
InputMessageContent.ifInputVenueMessageContent(block: (InputVenueMessageContent) -> T): T? =
inputVenueMessageContentOrNull() ?.let(block)
public inline fun ReplyInfo.externalOrNull(): ReplyInfo.External? = this as?
dev.inmo.tgbotapi.types.ReplyInfo.External
public inline fun ReplyInfo.externalOrThrow(): ReplyInfo.External = this as
dev.inmo.tgbotapi.types.ReplyInfo.External
public inline fun <T> ReplyInfo.ifExternal(block: (ReplyInfo.External) -> T): T? = externalOrNull()
?.let(block)
public inline fun ReplyInfo.contentOrNull(): ReplyInfo.External.Content? = this as?
dev.inmo.tgbotapi.types.ReplyInfo.External.Content
public inline fun ReplyInfo.contentOrThrow(): ReplyInfo.External.Content = this as
dev.inmo.tgbotapi.types.ReplyInfo.External.Content
public inline fun <T> ReplyInfo.ifContent(block: (ReplyInfo.External.Content) -> T): T? =
contentOrNull() ?.let(block)
public inline fun ReplyInfo.mediaOrNull(): ReplyInfo.External.Content.Media? = this as?
dev.inmo.tgbotapi.types.ReplyInfo.External.Content.Media
public inline fun ReplyInfo.mediaOrThrow(): ReplyInfo.External.Content.Media = this as
dev.inmo.tgbotapi.types.ReplyInfo.External.Content.Media
public inline fun <T> ReplyInfo.ifMedia(block: (ReplyInfo.External.Content.Media) -> T): T? =
mediaOrNull() ?.let(block)
public inline fun ReplyInfo.simpleOrNull(): ReplyInfo.External.Content.Simple? = this as?
dev.inmo.tgbotapi.types.ReplyInfo.External.Content.Simple
public inline fun ReplyInfo.simpleOrThrow(): ReplyInfo.External.Content.Simple = this as
dev.inmo.tgbotapi.types.ReplyInfo.External.Content.Simple
public inline fun <T> ReplyInfo.ifSimple(block: (ReplyInfo.External.Content.Simple) -> T): T? =
simpleOrNull() ?.let(block)
public inline fun ReplyInfo.textOrNull(): ReplyInfo.External.Text? = this as?
dev.inmo.tgbotapi.types.ReplyInfo.External.Text
public inline fun ReplyInfo.textOrThrow(): ReplyInfo.External.Text = this as
dev.inmo.tgbotapi.types.ReplyInfo.External.Text
public inline fun <T> ReplyInfo.ifText(block: (ReplyInfo.External.Text) -> T): T? = textOrNull()
?.let(block)
public inline fun ReplyInfo.internalOrNull(): ReplyInfo.Internal? = this as?
dev.inmo.tgbotapi.types.ReplyInfo.Internal
public inline fun ReplyInfo.internalOrThrow(): ReplyInfo.Internal = this as
dev.inmo.tgbotapi.types.ReplyInfo.Internal
public inline fun <T> ReplyInfo.ifInternal(block: (ReplyInfo.Internal) -> T): T? = internalOrNull()
?.let(block)
public inline fun BotAction.typingActionOrNull(): TypingAction? = this as?
dev.inmo.tgbotapi.types.actions.TypingAction
@ -2385,6 +2442,15 @@ public inline fun TelegramMediaFile.fileOrThrow(): File = this as dev.inmo.tgbot
public inline fun <T> TelegramMediaFile.ifFile(block: (File) -> T): T? = fileOrNull() ?.let(block)
public inline fun TelegramMediaFile.mediaContentVariantOrNull(): MediaContentVariant? = this as?
dev.inmo.tgbotapi.types.files.MediaContentVariant
public inline fun TelegramMediaFile.mediaContentVariantOrThrow(): MediaContentVariant = this as
dev.inmo.tgbotapi.types.files.MediaContentVariant
public inline fun <T> TelegramMediaFile.ifMediaContentVariant(block: (MediaContentVariant) -> T): T?
= mediaContentVariantOrNull() ?.let(block)
public inline fun TelegramMediaFile.mimedMediaFileOrNull(): MimedMediaFile? = this as?
dev.inmo.tgbotapi.types.files.MimedMediaFile
@ -2412,6 +2478,15 @@ public inline fun TelegramMediaFile.pathedFileOrThrow(): PathedFile = this as
public inline fun <T> TelegramMediaFile.ifPathedFile(block: (PathedFile) -> T): T? =
pathedFileOrNull() ?.let(block)
public inline fun TelegramMediaFile.photoOrNull(): Photo? = this as?
dev.inmo.tgbotapi.types.files.Photo
public inline fun TelegramMediaFile.photoOrThrow(): Photo = this as
dev.inmo.tgbotapi.types.files.Photo
public inline fun <T> TelegramMediaFile.ifPhoto(block: (Photo) -> T): T? = photoOrNull()
?.let(block)
public inline fun TelegramMediaFile.photoSizeOrNull(): PhotoSize? = this as?
dev.inmo.tgbotapi.types.files.PhotoSize

View File

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