Commit e8299391 authored by Him188's avatar Him188

Arise deprecation level, fix #353

parent 2d1bc657
......@@ -7,6 +7,8 @@
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
@file:Suppress("DEPRECATION_ERROR")
package net.mamoe.mirai.qqandroid.message
import net.mamoe.mirai.message.data.*
......
......@@ -42,7 +42,7 @@ suspend inline fun <B : Bot> B.alsoLogin(): B = also { login() }
* 有关 [Bot] 生命管理, 请查看 [BotConfiguration.inheritCoroutineContext]
*
* @see Contact 联系人
* @see kotlinx.coroutines.isActive 判断 [Bot] 是否正常运行中. (协程正常运行) (但不能判断是否在线, 需使用 [isOnline])
* @see isActive 判断 [Bot] 是否正常运行中. (协程正常运行) (但不能判断是否在线, 需使用 [isOnline])
*
* @see BotFactory 构造 [Bot] 的工厂, [Bot] 唯一的构造方式.
*/
......@@ -66,15 +66,8 @@ abstract class Bot internal constructor(
@Suppress("ObjectPropertyName")
internal val _instances: LockFreeLinkedList<WeakRef<Bot>> = LockFreeLinkedList()
/**
* 复制一份此时的 [Bot] 实例列表.
*/
@PlannedRemoval("1.2.0")
@Deprecated(
"use botInstances instead",
replaceWith = ReplaceWith("botInstances"),
level = DeprecationLevel.ERROR
)
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
@JvmStatic
val instances: List<WeakRef<Bot>>
get() = _instances.toList()
......@@ -230,7 +223,8 @@ abstract class Bot internal constructor(
@PlannedRemoval("1.2.0")
@Deprecated(
"use extension.",
replaceWith = ReplaceWith("image.queryUrl()", imports = ["net.mamoe.mirai.message.data.queryUrl"])
replaceWith = ReplaceWith("image.queryUrl()", imports = ["net.mamoe.mirai.message.data.queryUrl"]),
level = DeprecationLevel.ERROR
)
@JvmSynthetic
abstract suspend fun queryImageUrl(image: Image): String
......@@ -259,7 +253,7 @@ abstract class Bot internal constructor(
* @param event 好友验证的事件对象
*/
@PlannedRemoval("1.2.0")
@Deprecated("use member function.", replaceWith = ReplaceWith("event.accept()"))
@Deprecated("use member function.", replaceWith = ReplaceWith("event.accept()"), level = DeprecationLevel.ERROR)
@JvmSynthetic
abstract suspend fun acceptNewFriendRequest(event: NewFriendRequestEvent)
......@@ -270,7 +264,11 @@ abstract class Bot internal constructor(
* @param blackList 拒绝后是否拉入黑名单
*/
@PlannedRemoval("1.2.0")
@Deprecated("use member function.", replaceWith = ReplaceWith("event.reject(blackList)"))
@Deprecated(
"use member function.",
replaceWith = ReplaceWith("event.reject(blackList)"),
level = DeprecationLevel.ERROR
)
@JvmSynthetic
abstract suspend fun rejectNewFriendRequest(event: NewFriendRequestEvent, blackList: Boolean = false)
......@@ -280,7 +278,7 @@ abstract class Bot internal constructor(
* @param event 加群验证的事件对象
*/
@PlannedRemoval("1.2.0")
@Deprecated("use member function.", replaceWith = ReplaceWith("event.accept()"))
@Deprecated("use member function.", replaceWith = ReplaceWith("event.accept()"), level = DeprecationLevel.ERROR)
@JvmSynthetic
abstract suspend fun acceptMemberJoinRequest(event: MemberJoinRequestEvent)
......@@ -291,7 +289,11 @@ abstract class Bot internal constructor(
* @param blackList 拒绝后是否拉入黑名单
*/
@PlannedRemoval("1.2.0")
@Deprecated("use member function.", replaceWith = ReplaceWith("event.reject(blackList)"))
@Deprecated(
"use member function.",
replaceWith = ReplaceWith("event.reject(blackList)"),
level = DeprecationLevel.ERROR
)
@JvmSynthetic
abstract suspend fun rejectMemberJoinRequest(event: MemberJoinRequestEvent, blackList: Boolean = false)
......@@ -302,7 +304,11 @@ abstract class Bot internal constructor(
* @param blackList 忽略后是否拉入黑名单
*/
@PlannedRemoval("1.2.0")
@Deprecated("use member function.", replaceWith = ReplaceWith("event.ignore(blackList)"))
@Deprecated(
"use member function.",
replaceWith = ReplaceWith("event.ignore(blackList)"),
level = DeprecationLevel.ERROR
)
@JvmSynthetic
abstract suspend fun ignoreMemberJoinRequest(event: MemberJoinRequestEvent, blackList: Boolean = false)
......@@ -312,7 +318,7 @@ abstract class Bot internal constructor(
* @param event 邀请入群的事件对象
*/
@PlannedRemoval("1.2.0")
@Deprecated("use member function.", replaceWith = ReplaceWith("event.accept()"))
@Deprecated("use member function.", replaceWith = ReplaceWith("event.accept()"), level = DeprecationLevel.ERROR)
@JvmSynthetic
abstract suspend fun acceptInvitedJoinGroupRequest(event: BotInvitedJoinGroupRequestEvent)
......@@ -322,15 +328,15 @@ abstract class Bot internal constructor(
* @param event 邀请入群的事件对象
*/
@PlannedRemoval("1.2.0")
@Deprecated("use member function.", replaceWith = ReplaceWith("event.ignore()"))
@Deprecated("use member function.", replaceWith = ReplaceWith("event.ignore()"), level = DeprecationLevel.ERROR)
@JvmSynthetic
abstract suspend fun ignoreInvitedJoinGroupRequest(event: BotInvitedJoinGroupRequestEvent)
// endregion
/**
* 关闭这个 [Bot], 立即取消 [Bot] 的 [kotlinx.coroutines.SupervisorJob].
* 之后 [kotlinx.coroutines.isActive] 将会返回 `false`.
* 关闭这个 [Bot], 立即取消 [Bot] 的 [SupervisorJob].
* 之后 [isActive] 将会返回 `false`.
*
* **注意:** 不可重新登录. 必须重新实例化一个 [Bot].
*
......
......@@ -9,7 +9,7 @@
@file:JvmMultifileClass
@file:JvmName("BotEventsKt")
@file:Suppress("unused", "FunctionName", "INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
@file:Suppress("unused", "FunctionName", "INVISIBLE_REFERENCE", "INVISIBLE_MEMBER", "DEPRECATION_ERROR")
package net.mamoe.mirai.event.events
......
......@@ -175,7 +175,7 @@ internal expect interface MessageEventPlatformExtensions<out TSender : User, out
@Deprecated(
message = "use MessageEvent",
replaceWith = ReplaceWith("MessageEvent", "net.mamoe.mirai.message.MessageEvent"),
level = DeprecationLevel.ERROR
level = DeprecationLevel.HIDDEN
)
abstract class MessagePacketBase<out TSender : User, out TSubject : Contact> : Packet, BotEvent, AbstractEvent() {
abstract override val bot: Bot
......@@ -191,7 +191,7 @@ abstract class MessagePacketBase<out TSender : User, out TSubject : Contact> : P
@Deprecated(
message = "Ambiguous name. Use MessageEvent instead",
replaceWith = ReplaceWith("MessageEvent", "net.mamoe.mirai.message.MessageEvent"),
level = DeprecationLevel.ERROR
level = DeprecationLevel.HIDDEN
)
@Suppress("DEPRECATION_ERROR")
abstract class MessagePacket : MessagePacketBase<User, Contact>(),
......@@ -209,7 +209,7 @@ abstract class MessagePacket : MessagePacketBase<User, Contact>(),
@Deprecated(
message = "Ambiguous name. Use MessageEvent instead",
replaceWith = ReplaceWith("MessageEvent", "net.mamoe.mirai.message.MessageEvent"),
level = DeprecationLevel.ERROR
level = DeprecationLevel.HIDDEN
)
@Suppress("DEPRECATION_ERROR")
abstract class ContactMessage : MessagePacket(),
......@@ -227,7 +227,7 @@ abstract class ContactMessage : MessagePacket(),
@Deprecated(
message = "Ambiguous name. Use FriendMessageEvent instead",
replaceWith = ReplaceWith("FriendMessageEvent", "net.mamoe.mirai.message.FriendMessageEvent"),
level = DeprecationLevel.ERROR
level = DeprecationLevel.HIDDEN
)
@Suppress("DEPRECATION_ERROR")
abstract class FriendMessage : MessageEvent() {
......@@ -244,7 +244,7 @@ abstract class FriendMessage : MessageEvent() {
@Deprecated(
message = "Ambiguous name. Use GroupMessageEvent instead",
replaceWith = ReplaceWith("GroupMessageEvent", "net.mamoe.mirai.message.GroupMessageEvent"),
level = DeprecationLevel.ERROR
level = DeprecationLevel.HIDDEN
)
@Suppress("DEPRECATION_ERROR")
abstract class GroupMessage : MessageEvent() {
......@@ -262,7 +262,7 @@ abstract class GroupMessage : MessageEvent() {
@Deprecated(
message = "Ambiguous name. Use TempMessageEvent instead",
replaceWith = ReplaceWith("TempMessageEvent", "net.mamoe.mirai.message.TempMessageEvent"),
level = DeprecationLevel.ERROR
level = DeprecationLevel.HIDDEN
)
abstract class TempMessage : MessageEvent() {
abstract override val bot: Bot
......
......@@ -15,18 +15,18 @@
"unused",
"WRONG_MODIFIER_CONTAINING_DECLARATION",
"DEPRECATION",
"UnusedImport"
"UnusedImport",
"EXPOSED_SUPER_CLASS",
"DEPRECATION_ERROR"
)
package net.mamoe.mirai.message.data
import kotlinx.io.core.copyTo
import kotlinx.serialization.Serializable
import net.mamoe.mirai.Bot
import net.mamoe.mirai.contact.Contact
import net.mamoe.mirai.contact.Group
import net.mamoe.mirai.message.code.CodableMessage
import net.mamoe.mirai.utils.*
import net.mamoe.mirai.utils.ExternalImage
import net.mamoe.mirai.utils.sendImage
import kotlin.js.JsName
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName
......@@ -100,34 +100,6 @@ expect interface Image : Message, MessageContent, @SinceMirai("1.1.0") CodableMe
internal val DoNotImplementThisClass: Nothing?
}
internal interface ConstOriginUrlAware : Image {
val originUrl: String
}
internal interface DeferredOriginUrlAware : Image {
fun getUrl(bot: Bot): String
}
internal interface SuspendDeferredOriginUrlAware : Image {
suspend fun getUrl(bot: Bot): String
}
/**
* 由 [ExternalImage] 委托的 [Image] 类型. 用于 [ExternalImage.plus]
*/
@SinceMirai("1.1.0")
@MiraiExperimentalAPI("Will be renamed to OfflineImage on 1.2.0")
@Suppress("DEPRECATION_ERROR")
internal class ExperimentalDeferredImage internal constructor(
val externalImage: ExternalImage
) : AbstractImage(), SuspendDeferredOriginUrlAware {
override suspend fun getUrl(bot: Bot): String {
TODO()
}
override val imageId: String = externalImage.calculateImageResourceId()
}
/**
* 计算图片的 md5 校验值.
*
......@@ -142,15 +114,27 @@ val Image.md5: ByteArray
* 好友图片
*
* [imageId] 形如 `/f8f1ab55-bf8e-4236-b55e-955848d7069f` (37 长度) 或 `/000000000-3814297509-BFB7027B9354B8F899A062061D74E206` (54 长度)
*/ // NotOnlineImage
@PlannedRemoval("1.2.0") // make internal
@Suppress("DEPRECATION_ERROR")
sealed class FriendImage : AbstractImage() {
*/
// NotOnlineImage
abstract class FriendImage internal constructor() : AbstractImage() { // change to sealed in the future.
companion object Key : Message.Key<FriendImage> {
override val typeName: String get() = "FriendImage"
}
}
/**
* 群图片.
*
* @property imageId 形如 `{01E9451B-70ED-EAE3-B37C-101F1EEBF5B5}.mirai` (后缀一定为 `".mirai"`)
* @see Image 查看更多说明
*/
// CustomFace
abstract class GroupImage internal constructor() : AbstractImage() { // change to sealed in the future.
companion object Key : Message.Key<GroupImage> {
override val typeName: String get() = "GroupImage"
}
}
/**
* 好友图片 ID 正则表达式
*
......@@ -216,188 +200,4 @@ suspend fun Image.queryUrl(): String {
is SuspendDeferredOriginUrlAware -> this.getUrl(firstOnlineBotInstance)
else -> error("Internal error: unsupported Image class: ${this::class}")
}
}
internal val firstOnlineBotInstance: Bot get() = Bot.botInstancesSequence.firstOrNull() ?: error("No Bot available")
/////////////////////////
///// 以下 API 已弃用 /////
/////////////////////////
// region 已启用
internal const val ONLINE_OFFLINE_DEPRECATION_MESSAGE = """
自 1.0.0 起, mirai 已经能正常处理离线图片和在线图片的下载链接等功能.
使用者无需考虑一个图片为在线图片还是离线图片, 只需使用 Image 类型.
"""
@PlannedRemoval("1.2.0") // 改为 internal
@Deprecated(
ONLINE_OFFLINE_DEPRECATION_MESSAGE,
level = DeprecationLevel.WARNING,
replaceWith = ReplaceWith("Image", "net.mamoe.mirai.message.data.Image")
)
@Suppress("EXPOSED_SUPER_INTERFACE")
interface OnlineImage : Image, ConstOriginUrlAware {
companion object Key : Message.Key<OnlineImage> {
override val typeName: String get() = "OnlineImage"
}
override val originUrl: String
}
/**
* 离线的图片, 即为客户端主动上传到服务器而获得的 [Image] 实例.
* 不能直接获取它在服务器上的链接. 需要通过 [Bot.queryImageUrl] 查询
*
* 一般由 [Contact.uploadImage] 得到
*/
@PlannedRemoval("1.2.0") // 改为 internal
@Deprecated(
ONLINE_OFFLINE_DEPRECATION_MESSAGE,
level = DeprecationLevel.WARNING,
replaceWith = ReplaceWith("Image", "net.mamoe.mirai.message.data.Image")
)
interface OfflineImage : Image {
companion object Key : Message.Key<OfflineImage> {
override val typeName: String get() = "OfflineImage"
}
}
@PlannedRemoval("1.2.0") // 删除
@Deprecated(
ONLINE_OFFLINE_DEPRECATION_MESSAGE,
level = DeprecationLevel.HIDDEN
)
@JvmSynthetic
suspend fun OfflineImage.queryUrl(): String {
return Bot._instances.peekFirst()?.get()?.queryImageUrl(this) ?: error("No Bot available to query image url")
}
/**
* 通过 [Group.uploadImage] 上传得到的 [GroupImage]. 它的链接需要查询 [Bot.queryImageUrl]
*
* @param imageId 参考 [Image.imageId]
*/
@PlannedRemoval("1.2.0") // 改为 internal
@Deprecated(
ONLINE_OFFLINE_DEPRECATION_MESSAGE,
level = DeprecationLevel.WARNING,
replaceWith = ReplaceWith("Image", "net.mamoe.mirai.message.data.Image")
)
@Serializable
data class OfflineGroupImage(
override val imageId: String
) : GroupImage(), OfflineImage, DeferredOriginUrlAware {
override fun getUrl(bot: Bot): String {
return "http://gchat.qpic.cn/gchatpic_new/${bot.id}/0-0-${imageId.substring(1..36)
.replace("-", "")}/0?term=2"
}
init {
@Suppress("DEPRECATION")
require(imageId matches GROUP_IMAGE_ID_REGEX) {
"Illegal imageId. It must matches GROUP_IMAGE_ID_REGEX"
}
}
}
/**
* 接收消息时获取到的 [GroupImage]. 它可以直接获取下载链接 [originUrl]
*/
@PlannedRemoval("1.2.0") // 改为 internal
@Deprecated(
ONLINE_OFFLINE_DEPRECATION_MESSAGE,
level = DeprecationLevel.WARNING,
replaceWith = ReplaceWith("Image", "net.mamoe.mirai.message.data.Image")
)
abstract class OnlineGroupImage : GroupImage(), OnlineImage
/**
* 通过 [Group.uploadImage] 上传得到的 [GroupImage]. 它的链接需要查询 [Bot.queryImageUrl]
*
* @param imageId 参考 [Image.imageId]
*/
@PlannedRemoval("1.2.0") // 改为 internal
@Deprecated(
ONLINE_OFFLINE_DEPRECATION_MESSAGE,
level = DeprecationLevel.WARNING,
replaceWith = ReplaceWith("Image", "net.mamoe.mirai.message.data.Image")
)
@Serializable
data class OfflineFriendImage(
override val imageId: String
) : FriendImage(), OfflineImage, DeferredOriginUrlAware {
override fun getUrl(bot: Bot): String {
return "http://c2cpicdw.qpic.cn/offpic_new/${bot.id}/${this.imageId}/0?term=2"
}
init {
require(imageId matches FRIEND_IMAGE_ID_REGEX_1 || imageId matches FRIEND_IMAGE_ID_REGEX_2) {
"Illegal imageId. It must matches either FRIEND_IMAGE_ID_REGEX_1 or FRIEND_IMAGE_ID_REGEX_2"
}
}
}
/**
* 接收消息时获取到的 [FriendImage]. 它可以直接获取下载链接 [originUrl]
*/
@PlannedRemoval("1.2.0") // 改为 internal
@Deprecated(
ONLINE_OFFLINE_DEPRECATION_MESSAGE,
level = DeprecationLevel.WARNING,
replaceWith = ReplaceWith("Image", "net.mamoe.mirai.message.data.Image")
)
abstract class OnlineFriendImage : FriendImage(), OnlineImage
/**
* 群图片.
*
* @property imageId 形如 `{01E9451B-70ED-EAE3-B37C-101F1EEBF5B5}.mirai` (后缀一定为 `".mirai"`)
* @see Image 查看更多说明
*/
@PlannedRemoval("1.2.0") // make internal
@Suppress("DEPRECATION_ERROR")
// CustomFace
sealed class GroupImage : AbstractImage() {
companion object Key : Message.Key<GroupImage> {
override val typeName: String get() = "GroupImage"
}
}
// endregion
/**
* 所有 [Image] 实现的基类.
*/
@PlannedRemoval("1.2.0") // make internal
@Deprecated(
"This is internal API. Use Image instead",
level = DeprecationLevel.HIDDEN, // so that others can't see this class
replaceWith = ReplaceWith("Image")
)
@MiraiInternalAPI("Use Image instead")
sealed class AbstractImage : Image {
@Deprecated(
"""
不要自行实现 Image, 它必须由协议模块实现, 否则会无法发送也无法解析.
""", level = DeprecationLevel.HIDDEN
)
@Suppress("PropertyName", "DeprecatedCallableAddReplaceWith")
@get:JvmSynthetic
final override val DoNotImplementThisClass: Nothing?
get() = error("stub")
private var _stringValue: String? = null
get() = field ?: kotlin.run {
field = "[mirai:image:$imageId]"
field
}
final override fun toString(): String = _stringValue!!
final override fun contentToString(): String = "[图片]"
}
}
\ No newline at end of file
/*
* Copyright 2020 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
@file:JvmMultifileClass
@file:JvmName("MessageUtils")
@file:Suppress(
"EXPERIMENTAL_API_USAGE",
"unused",
"WRONG_MODIFIER_CONTAINING_DECLARATION",
"DEPRECATION",
"UnusedImport",
"EXPOSED_SUPER_CLASS",
"DEPRECATION_ERROR"
)
package net.mamoe.mirai.message.data
import kotlinx.serialization.Serializable
import net.mamoe.mirai.Bot
import net.mamoe.mirai.contact.Contact
import net.mamoe.mirai.contact.Group
import net.mamoe.mirai.utils.PlannedRemoval
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName
import kotlin.jvm.JvmSynthetic
/////////////////////////
///// 以下 API 已弃用 /////
/////////////////////////
// region 已启用
internal const val ONLINE_OFFLINE_DEPRECATION_MESSAGE = """
自 1.0.0 起, mirai 已经能正常处理离线图片和在线图片的下载链接等功能.
使用者无需考虑一个图片为在线图片还是离线图片, 只需使用 Image 类型.
"""
@PlannedRemoval("1.2.0") // 改为 internal
@Deprecated(
ONLINE_OFFLINE_DEPRECATION_MESSAGE,
level = DeprecationLevel.ERROR,
replaceWith = ReplaceWith("Image", "net.mamoe.mirai.message.data.Image")
)
@Suppress("EXPOSED_SUPER_INTERFACE")
interface OnlineImage : Image, ConstOriginUrlAware {
companion object Key : Message.Key<OnlineImage> {
override val typeName: String get() = "OnlineImage"
}
override val originUrl: String
}
/**
* 离线的图片, 即为客户端主动上传到服务器而获得的 [Image] 实例.
* 不能直接获取它在服务器上的链接. 需要通过 [Bot.queryImageUrl] 查询
*
* 一般由 [Contact.uploadImage] 得到
*/
@PlannedRemoval("1.2.0") // 改为 internal
@Deprecated(
ONLINE_OFFLINE_DEPRECATION_MESSAGE,
level = DeprecationLevel.ERROR,
replaceWith = ReplaceWith("Image", "net.mamoe.mirai.message.data.Image")
)
interface OfflineImage : Image {
companion object Key : Message.Key<OfflineImage> {
override val typeName: String get() = "OfflineImage"
}
}
@PlannedRemoval("1.2.0") // 删除
@Deprecated(
ONLINE_OFFLINE_DEPRECATION_MESSAGE,
level = DeprecationLevel.HIDDEN
)
@JvmSynthetic
suspend fun OfflineImage.queryUrl(): String {
return Bot._instances.peekFirst()?.get()?.queryImageUrl(this) ?: error("No Bot available to query image url")
}
/**
* 通过 [Group.uploadImage] 上传得到的 [GroupImage]. 它的链接需要查询 [Bot.queryImageUrl]
*
* @param imageId 参考 [Image.imageId]
*/
@PlannedRemoval("1.2.0") // 改为 internal
@Deprecated(
ONLINE_OFFLINE_DEPRECATION_MESSAGE,
level = DeprecationLevel.ERROR,
replaceWith = ReplaceWith("Image", "net.mamoe.mirai.message.data.Image")
)
@Serializable
data class OfflineGroupImage(
override val imageId: String
) : GroupImage(), OfflineImage, DeferredOriginUrlAware {
override fun getUrl(bot: Bot): String {
return "http://gchat.qpic.cn/gchatpic_new/${bot.id}/0-0-${imageId.substring(1..36)
.replace("-", "")}/0?term=2"
}
init {
@Suppress("DEPRECATION")
require(imageId matches GROUP_IMAGE_ID_REGEX) {
"Illegal imageId. It must matches GROUP_IMAGE_ID_REGEX"
}
}
}
/**
* 接收消息时获取到的 [GroupImage]. 它可以直接获取下载链接 [originUrl]
*/
@PlannedRemoval("1.2.0") // 改为 internal
@Deprecated(
ONLINE_OFFLINE_DEPRECATION_MESSAGE,
level = DeprecationLevel.ERROR,
replaceWith = ReplaceWith("Image", "net.mamoe.mirai.message.data.Image")
)
abstract class OnlineGroupImage : GroupImage(), OnlineImage
/**
* 通过 [Group.uploadImage] 上传得到的 [GroupImage]. 它的链接需要查询 [Bot.queryImageUrl]
*
* @param imageId 参考 [Image.imageId]
*/
@PlannedRemoval("1.2.0") // 改为 internal
@Deprecated(
ONLINE_OFFLINE_DEPRECATION_MESSAGE,
level = DeprecationLevel.ERROR,
replaceWith = ReplaceWith("Image", "net.mamoe.mirai.message.data.Image")
)
@Serializable
data class OfflineFriendImage(
override val imageId: String
) : FriendImage(), OfflineImage, DeferredOriginUrlAware {
override fun getUrl(bot: Bot): String {
return "http://c2cpicdw.qpic.cn/offpic_new/${bot.id}/${this.imageId}/0?term=2"
}
init {
require(imageId matches FRIEND_IMAGE_ID_REGEX_1 || imageId matches FRIEND_IMAGE_ID_REGEX_2) {
"Illegal imageId. It must matches either FRIEND_IMAGE_ID_REGEX_1 or FRIEND_IMAGE_ID_REGEX_2"
}
}
}
/**
* 接收消息时获取到的 [FriendImage]. 它可以直接获取下载链接 [originUrl]
*/
@PlannedRemoval("1.2.0") // 改为 internal
@Deprecated(
ONLINE_OFFLINE_DEPRECATION_MESSAGE,
level = DeprecationLevel.ERROR,
replaceWith = ReplaceWith("Image", "net.mamoe.mirai.message.data.Image")
)
abstract class OnlineFriendImage : FriendImage(), OnlineImage
// endregion
......@@ -13,15 +13,77 @@
package net.mamoe.mirai.message.data
import net.mamoe.mirai.Bot
import net.mamoe.mirai.utils.ExternalImage
import net.mamoe.mirai.utils.MiraiExperimentalAPI
import net.mamoe.mirai.utils.SinceMirai
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName
import kotlin.jvm.JvmSynthetic
import kotlin.native.concurrent.SharedImmutable
// region image
/**
* 所有 [Image] 实现的基类.
*/
internal abstract class AbstractImage : Image { // make sealed in 1.3.0 ?
@Deprecated(
"""
不要自行实现 Image, 它必须由协议模块实现, 否则会无法发送也无法解析.
""", level = DeprecationLevel.HIDDEN
)
@Suppress("PropertyName", "DeprecatedCallableAddReplaceWith")
@get:JvmSynthetic
final override val DoNotImplementThisClass: Nothing?
get() = error("stub")
private var _stringValue: String? = null
get() = field ?: kotlin.run {
field = "[mirai:image:$imageId]"
field
}
final override fun toString(): String = _stringValue!!
final override fun contentToString(): String = "[图片]"
}
internal interface ConstOriginUrlAware : Image {
val originUrl: String
}
internal interface DeferredOriginUrlAware : Image {
fun getUrl(bot: Bot): String
}
internal interface SuspendDeferredOriginUrlAware : Image {
suspend fun getUrl(bot: Bot): String
}
/**
* 由 [ExternalImage] 委托的 [Image] 类型.
*/
@SinceMirai("1.1.0")
@MiraiExperimentalAPI("Will be renamed to OfflineImage on 1.2.0")
@Suppress("DEPRECATION_ERROR")
internal class ExperimentalDeferredImage internal constructor(
@Suppress("CanBeParameter") private val externalImage: ExternalImage // for future use
) : AbstractImage(), SuspendDeferredOriginUrlAware {
override suspend fun getUrl(bot: Bot): String {
TODO()
}
override val imageId: String = externalImage.calculateImageResourceId()
}
internal val firstOnlineBotInstance: Bot get() = Bot.botInstancesSequence.firstOrNull() ?: error("No Bot available")
// endergion
/////////////////////////
//// IMPLEMENTATIONS ////
/////////////////////////
private fun Message.hasDuplicationOfConstrain(key: Message.Key<*>): Boolean {
return when (this) {
is SingleMessage -> (this as? ConstrainSingle<*>)?.key == key
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment