mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-23 06:10:30 +08:00
Cleanup
This commit is contained in:
parent
2b49a7586f
commit
039b3d7517
@ -182,11 +182,11 @@ internal abstract class QQAndroidBotBase constructor(
|
||||
}
|
||||
|
||||
@Suppress("RemoveExplicitTypeArguments") // false positive
|
||||
@ExperimentalMessageSource
|
||||
override suspend fun recall(source: MessageSource) {
|
||||
// println(source._miraiContentToString())
|
||||
|
||||
check(source is MessageSourceImpl)
|
||||
source.ensureSequenceIdAvailable()
|
||||
|
||||
val response: PbMessageSvc.PbMsgWithDraw.Response = when (source) {
|
||||
is MessageSourceToGroupImpl,
|
||||
@ -216,6 +216,7 @@ internal abstract class QQAndroidBotBase constructor(
|
||||
).sendAndExpect<PbMessageSvc.PbMsgWithDraw.Response>()
|
||||
}
|
||||
}
|
||||
is OfflineMessageSource,
|
||||
is MessageSourceFromFriendImpl,
|
||||
is MessageSourceToFriendImpl
|
||||
-> network.run {
|
||||
@ -227,7 +228,7 @@ internal abstract class QQAndroidBotBase constructor(
|
||||
source.time
|
||||
).sendAndExpect<PbMessageSvc.PbMsgWithDraw.Response>()
|
||||
}
|
||||
else -> error("stub")
|
||||
else -> error("stub!")
|
||||
}
|
||||
|
||||
check(response is PbMessageSvc.PbMsgWithDraw.Response.Success) { "Failed to recall message #${source.id}: $response" }
|
||||
|
@ -12,8 +12,6 @@
|
||||
|
||||
package net.mamoe.mirai.qqandroid.utils
|
||||
|
||||
import net.mamoe.mirai.message.data.*
|
||||
import net.mamoe.mirai.message.data.AtAll.display
|
||||
import kotlin.jvm.JvmMultifileClass
|
||||
import kotlin.jvm.JvmName
|
||||
|
||||
@ -32,6 +30,7 @@ internal fun Int.toIpV4AddressString(): String {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
internal fun String.chineseLength(upTo: Int): Int {
|
||||
return this.sumUpTo(upTo) { if (it in '\u0391'..'\uFFE5') 3 else 1 }
|
||||
}
|
||||
@ -41,11 +40,10 @@ internal fun MessageChain.estimateLength(upTo: Int = Int.MAX_VALUE): Int =
|
||||
it.estimateLength(up)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMessageSource::class)
|
||||
internal fun SingleMessage.estimateLength(upTo: Int = Int.MAX_VALUE): Int {
|
||||
return when (this) {
|
||||
is QuoteReply -> {
|
||||
700 + source.originalMessage.estimateLength(upTo)
|
||||
700
|
||||
}
|
||||
// is Image -> 300
|
||||
is PlainText -> stringValue.chineseLength(upTo)
|
||||
@ -76,3 +74,4 @@ internal inline fun CharSequence.sumUpTo(upTo: Int, selector: (Char) -> Int): In
|
||||
}
|
||||
return sum
|
||||
}
|
||||
*/
|
@ -5,7 +5,6 @@ import net.mamoe.mirai.contact.PermissionDeniedException
|
||||
import net.mamoe.mirai.contact.recall
|
||||
import net.mamoe.mirai.data.AddFriendResult
|
||||
import net.mamoe.mirai.message.MessageReceipt
|
||||
import net.mamoe.mirai.message.data.ExperimentalMessageSource
|
||||
import net.mamoe.mirai.message.data.Image
|
||||
import net.mamoe.mirai.message.data.MessageChain
|
||||
import net.mamoe.mirai.message.data.MessageSource
|
||||
@ -62,7 +61,6 @@ actual abstract class BotJavaFriendlyAPI actual constructor() {
|
||||
*
|
||||
* @see Bot.recall (扩展函数) 接受参数 [MessageChain]
|
||||
*/
|
||||
@ExperimentalMessageSource
|
||||
@JvmName("recall")
|
||||
fun __recallBlockingForJava__(source: MessageSource) {
|
||||
runBlocking { recall(source) }
|
||||
@ -90,7 +88,6 @@ actual abstract class BotJavaFriendlyAPI actual constructor() {
|
||||
* @param millis 延迟的时间, 单位为毫秒
|
||||
* @see recall
|
||||
*/
|
||||
@ExperimentalMessageSource
|
||||
@JvmName("recallIn")
|
||||
fun __recallIn_MemberForJava__(source: MessageSource, millis: Long) {
|
||||
runBlocking { recallIn(source, millis) }
|
||||
@ -151,7 +148,6 @@ actual abstract class BotJavaFriendlyAPI actual constructor() {
|
||||
/**
|
||||
* 异步调用 [__recallBlockingForJava__]
|
||||
*/
|
||||
@ExperimentalMessageSource
|
||||
@JvmName("recallAsync")
|
||||
fun __recallAsyncForJava__(source: MessageSource): Future<Unit> {
|
||||
return future { recall(source) }
|
||||
|
@ -11,7 +11,6 @@ import net.mamoe.mirai.contact.Contact
|
||||
import net.mamoe.mirai.contact.Group
|
||||
import net.mamoe.mirai.contact.Member
|
||||
import net.mamoe.mirai.contact.QQ
|
||||
import net.mamoe.mirai.message.data.ExperimentalMessageSource
|
||||
import net.mamoe.mirai.message.data.Message
|
||||
import net.mamoe.mirai.message.data.OnlineMessageSource
|
||||
import net.mamoe.mirai.message.data.QuoteReply
|
||||
@ -24,16 +23,18 @@ import net.mamoe.mirai.utils.unsafeWeakRef
|
||||
*
|
||||
* 此对象持有 [Contact] 的弱引用, [Bot] 离线后将会释放引用, 届时 [target] 将无法访问.
|
||||
*
|
||||
* @param source 指代发送出去的消息
|
||||
* @param target 消息发送对象
|
||||
*
|
||||
* @see Group.sendMessage 发送群消息, 返回回执(此对象)
|
||||
* @see QQ.sendMessage 发送群消息, 返回回执(此对象)
|
||||
*
|
||||
* @see MessageReceipt.sourceId 源 id
|
||||
* @see MessageReceipt.sourceSequenceId 源序列号
|
||||
* @see MessageReceipt.sourceTime 源时间
|
||||
*/
|
||||
@Suppress("FunctionName")
|
||||
@OptIn(MiraiInternalAPI::class)
|
||||
actual open class MessageReceipt<out C : Contact> @OptIn(ExperimentalMessageSource::class)
|
||||
actual open class MessageReceipt<out C : Contact>
|
||||
actual constructor(
|
||||
actual val source: OnlineMessageSource.Outgoing,
|
||||
target: C,
|
||||
|
@ -18,7 +18,6 @@ import net.mamoe.mirai.event.BroadcastControllable
|
||||
import net.mamoe.mirai.event.CancellableEvent
|
||||
import net.mamoe.mirai.event.events.ImageUploadEvent.Failed
|
||||
import net.mamoe.mirai.event.events.ImageUploadEvent.Succeed
|
||||
import net.mamoe.mirai.message.data.ExperimentalMessageSource
|
||||
import net.mamoe.mirai.message.data.Image
|
||||
import net.mamoe.mirai.message.data.MessageChain
|
||||
import net.mamoe.mirai.message.data.MessageSource
|
||||
@ -98,7 +97,6 @@ sealed class MessageSendEvent : BotEvent, BotActiveEvent, AbstractCancellableEve
|
||||
/**
|
||||
* 消息撤回事件. 可是任意消息被任意人撤回.
|
||||
*/
|
||||
@OptIn(ExperimentalMessageSource::class)
|
||||
sealed class MessageRecallEvent : BotEvent {
|
||||
/**
|
||||
* 消息原发送人
|
||||
|
@ -34,7 +34,7 @@ import kotlin.jvm.JvmSynthetic
|
||||
* @see MessageReceipt.sourceId 源 id
|
||||
* @see MessageReceipt.sourceTime 源时间
|
||||
*/
|
||||
expect open class MessageReceipt<out C : Contact> @OptIn(ExperimentalMessageSource::class) constructor(
|
||||
expect open class MessageReceipt<out C : Contact>(
|
||||
source: OnlineMessageSource.Outgoing,
|
||||
target: C,
|
||||
botAsMember: Member?
|
||||
|
@ -69,7 +69,7 @@ interface Message {
|
||||
*
|
||||
* @param M 指代持有这个 Key 的消息类型
|
||||
*/
|
||||
interface Key<M : Message>
|
||||
interface Key<out M : Message>
|
||||
|
||||
infix fun eq(other: Message): Boolean = this.toString() == other.toString()
|
||||
|
||||
|
@ -132,7 +132,7 @@ inline fun <reified M : Message> MessageChain.any(): Boolean = this.any { it is
|
||||
/**
|
||||
* 获取第一个 [M] 类型的 [Message] 实例
|
||||
*/
|
||||
@OptIn(ExperimentalMessageSource::class, MiraiExperimentalAPI::class)
|
||||
@OptIn(MiraiExperimentalAPI::class)
|
||||
@JvmSynthetic
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun <M : Message> MessageChain.firstOrNull(key: Message.Key<M>): M? = when (key) {
|
||||
|
@ -28,12 +28,6 @@ import kotlin.jvm.JvmMultifileClass
|
||||
import kotlin.jvm.JvmName
|
||||
import kotlin.jvm.JvmSynthetic
|
||||
|
||||
/**
|
||||
* MessageSource 正计划于 0.32 或 0.33 或之后进行 API 不兼容的重写.
|
||||
*/
|
||||
@RequiresOptIn(message = "MessageSource 正计划于 0.32 或 0.33 或之后进行 API 不兼容的重写", level = RequiresOptIn.Level.WARNING)
|
||||
annotation class ExperimentalMessageSource
|
||||
|
||||
/**
|
||||
* 消息源, 它存在于 [MessageChain] 中, 用于表示这个消息的来源.
|
||||
*
|
||||
@ -103,6 +97,8 @@ sealed class MessageSource : Message, MessageMetadata {
|
||||
*/
|
||||
@SinceMirai("0.33.0")
|
||||
sealed class OnlineMessageSource : MessageSource() {
|
||||
companion object Key : Message.Key<OnlineMessageSource>
|
||||
|
||||
/**
|
||||
* 消息发送人. 可能为 [机器人][Bot] 或 [好友][QQ] 或 [群员][Member].
|
||||
* 即类型必定为 [Bot], [QQ] 或 [Member]
|
||||
@ -125,6 +121,8 @@ sealed class OnlineMessageSource : MessageSource() {
|
||||
* 由 [机器人主动发送消息][Contact.sendMessage] 产生的 [MessageSource]
|
||||
*/
|
||||
sealed class Outgoing : OnlineMessageSource() {
|
||||
companion object Key : Message.Key<Outgoing>
|
||||
|
||||
abstract override val sender: Bot
|
||||
abstract override val target: Contact
|
||||
|
||||
@ -132,12 +130,16 @@ sealed class OnlineMessageSource : MessageSource() {
|
||||
final override val targetId: Long get() = target.id
|
||||
|
||||
abstract class ToFriend : Outgoing() {
|
||||
companion object Key : Message.Key<ToFriend>
|
||||
|
||||
abstract override val target: QQ
|
||||
final override val subject: QQ get() = target
|
||||
// final override fun toString(): String = "OnlineMessageSource.ToFriend(target=${target.id})"
|
||||
}
|
||||
|
||||
abstract class ToGroup : Outgoing() {
|
||||
companion object Key : Message.Key<ToGroup>
|
||||
|
||||
abstract override val target: Group
|
||||
final override val subject: Group get() = target
|
||||
// final override fun toString(): String = "OnlineMessageSource.ToGroup(group=${target.id})"
|
||||
@ -148,6 +150,8 @@ sealed class OnlineMessageSource : MessageSource() {
|
||||
* 接收到的一条消息的 [MessageSource]
|
||||
*/
|
||||
sealed class Incoming : OnlineMessageSource() {
|
||||
companion object Key : Message.Key<Incoming>
|
||||
|
||||
abstract override val sender: QQ // out QQ
|
||||
abstract override val target: Bot
|
||||
|
||||
@ -155,12 +159,16 @@ sealed class OnlineMessageSource : MessageSource() {
|
||||
final override val targetId: Long get() = target.id
|
||||
|
||||
abstract class FromFriend : Incoming() {
|
||||
companion object Key : Message.Key<FromFriend>
|
||||
|
||||
abstract override val sender: QQ
|
||||
final override val subject: QQ get() = sender
|
||||
// final override fun toString(): String = "OnlineMessageSource.FromFriend(from=${sender.id})"
|
||||
}
|
||||
|
||||
abstract class FromGroup : Incoming() {
|
||||
companion object Key : Message.Key<FromGroup>
|
||||
|
||||
abstract override val sender: Member
|
||||
final override val subject: Group get() = sender.group
|
||||
val group: Group get() = sender.group
|
||||
@ -207,6 +215,7 @@ inline fun MessageSource.recallIn(
|
||||
*/
|
||||
@SinceMirai("0.33.0")
|
||||
abstract class OfflineMessageSource : MessageSource() {
|
||||
companion object Key : Message.Key<OfflineMessageSource>
|
||||
// final override fun toString(): String = "OfflineMessageSource(sender=$senderId, target=$targetId)"
|
||||
} // TODO: 2020/4/4 可能要分群和好友
|
||||
|
||||
|
@ -5,7 +5,6 @@ import net.mamoe.mirai.contact.PermissionDeniedException
|
||||
import net.mamoe.mirai.contact.recall
|
||||
import net.mamoe.mirai.data.AddFriendResult
|
||||
import net.mamoe.mirai.message.MessageReceipt
|
||||
import net.mamoe.mirai.message.data.ExperimentalMessageSource
|
||||
import net.mamoe.mirai.message.data.Image
|
||||
import net.mamoe.mirai.message.data.MessageChain
|
||||
import net.mamoe.mirai.message.data.MessageSource
|
||||
@ -62,7 +61,6 @@ actual abstract class BotJavaFriendlyAPI actual constructor() {
|
||||
*
|
||||
* @see Bot.recall (扩展函数) 接受参数 [MessageChain]
|
||||
*/
|
||||
@ExperimentalMessageSource
|
||||
@JvmName("recall")
|
||||
fun __recallBlockingForJava__(source: MessageSource) {
|
||||
runBlocking { recall(source) }
|
||||
@ -90,7 +88,6 @@ actual abstract class BotJavaFriendlyAPI actual constructor() {
|
||||
* @param millis 延迟的时间, 单位为毫秒
|
||||
* @see recall
|
||||
*/
|
||||
@ExperimentalMessageSource
|
||||
@JvmName("recallIn")
|
||||
fun __recallIn_MemberForJava__(source: MessageSource, millis: Long) {
|
||||
runBlocking { recallIn(source, millis) }
|
||||
@ -151,7 +148,6 @@ actual abstract class BotJavaFriendlyAPI actual constructor() {
|
||||
/**
|
||||
* 异步调用 [__recallBlockingForJava__]
|
||||
*/
|
||||
@ExperimentalMessageSource
|
||||
@JvmName("recallAsync")
|
||||
fun __recallAsyncForJava__(source: MessageSource): Future<Unit> {
|
||||
return future { recall(source) }
|
||||
|
@ -11,7 +11,6 @@ import net.mamoe.mirai.contact.Contact
|
||||
import net.mamoe.mirai.contact.Group
|
||||
import net.mamoe.mirai.contact.Member
|
||||
import net.mamoe.mirai.contact.QQ
|
||||
import net.mamoe.mirai.message.data.ExperimentalMessageSource
|
||||
import net.mamoe.mirai.message.data.Message
|
||||
import net.mamoe.mirai.message.data.OnlineMessageSource
|
||||
import net.mamoe.mirai.message.data.QuoteReply
|
||||
@ -24,16 +23,18 @@ import net.mamoe.mirai.utils.unsafeWeakRef
|
||||
*
|
||||
* 此对象持有 [Contact] 的弱引用, [Bot] 离线后将会释放引用, 届时 [target] 将无法访问.
|
||||
*
|
||||
* @param source 指代发送出去的消息
|
||||
* @param target 消息发送对象
|
||||
*
|
||||
* @see Group.sendMessage 发送群消息, 返回回执(此对象)
|
||||
* @see QQ.sendMessage 发送群消息, 返回回执(此对象)
|
||||
*
|
||||
* @see MessageReceipt.sourceId 源 id
|
||||
* @see MessageReceipt.sourceSequenceId 源序列号
|
||||
* @see MessageReceipt.sourceTime 源时间
|
||||
*/
|
||||
@Suppress("FunctionName")
|
||||
@OptIn(MiraiInternalAPI::class)
|
||||
actual open class MessageReceipt<out C : Contact> @OptIn(ExperimentalMessageSource::class)
|
||||
actual open class MessageReceipt<out C : Contact>
|
||||
actual constructor(
|
||||
actual val source: OnlineMessageSource.Outgoing,
|
||||
target: C,
|
||||
|
Loading…
Reference in New Issue
Block a user