Skip to content

Commit

Permalink
feat: try from
Browse files Browse the repository at this point in the history
  • Loading branch information
cssxsh committed Aug 15, 2023
1 parent 6dda2ea commit f31cfc0
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions mirai-core-api/src/commonMain/kotlin/message/data/SuperFace.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,23 @@ public class SuperFace @MiraiInternalApi constructor(

/**
* 将普通表情转换为超级表情.
*
* @throws UnsupportedOperationException 无法转换时抛出
**/
@JvmStatic
@OptIn(MiraiInternalApi::class)
@Throws(UnsupportedOperationException::class)
public fun from(face: Face): SuperFace {
return tryFrom(face = face) ?: throw UnsupportedOperationException("${face.id} - ${face.name}")
}

/**
* 将普通表情转换为超级表情.
*
* @return 无法转换时返回 null
**/
@JvmStatic
@OptIn(MiraiInternalApi::class)
public fun tryFrom(face: Face): SuperFace? {
val stickerId = when (face.id) {
Face.DA_CALL -> "1"
Face.BIAN_XING -> "2"
Expand Down Expand Up @@ -79,7 +91,7 @@ public class SuperFace @MiraiInternalApi constructor(
Face.WO_FANG_LE -> "27"
Face.DA_YUAN_ZHONG -> "28"
Face.HONG_BAO_DUO_DUO -> "29"
else -> throw UnsupportedOperationException(face.name)
else -> return null
}
val stickerType = when (face.id) {
Face.LAN_QIU -> 2
Expand Down

0 comments on commit f31cfc0

Please sign in to comment.