mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-08 01:42:28 +08:00
Change ExternalResource.uploadAsVoice parameter type from Group to Contact for future compatibility.
This commit is contained in:
parent
93fcb566fd
commit
45c5e0fb9c
@ -11,6 +11,8 @@ package net.mamoe.mirai.message.data
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import net.mamoe.mirai.utils.ExternalResource
|
||||
import net.mamoe.mirai.utils.ExternalResource.Companion.uploadAsVoice
|
||||
import net.mamoe.mirai.utils.MiraiExperimentalApi
|
||||
import net.mamoe.mirai.utils.MiraiInternalApi
|
||||
import net.mamoe.mirai.utils.safeCast
|
||||
@ -36,9 +38,11 @@ public abstract class PttMessage : MessageContent {
|
||||
public abstract val fileSize: Long
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 语音消息, 目前只支持接收和转发
|
||||
*
|
||||
* 目前, 使用 [Voice] 类型是稳定的, 但调用 [Voice] 中的属性 [fileName], [md5], [fileSize] 是不稳定的. 语音的序列化也可能会在未来有变动.
|
||||
* 可安全地通过 [ExternalResource.uploadAsVoice] 上传语音并使用.
|
||||
*/
|
||||
@Serializable // experimental
|
||||
@SerialName(Voice.SERIAL_NAME)
|
||||
@ -55,6 +59,9 @@ public class Voice @MiraiInternalApi constructor(
|
||||
public const val SERIAL_NAME: String = "Voice"
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载链接 HTTP URL.
|
||||
*/
|
||||
public val url: String?
|
||||
get() = when {
|
||||
_url.isBlank() -> null
|
||||
|
@ -261,14 +261,13 @@ public interface ExternalResource : Closeable {
|
||||
* - 请手动关闭输入流
|
||||
* - 请使用 amr 或 silk 格式
|
||||
*
|
||||
* @suppress 将来支持好友语音之后将会把参数修改为 [Contact], 这会是一个不兼容变更. 因此请优先使用 [Group.uploadVoice]
|
||||
* @throws OverFileSizeMaxException
|
||||
*/
|
||||
@JvmBlockingBridge
|
||||
@JvmStatic
|
||||
@MiraiExperimentalApi
|
||||
public suspend fun ExternalResource.uploadAsVoice(group: Group): Voice {
|
||||
return group.uploadVoice(this)
|
||||
public suspend fun ExternalResource.uploadAsVoice(contact: Contact): Voice {
|
||||
if (contact is Group) return contact.uploadVoice(this)
|
||||
else throw UnsupportedOperationException("Uploading Voice is only supported for Group yet.")
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user