FileMessageImpl.kt 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright 2019-2021 Mamoe Technologies and contributors.
  3. *
  4. * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
  5. * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
  6. *
  7. * https://github.com/mamoe/mirai/blob/master/LICENSE
  8. */
  9. package net.mamoe.mirai.internal.message
  10. import kotlinx.serialization.SerialName
  11. import kotlinx.serialization.Serializable
  12. import net.mamoe.mirai.message.data.FileMessage
  13. import kotlin.contracts.contract
  14. internal fun FileMessage.checkIsImpl(): FileMessageImpl {
  15. contract { returns() implies (this@checkIsImpl is FileMessageImpl) }
  16. return this as? FileMessageImpl ?: error("FileMessage must not be implemented manually.")
  17. }
  18. @Serializable
  19. @SerialName(FileMessage.SERIAL_NAME)
  20. internal data class FileMessageImpl(
  21. override val id: String,
  22. @SerialName("internalId") val busId: Int,
  23. override val name: String,
  24. override val size: Long,
  25. ) : FileMessage {
  26. override val internalId: Int
  27. get() = busId
  28. override fun appendMiraiCodeTo(builder: StringBuilder) {
  29. builder.append("[mirai:file:")
  30. builder.append(id).append(",")
  31. builder.append(busId).append(",")
  32. builder.append(name).append(",")
  33. builder.append(size).append("]")
  34. }
  35. override fun toString(): String = "[mirai:file:$name,$id,$size,$busId]"
  36. }