Skip to content

Commit

Permalink
Merge pull request #170 from simple-robot/dev/fix-169
Browse files Browse the repository at this point in the history
fix: 为 CardMessage 相关的部分类型的部分属性添加默认值,以及修正部分缺陷
  • Loading branch information
ForteScarlet authored Aug 18, 2024
2 parents 3f38674 + a3745a7 commit 055bf77
Showing 1 changed file with 40 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ public sealed class CardElement {
@SerialName(Image.TYPE)
public data class Image @JvmOverloads constructor(
public val src: String,
public val alt: String,
public val alt: String = "",
public val size: Size = Size.Default,
public val circle: Boolean = false
) : CardElement() {
Expand Down Expand Up @@ -453,7 +453,7 @@ public sealed class CardElement {
@SerialName(Paragraph.TYPE)
public data class Paragraph(
public val cols: Int,
public val fields: List<Text>
public val fields: List<Text> = emptyList()
) : CardElement() {
init {
require(cols in 1..3) { "Cols must in 1..3, but $cols" }
Expand Down Expand Up @@ -625,8 +625,10 @@ public sealed class CardModule {
*/
@Serializable
@SerialName(ImageGroup.TYPE)
public data class ImageGroup(@Serializable(CardImageListWithTypeSerializer::class) public val elements: List<CardElement.Image>) :
CardModule() {
public data class ImageGroup(
@Serializable(CardImageListWithTypeSerializer::class)
public val elements: List<CardElement.Image>
) : CardModule() {
init {
require(elements.size in 1..9) { "The size of elements must be 1..9, but ${elements.size}" }
}
Expand Down Expand Up @@ -659,8 +661,10 @@ public sealed class CardModule {
*/
@Serializable
@SerialName(Container.TYPE)
public data class Container(@Serializable(CardImageListWithTypeSerializer::class) public val elements: List<CardElement.Image>) :
CardModule() {
public data class Container(
@Serializable(CardImageListWithTypeSerializer::class)
public val elements: List<CardElement.Image>
) : CardModule() {
init {
require(elements.size in 1..9) { "The size of elements must be 1..9, but ${elements.size}" }
}
Expand Down Expand Up @@ -693,8 +697,10 @@ public sealed class CardModule {
*/
@Serializable
@SerialName(ActionGroup.TYPE)
public data class ActionGroup(@Serializable(CardButtonListWithTypeSerializer::class) public val elements: List<CardElement.Button>) :
CardModule() {
public data class ActionGroup(
@Serializable(CardButtonListWithTypeSerializer::class)
public val elements: List<CardElement.Button> = emptyList()
) : CardModule() {
init {
require(elements.size <= 4) { "The size of elements must be <= 4, but ${elements.size}" }
}
Expand Down Expand Up @@ -789,23 +795,35 @@ public sealed class CardModule {
*/
@Serializable
@SerialName(FILE_TYPE)
public data class File(override val src: String, override val title: String, override val cover: String) :
public data class File(
override val src: String = "",
override val title: String = "",
override val cover: String = ""
) :
Files()

/**
* 音频。
*/
@Serializable
@SerialName(AUDIO_TYPE)
public data class Audio(override val src: String, override val title: String, override val cover: String) :
public data class Audio(
override val src: String = "",
override val title: String = "",
override val cover: String = ""
) :
Files()

/**
* 视频。
*/
@Serializable
@SerialName(VIDEO_TYPE)
public data class Video(override val src: String, override val title: String, override val cover: String) :
public data class Video(
override val src: String = "",
override val title: String = "",
override val cover: String = ""
) :
Files()

public companion object {
Expand All @@ -814,13 +832,16 @@ public sealed class CardModule {
public const val VIDEO_TYPE: String = "video"

@JvmStatic
public fun file(src: String, title: String, cover: String): File = File(src, title, cover)
@JvmOverloads
public fun file(src: String, title: String, cover: String = ""): File = File(src, title, cover)

@JvmStatic
public fun audio(src: String, title: String, cover: String): Audio = Audio(src, title, cover)
@JvmOverloads
public fun audio(src: String, title: String, cover: String = ""): Audio = Audio(src, title, cover)

@JvmStatic
public fun video(src: String, title: String, cover: String): Video = Video(src, title, cover)
@JvmOverloads
public fun video(src: String, title: String, cover: String = ""): Video = Video(src, title, cover)

}
}
Expand Down Expand Up @@ -853,8 +874,10 @@ public sealed class CardModule {
public val endTime: Long
) : CardModule() {
init {
require(mode == CountdownMode.SECOND && startTime != null) {
"When mode is 'SECOND', 'startTime' must not be null."
if (mode == CountdownMode.SECOND) {
requireNotNull(startTime) {
"When mode is 'SECOND', 'startTime' must not be null."
}
}
}

Expand Down Expand Up @@ -898,7 +921,7 @@ public sealed class CardModule {
public val code: String
) : CardModule() {
public companion object {
public const val TYPE: String = ""
public const val TYPE: String = "invite"
}
}

Expand Down

0 comments on commit 055bf77

Please sign in to comment.