Skip to content

Commit

Permalink
Code format
Browse files Browse the repository at this point in the history
  • Loading branch information
ryoii committed Oct 12, 2023
1 parent 040be0d commit dc194a1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import net.mamoe.mirai.console.util.ContactUtils.getContact
import net.mamoe.mirai.console.util.cast
import net.mamoe.mirai.contact.*
import net.mamoe.mirai.contact.roaming.RoamingSupported
import net.mamoe.mirai.data.MemberInfo
import net.mamoe.mirai.message.MessageReceipt
import net.mamoe.mirai.message.data.*
import net.mamoe.mirai.message.data.Image.Key.queryUrl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,49 @@ internal suspend fun Message.toDTO() = when (this) {
is Face -> FaceDTO(id, FaceMap[id], isSuperFace = false)
is SuperFace -> FaceDTO(face, FaceMap[face], isSuperFace = true)
is PlainText -> PlainDTO(content)
is Image -> ImageDTO(imageId, queryUrl(), width = width, height = height, size = size, imageType = imageType.name, isEmoji = isEmoji)
is Image -> ImageDTO(
imageId,
queryUrl(),
width = width,
height = height,
size = size,
imageType = imageType.name,
isEmoji = isEmoji
)

is FlashImage -> with(image) {
FlashImageDTO(imageId, queryUrl(), width = width, height = height, size = size, imageType = imageType.name, isEmoji = isEmoji)
FlashImageDTO(
imageId,
queryUrl(),
width = width,
height = height,
size = size,
imageType = imageType.name,
isEmoji = isEmoji
)
}

is OnlineAudio -> VoiceDTO(filename, urlForDownload, length = length)
is ServiceMessage -> XmlDTO(content)
is LightApp -> AppDTO(content)
is QuoteReply -> QuoteDTO(source.ids.firstOrNull() ?: 0, source.fromId, source.targetId,
groupId = when {
source is OfflineMessageSource && (source as OfflineMessageSource).kind == MessageSourceKind.GROUP ||
source is OnlineMessageSource && (source as OnlineMessageSource).subject is Group -> source.targetId

else -> 0L
},
// 避免套娃
origin = source.originalMessage.toDTO { it != UnknownMessageDTO && it !is QuoteDTO })

is PokeMessage -> PokeMessageDTO(PokeMap[pokeType])
is Dice -> DiceDTO(value)
is MarketFace -> MarketFaceDTO(id, name)
is MusicShare -> MusicShareDTO(kind.name, title, summary, jumpUrl, pictureUrl, musicUrl, brief)
is ForwardMessage -> ForwardMessageDTO(null, nodeList.map {
ForwardMessageNode(it.senderId, it.time, it.senderName, it.messageChain.toDTO { d -> d != UnknownMessageDTO })
})

is FileMessage -> FileDTO(id, name, size)
is OnlineShortVideo -> ShortVideoDTO(videoId, fileMd5.toHexString(), fileSize, fileFormat, filename, urlForDownload)
is OfflineShortVideo -> ShortVideoDTO(videoId, fileMd5.toHexString(), fileSize, fileFormat, filename, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ internal data class AtAllDTO(val target: Long = 0) : MessageDTO() {

@Serializable
@SerialName("Face")
internal data class FaceDTO(val faceId: Int = -1, val name: String = "", val isSuperFace: Boolean = false) : MessageDTO() {
internal data class FaceDTO(val faceId: Int = -1, val name: String = "", val isSuperFace: Boolean = false) :
MessageDTO() {
override suspend fun convertToMessage(contact: Contact, persistence: Persistence): Message {
return when {
faceId >= 0 -> Face(faceId)
Expand Down Expand Up @@ -135,14 +136,17 @@ internal interface ImageLikeDTO {
size = this@ImageLikeDTO.size
isEmoji = this@ImageLikeDTO.isEmoji
}

!url.isNullOrBlank() -> withContext(Dispatchers.IO) {
url!!.useUrl { it.uploadAsImage(contact) }
}

!path.isNullOrBlank() -> with(File(path!!)) {
if (exists()) {
inputStream().useStream { it.uploadAsImage(contact) }
} else throw NoSuchFileException(this)
}

!base64.isNullOrBlank() -> with(Base64.getDecoder().decode(base64)) {
inputStream().useStream { it.uploadAsImage(contact) }
}
Expand All @@ -161,23 +165,23 @@ internal interface VoiceLikeDTO {
suspend fun voiceLikeToMessage(contact: Contact) = when {
contact !is AudioSupported -> null
!voiceId.isNullOrBlank() -> OfflineAudio.Factory.create(
voiceId!!,
voiceId!!.substringBefore(".").toHexArray(),
0,
AudioCodec.SILK,
null
voiceId!!, voiceId!!.substringBefore(".").toHexArray(), 0, AudioCodec.SILK, null
)

!url.isNullOrBlank() -> withContext(Dispatchers.IO) {
url!!.useUrl { contact.uploadAudio(it) }
}

!path.isNullOrBlank() -> with(File(path!!)) {
if (exists()) {
inputStream().useStream { contact.uploadAudio(it) }
} else throw NoSuchFileException(this)
}

!base64.isNullOrBlank() -> with(Base64.getDecoder().decode(base64)) {
inputStream().useStream { contact.uploadAudio(it) }
}

else -> null
}
}
Expand All @@ -200,6 +204,7 @@ internal interface VedioLikeDTO {
}
}
}

else -> {
OfflineShortVideo(
videoId,
Expand Down Expand Up @@ -291,11 +296,7 @@ internal data class AppDTO(val content: String) : MessageDTO() {
@Serializable
@SerialName("Quote")
internal data class QuoteDTO(
val id: Int,
val senderId: Long,
val targetId: Long,
val groupId: Long,
val origin: MessageChainDTO
val id: Int, val senderId: Long, val targetId: Long, val groupId: Long, val origin: MessageChainDTO
) : MessageDTO()

@Serializable
Expand Down

0 comments on commit dc194a1

Please sign in to comment.