diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index 47a2cb97ae..b60bbf4cde 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -1,13 +1,6 @@ package dev.inmo.tgbotapi.types import dev.inmo.tgbotapi.utils.BuiltinMimeTypes -import kotlinx.serialization.KSerializer -import kotlinx.serialization.Serializable -import kotlinx.serialization.builtins.serializer -import kotlinx.serialization.descriptors.SerialDescriptor -import kotlinx.serialization.encoding.Decoder -import kotlinx.serialization.encoding.Encoder -import kotlin.jvm.JvmInline typealias ForwardSignature = String typealias ForwardSenderName = String @@ -22,20 +15,6 @@ typealias GooglePlaceId = String typealias GooglePlaceType = String typealias MembersLimit = Int -@Serializable -@JvmInline -value class CustomEmojiId( - val string: String -) { - val appLink - get() = "${internalTgAppLinksBeginning}emoji?id=$this" -} -@Serializable -@JvmInline -value class StoryId( - val long: Long -) - typealias Seconds = Int typealias MilliSeconds = Long typealias LongSeconds = Long @@ -44,70 +23,6 @@ typealias UnixTimeStamp = LongSeconds typealias Meters = Float typealias Degrees = Int -@Serializable(StickerType.Serializer::class) -sealed interface StickerType { - val type: String - - @Serializable - object Regular : StickerType { override val type: String = "regular" } - @Serializable - object Mask : StickerType { override val type: String = "mask" } - @Serializable - object CustomEmoji : StickerType { override val type: String = "custom_emoji" } - @Serializable - data class Unknown(override val type: String = "custom_emoji") : StickerType - - object Serializer : KSerializer { - override val descriptor: SerialDescriptor = String.serializer().descriptor - - override fun deserialize(decoder: Decoder): StickerType { - return when (val type = decoder.decodeString()) { - Regular.type -> Regular - Mask.type -> Mask - CustomEmoji.type -> CustomEmoji - else -> Unknown(type) - } - } - - override fun serialize(encoder: Encoder, value: StickerType) { - encoder.encodeString(value.type) - } - - } -} - -@Serializable(StickerFormat.Serializer::class) -sealed interface StickerFormat { - val type: String - - @Serializable - object Static : StickerFormat { override val type: String = "static" } - @Serializable - object Animated : StickerFormat { override val type: String = "animated" } - @Serializable - object Video : StickerFormat { override val type: String = "video" } - @Serializable - data class Unknown(override val type: String = "custom_emoji") : StickerFormat - - object Serializer : KSerializer { - override val descriptor: SerialDescriptor = String.serializer().descriptor - - override fun deserialize(decoder: Decoder): StickerFormat { - return when (val type = decoder.decodeString()) { - Static.type -> Static - Animated.type -> Animated - Video.type -> Video - else -> Unknown(type) - } - } - - override fun serialize(encoder: Encoder, value: StickerFormat) { - encoder.encodeString(value.type) - } - - } -} - val usernameRegex = Regex("@[\\w\\d_]+") val degreesLimit = 1 .. 360 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/CustomEmojiId.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/CustomEmojiId.kt new file mode 100644 index 0000000000..46523a0cb0 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/CustomEmojiId.kt @@ -0,0 +1,13 @@ +package dev.inmo.tgbotapi.types + +import kotlinx.serialization.Serializable +import kotlin.jvm.JvmInline + +@Serializable +@JvmInline +value class CustomEmojiId( + val string: String +) { + val appLink + get() = "${internalTgAppLinksBeginning}emoji?id=$this" +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/StickerFormat.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/StickerFormat.kt new file mode 100644 index 0000000000..1ff224e2f7 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/StickerFormat.kt @@ -0,0 +1,40 @@ +package dev.inmo.tgbotapi.types + +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.builtins.serializer +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable(StickerFormat.Serializer::class) +sealed interface StickerFormat { + val type: String + + @Serializable + object Static : StickerFormat { override val type: String = "static" } + @Serializable + object Animated : StickerFormat { override val type: String = "animated" } + @Serializable + object Video : StickerFormat { override val type: String = "video" } + @Serializable + data class Unknown(override val type: String = "custom_emoji") : StickerFormat + + object Serializer : KSerializer { + override val descriptor: SerialDescriptor = String.serializer().descriptor + + override fun deserialize(decoder: Decoder): StickerFormat { + return when (val type = decoder.decodeString()) { + Static.type -> Static + Animated.type -> Animated + Video.type -> Video + else -> Unknown(type) + } + } + + override fun serialize(encoder: Encoder, value: StickerFormat) { + encoder.encodeString(value.type) + } + + } +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/StickerType.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/StickerType.kt new file mode 100644 index 0000000000..0a474620f1 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/StickerType.kt @@ -0,0 +1,40 @@ +package dev.inmo.tgbotapi.types + +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.builtins.serializer +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable(StickerType.Serializer::class) +sealed interface StickerType { + val type: String + + @Serializable + object Regular : StickerType { override val type: String = "regular" } + @Serializable + object Mask : StickerType { override val type: String = "mask" } + @Serializable + object CustomEmoji : StickerType { override val type: String = "custom_emoji" } + @Serializable + data class Unknown(override val type: String = "custom_emoji") : StickerType + + object Serializer : KSerializer { + override val descriptor: SerialDescriptor = String.serializer().descriptor + + override fun deserialize(decoder: Decoder): StickerType { + return when (val type = decoder.decodeString()) { + Regular.type -> Regular + Mask.type -> Mask + CustomEmoji.type -> CustomEmoji + else -> Unknown(type) + } + } + + override fun serialize(encoder: Encoder, value: StickerType) { + encoder.encodeString(value.type) + } + + } +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/StoryId.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/StoryId.kt new file mode 100644 index 0000000000..a88fe86660 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/StoryId.kt @@ -0,0 +1,10 @@ +package dev.inmo.tgbotapi.types + +import kotlinx.serialization.Serializable +import kotlin.jvm.JvmInline + +@Serializable +@JvmInline +value class StoryId( + val long: Long +) \ No newline at end of file