Skip to content

Commit dec55cf

Browse files
extract different ids into external files
1 parent 3997af1 commit dec55cf

File tree

5 files changed

+103
-85
lines changed

5 files changed

+103
-85
lines changed

tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt

-85
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
package dev.inmo.tgbotapi.types
22

33
import dev.inmo.tgbotapi.utils.BuiltinMimeTypes
4-
import kotlinx.serialization.KSerializer
5-
import kotlinx.serialization.Serializable
6-
import kotlinx.serialization.builtins.serializer
7-
import kotlinx.serialization.descriptors.SerialDescriptor
8-
import kotlinx.serialization.encoding.Decoder
9-
import kotlinx.serialization.encoding.Encoder
10-
import kotlin.jvm.JvmInline
114

125
typealias ForwardSignature = String
136
typealias ForwardSenderName = String
@@ -22,20 +15,6 @@ typealias GooglePlaceId = String
2215
typealias GooglePlaceType = String
2316
typealias MembersLimit = Int
2417

25-
@Serializable
26-
@JvmInline
27-
value class CustomEmojiId(
28-
val string: String
29-
) {
30-
val appLink
31-
get() = "${internalTgAppLinksBeginning}emoji?id=$this"
32-
}
33-
@Serializable
34-
@JvmInline
35-
value class StoryId(
36-
val long: Long
37-
)
38-
3918
typealias Seconds = Int
4019
typealias MilliSeconds = Long
4120
typealias LongSeconds = Long
@@ -44,70 +23,6 @@ typealias UnixTimeStamp = LongSeconds
4423
typealias Meters = Float
4524
typealias Degrees = Int
4625

47-
@Serializable(StickerType.Serializer::class)
48-
sealed interface StickerType {
49-
val type: String
50-
51-
@Serializable
52-
object Regular : StickerType { override val type: String = "regular" }
53-
@Serializable
54-
object Mask : StickerType { override val type: String = "mask" }
55-
@Serializable
56-
object CustomEmoji : StickerType { override val type: String = "custom_emoji" }
57-
@Serializable
58-
data class Unknown(override val type: String = "custom_emoji") : StickerType
59-
60-
object Serializer : KSerializer<StickerType> {
61-
override val descriptor: SerialDescriptor = String.serializer().descriptor
62-
63-
override fun deserialize(decoder: Decoder): StickerType {
64-
return when (val type = decoder.decodeString()) {
65-
Regular.type -> Regular
66-
Mask.type -> Mask
67-
CustomEmoji.type -> CustomEmoji
68-
else -> Unknown(type)
69-
}
70-
}
71-
72-
override fun serialize(encoder: Encoder, value: StickerType) {
73-
encoder.encodeString(value.type)
74-
}
75-
76-
}
77-
}
78-
79-
@Serializable(StickerFormat.Serializer::class)
80-
sealed interface StickerFormat {
81-
val type: String
82-
83-
@Serializable
84-
object Static : StickerFormat { override val type: String = "static" }
85-
@Serializable
86-
object Animated : StickerFormat { override val type: String = "animated" }
87-
@Serializable
88-
object Video : StickerFormat { override val type: String = "video" }
89-
@Serializable
90-
data class Unknown(override val type: String = "custom_emoji") : StickerFormat
91-
92-
object Serializer : KSerializer<StickerFormat> {
93-
override val descriptor: SerialDescriptor = String.serializer().descriptor
94-
95-
override fun deserialize(decoder: Decoder): StickerFormat {
96-
return when (val type = decoder.decodeString()) {
97-
Static.type -> Static
98-
Animated.type -> Animated
99-
Video.type -> Video
100-
else -> Unknown(type)
101-
}
102-
}
103-
104-
override fun serialize(encoder: Encoder, value: StickerFormat) {
105-
encoder.encodeString(value.type)
106-
}
107-
108-
}
109-
}
110-
11126
val usernameRegex = Regex("@[\\w\\d_]+")
11227

11328
val degreesLimit = 1 .. 360
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package dev.inmo.tgbotapi.types
2+
3+
import kotlinx.serialization.Serializable
4+
import kotlin.jvm.JvmInline
5+
6+
@Serializable
7+
@JvmInline
8+
value class CustomEmojiId(
9+
val string: String
10+
) {
11+
val appLink
12+
get() = "${internalTgAppLinksBeginning}emoji?id=$this"
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package dev.inmo.tgbotapi.types
2+
3+
import kotlinx.serialization.KSerializer
4+
import kotlinx.serialization.Serializable
5+
import kotlinx.serialization.builtins.serializer
6+
import kotlinx.serialization.descriptors.SerialDescriptor
7+
import kotlinx.serialization.encoding.Decoder
8+
import kotlinx.serialization.encoding.Encoder
9+
10+
@Serializable(StickerFormat.Serializer::class)
11+
sealed interface StickerFormat {
12+
val type: String
13+
14+
@Serializable
15+
object Static : StickerFormat { override val type: String = "static" }
16+
@Serializable
17+
object Animated : StickerFormat { override val type: String = "animated" }
18+
@Serializable
19+
object Video : StickerFormat { override val type: String = "video" }
20+
@Serializable
21+
data class Unknown(override val type: String = "custom_emoji") : StickerFormat
22+
23+
object Serializer : KSerializer<StickerFormat> {
24+
override val descriptor: SerialDescriptor = String.serializer().descriptor
25+
26+
override fun deserialize(decoder: Decoder): StickerFormat {
27+
return when (val type = decoder.decodeString()) {
28+
Static.type -> Static
29+
Animated.type -> Animated
30+
Video.type -> Video
31+
else -> Unknown(type)
32+
}
33+
}
34+
35+
override fun serialize(encoder: Encoder, value: StickerFormat) {
36+
encoder.encodeString(value.type)
37+
}
38+
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package dev.inmo.tgbotapi.types
2+
3+
import kotlinx.serialization.KSerializer
4+
import kotlinx.serialization.Serializable
5+
import kotlinx.serialization.builtins.serializer
6+
import kotlinx.serialization.descriptors.SerialDescriptor
7+
import kotlinx.serialization.encoding.Decoder
8+
import kotlinx.serialization.encoding.Encoder
9+
10+
@Serializable(StickerType.Serializer::class)
11+
sealed interface StickerType {
12+
val type: String
13+
14+
@Serializable
15+
object Regular : StickerType { override val type: String = "regular" }
16+
@Serializable
17+
object Mask : StickerType { override val type: String = "mask" }
18+
@Serializable
19+
object CustomEmoji : StickerType { override val type: String = "custom_emoji" }
20+
@Serializable
21+
data class Unknown(override val type: String = "custom_emoji") : StickerType
22+
23+
object Serializer : KSerializer<StickerType> {
24+
override val descriptor: SerialDescriptor = String.serializer().descriptor
25+
26+
override fun deserialize(decoder: Decoder): StickerType {
27+
return when (val type = decoder.decodeString()) {
28+
Regular.type -> Regular
29+
Mask.type -> Mask
30+
CustomEmoji.type -> CustomEmoji
31+
else -> Unknown(type)
32+
}
33+
}
34+
35+
override fun serialize(encoder: Encoder, value: StickerType) {
36+
encoder.encodeString(value.type)
37+
}
38+
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package dev.inmo.tgbotapi.types
2+
3+
import kotlinx.serialization.Serializable
4+
import kotlin.jvm.JvmInline
5+
6+
@Serializable
7+
@JvmInline
8+
value class StoryId(
9+
val long: Long
10+
)

0 commit comments

Comments
 (0)