-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extract different ids into external files
- Loading branch information
1 parent
3997af1
commit dec55cf
Showing
5 changed files
with
103 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/CustomEmojiId.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} |
40 changes: 40 additions & 0 deletions
40
tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/StickerFormat.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<StickerFormat> { | ||
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) | ||
} | ||
|
||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/StickerType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<StickerType> { | ||
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) | ||
} | ||
|
||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/StoryId.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) |